2011-10-13 71 views
28

我使用ggplot来绘制时间过程数据(固定比例随着时间的推移对屏幕上的不同对象),并希望使用色带显示SE,但色带本身在顶部和底部边缘,这使得阅读图形有点困难。我一直无法弄清楚如何摆脱这些边缘线。这里是我的剧情代码:ggplot:删除色带边缘的线

ggplot(gaze, aes(Time, Fix, color=Object, fill=Object)) + 
    stat_summary(fun.y="mean", geom="line", size=2) + 
    stat_summary(fun.data="mean_se", geom="ribbon", alpha=.3) 

有什么建议吗?

这是一个最小的工作示例。我压缩我的数据:

Time Object   y  lower  upper 
1 1000  C 0.12453389 0.04510504 0.2039627 
2 1000  T 0.58826856 0.37615078 0.8003864 
3 1000  U 0.09437160 0.03278069 0.1559625 
4 1100  C 0.12140127 0.03943988 0.2033627 
5 1100  T 0.64560823 0.44898727 0.8422292 
6 1100  U 0.06725172 0.01584248 0.1186610 

d <- structure(list(Time = c(1000L, 1000L, 1000L, 1100L, 1100L, 1100L), Object = structure(c(1L, 2L, 3L, 1L, 2L, 3L), .Label = c("C", 
"T", "U"), class = "factor"), y = c(0.12453389, 0.58826856, 0.0943716, 
0.12140127, 0.64560823, 0.06725172), lower = c(0.04510504, 0.37615078, 
0.03278069, 0.03943988, 0.44898727, 0.01584248), upper = c(0.2039627, 
0.8003864, 0.1559625, 0.2033627, 0.8422292, 0.118661)), .Names = c("Time", 
"Object", "y", "lower", "upper"), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6")) 

,这里是新的图形代码:

ggplot(d, aes(Time, y, color=Object, fill=Object)) + 
    geom_line(size=2) + 
    geom_ribbon(aes(ymin=lower, ymax=upper), alpha=.3, colour=NA) 
+0

你构建一个最小的工作示例。这意味着你应该添加一些简单的数据来运行你的图形命令。 – csgillespie

+0

谢谢,这似乎有所帮助。 –

回答

36

您可以使用colour参数删除边框

ggplot(d, aes(Time, y, fill=Object)) + 
    geom_line(size=2, aes(colour = Object)) + 
    geom_ribbon(aes(ymin=lower, ymax=upper), alpha=.3) 
2

在这里你去:

ggplot(d, aes(Time, y, color=Object, fill=Object)) + 
    geom_line(size=2) + 
    geom_ribbon(aes(ymin=lower, ymax=upper), alpha=.3) 
15

geom_ribbon理解linetype审美。只要给它NA,像这样:

ggplot(d, aes(Time, y, color=Object, fill=Object)) + 
    geom_line(size=2) + 
    geom_ribbon(aes(ymin=lower, ymax=upper, linetype=NA), alpha=.3) 

此处了解详情:http://docs.ggplot2.org/current/geom_ribbon.html

+0

'linetype = NA'不适用于我,但是,'linetype = 0'或'linetype ='blank''工作。 http://ggplot2.tidyverse.org/reference/aes_linetype_size_shape.html – fber