修改geom_ribbon边框 [英] Modifying geom_ribbon borders

查看:187
本文介绍了修改geom_ribbon边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



由于以下原因,我正在绘制一系列随时间变化的方法和标准偏差,并尝试使用geom_ribbon显示sd,见下文。重要的重叠我想添加一个边框到与相应的变量相同的颜色但是是虚线的边框,但我无法弄清楚代码中的哪个位置。我知道颜色和线型命令涉及到某些方面...

谢谢!

$ pre > graph.msd <-ggplot(data = g.data,aes(x = quarter,y = mean,group = number))
graph.msd< - graph.msd + geom_line(aes(color = number),size = 1)+ geom_ribbon(aes(ymin = mean-sd,ymax = mean + sd,fill = number),linetype = 2,alpha = 0.1)

解决方案

您需要为颜色 to geom_ribbon 类似于

  graph.msd<  - 图.msd + 
geom_line(aes(color = number),size = 1)+
geom_ribbon(aes(ymin = mean-sd,ymax = mean + sd,
fill = number,color =数字),linetype = 2,alpha = 0.1)

用一个可重复的例子?geom_ribbon

  huron<  -  data.frame( year = 1875:1972,level = as.vector(Lake Huuron))
library(plyr)#访问round_any
h uron $ 10 < - round_any(huron $ year,10,floor)

ggplot(huron,aes(x = year,group = decade))+
geom_ribbon(aes(ymin =等级1,ymax =等级+1,
颜色=因子(十年),fill =因子(十年)),
linetype = 2,alpha = 0.1)


I am plotting a series of means and standard deviations over time with code below, and am trying to use geom_ribbon to display the sd's, see below.

Due to the significant overlap I'd like to add a border to the ribbons that is the same color as the corresponding variable but is a dashed line, but I can't figure out where in the code this would go. I know "colour" and "linetype" commands are involved somehow...

Thanks!

graph.msd <- ggplot(data=g.data, aes(x=quarter,y=mean,group=number)) 
graph.msd <- graph.msd + geom_line(aes(colour = number),size=1)+geom_ribbon(aes(ymin=mean-sd,ymax=mean+sd,fill=number),linetype=2,alpha=0.1)

解决方案

You need pass a value for colour to geom_ribbon something like

graph.msd <- graph.msd + 
 geom_line(aes(colour = number),size=1)+
 geom_ribbon(aes(ymin = mean-sd, ymax = mean+sd, 
                 fill = number,colour = number), linetype=2, alpha=0.1)

with a reproducible example (using a variant on the examples in ?geom_ribbon

huron <- data.frame(year = 1875:1972, level = as.vector(LakeHuron))
library(plyr) # to access round_any
huron$decade <- round_any(huron$year, 10, floor)

ggplot(huron, aes(x =year, group = decade)) + 
  geom_ribbon(aes(ymin = level-1, ymax = level+1, 
      colour = factor(decade), fill = factor(decade)), 
    linetype = 2, alpha= 0.1)

这篇关于修改geom_ribbon边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆