这是我到目前为止所做的,结果图如下:
set.seed(17)
require(ggplot2)
x = expand.grid(a=1:5, b=1:5)
x$c = rnorm(25)
png('test.png')
p = ggplot(x, aes(a, c, group=b)) + geom_line()
print(p)
dev.off()
savehistory()
目标是使每行以不同的颜色显示。
最佳答案
使用ggplot2
注释给你正确的答案:
You should coerce b to a factor and it as a color aes.
使用lattice
无需强制b进行因子分解:
library(lattice)
xyplot(c~a,data =x,groups=b,type='l')
或者使用latticeExtra
来获取ggplot2
主题:
library(latticeExtra)
xyplot(c~a,data =x,groups=b,type='l',
par.settings = ggplot2like(),axis=axis.grid)
关于r - ggplot2 中每个主题具有不同颜色的意大利面条图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17490515/