作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使用 ggplot2
和 stat_summary
来显示我选择的颜色?例如:
simVol <- data.frame(simId=c(1,1,1,1,2,2,2,2),
farm=rep(c('farm A', 'farm A', 'farm B', 'farm B'),2),
period=rep(1:2,4),
volume=c(9,21,12,18,10,22,11,19))
P10meanP90 <- function(x) data.frame(
y = mean(x),
ymin = quantile(x, .1),
ymax = quantile(x, .9)
)
此命令使用默认颜色绘制每个农场的体积分布与时间的关系:
ggplot(simVol, aes(x=period, y=volume, colour=farm)) +
stat_summary(fun.data="P10meanP90", geom="smooth", size=2)
但是,如果我将 colour='green'
添加到 stat_summary
的参数中,它会绘制整个农场的总和。我试过使用 colour=c('green','orange')
,但这仍然只显示一条绿线。
如何更改图中的颜色?
谢谢
最佳答案
scale_colour_manual
是您正在寻找的功能。 http://docs.ggplot2.org/0.9.3.1/scale_manual.html
ggplot(simVol, aes(x=period, y=volume, colour=farm)) +
stat_summary(fun.data="P10meanP90", geom="smooth", size=2) +
scale_colour_manual(values = c("green", "orange"))
关于r - 如何在 ggplot2 stat_summary 图中设置多种颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21817856/
我是一名优秀的程序员,十分优秀!