我有以下代码:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
df <- read.csv("https://dl.dropboxusercontent.com/u/73950/moduVSmnc.csv")
breaks1 <- seq(1.85,2.5,by=0.05)
gg <- aggregate(mnc~cut(apl,breaks=breaks1,
labels=format(breaks1[-1],nsmall=2))+modu,df,mean)
colnames(gg)<- c("apl","modu","mnc")
gg$modu <- as.factor(gg$modu)
library(ggplot2)
library(RColorBrewer)
ggplot(gg) +
geom_tile(aes(x=modu,y=apl,fill=mnc))+
scale_fill_gradientn(colours=rev(brewer.pal(10,"Spectral"))) +
coord_fixed()
产生:
现在,我希望此图将40以下所有值显示为深蓝色(好像值是0),然后开始平滑地移动到绿色,黄色,橙色,红色和深红色(啤酒的光谱色标),直到达到最大值。
如何用ggplot2实现呢?
我不确定我是否正确理解了您的问题。为什么不将所有mnc
<40映射为40并重新着色?
gg$mnc2<-gg$mnc
gg$mnc2[gg$mnc2<40]<-40
ggplot(gg) +
geom_tile(aes(x=modu,y=apl,fill=mnc2))+
scale_fill_gradientn(colours=rev(brewer.pal(11,"Spectral"))) +
coord_fixed()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句