r - ggplot2 中每个主题具有不同颜色的意大利面条图

标签 r ggplot2

这是我到目前为止所做的,结果图如下:

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()

enter image description here

目标是使每行以不同的颜色显示。

最佳答案

使用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')

enter image description here

或者使用latticeExtra来获取ggplot2主题:

library(latticeExtra)
xyplot(c~a,data =x,groups=b,type='l',
       par.settings = ggplot2like(),axis=axis.grid)

enter image description here

关于r - ggplot2 中每个主题具有不同颜色的意大利面条图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17490515/

相关文章:

r - 如何从 ggplot2 中的 x 轴的 %m 中删除前导零

r - 将单独的图绘制在一起时自动调整轴限制

r - 在R中如何使用ggplot绘制正态分布的尾部区域?

r - 在 ggplot2 中创建计数频率的直方图

r - GGally putPlot 无法在循环中工作

r - 在R和knitr中,我可以抑制readOGR的消息吗?

r - 在 ggplot 中指定 map 的色阶

r - geom_密度()图中的多个组

R read.table csv with classic-mac 行结尾

r dplyr transmute_字符串输入错误