这就是为什么ggplot
如此流行... AFAIK,图中基R图形一个彩条说明需要具有两列创建布局,并把一个image(...)
在第二时隙中,如在一个很好的例子:
n =30
color=rainbow(n, s = 1, v = 1, start = 0, end = max(1, n - 1)/n, alpha = 1)
layout(t(1:2),widths=c(6,1))
x=0:10
par(mar=c(4,4,1,0.5))
plot(x,1*x,col=color[1],type="l")
for (i in seq(2,30)){
lines(x,i*x,col=color[i])}
par(mar=c(5,1,5,2.5))
image(y=2:30,z=t(2:30), col=color[2:30], axes=FALSE, main="Slope", cex.main=.8)
axis(4,cex.axis=0.8,mgp=c(0,.5,0))
有关所有那些晦涩情节参数(mar
,mgp
,cex.main
等,.etc),类型信息。此外,还有几个软件包试图使这更容易:here和here
而且,即使您没有要求它,一个ggplot
解决方案。
library(ggplot2)
n <- 30
df <- expand.grid(x=0:10,slope=2:n)
df$y <- with(df,x*slope)
ggplot(df) + geom_line(aes(x,y,group=slope,color=slope))+
coord_cartesian(ylim=c(0,10))+
scale_color_gradientn(colours=rainbow(n))+
theme_bw()