Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我到目前为止所做的,结果图如下:
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评论会给你正确的答案:
ggplot2
您应该将 b 强制为一个因素,并将其作为颜色 aes。
无需lattice强制 b 考虑:
lattice
library(lattice) xyplot(c~a,data =x,groups=b,type='l')
或latticeExtra用于获取ggplot2主题:
latticeExtra
library(latticeExtra) xyplot(c~a,data =x,groups=b,type='l', par.settings = ggplot2like(),axis=axis.grid)