我正在使用ggplot
绘制时间进程数据(随着时间的推移固定比例到屏幕上的不同对象)并想要使用功能区来显示SE,但功能区本身在顶部和底部都有线条边缘,这使得阅读图形有点困难。我无法弄清楚如何摆脱这些边缘线。这是我的情节代码:
ggplot(d, aes(Time, y, 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)
答案 0 :(得分:45)
您可以使用colour
参数删除边框:
ggplot(d, aes(Time, y, color = Object, fill = Object)) +
geom_line(size = 2) +
geom_ribbon(aes(ymin = lower, ymax = upper), alpha = .3, colour = NA)
答案 1 :(得分:25)
geom_ribbon
了解linetype
美学。如果您想将线型映射到变量,请将其包含在aes()
参数中,否则,请将linetype
放在外面,然后将其0
赋予它,如下所示:
ggplot(d, aes(Time, y, color = Object, fill = Object)) +
geom_line(size = 2) +
geom_ribbon(aes(ymin = lower, ymax = upper), linetype = 0, alpha = .3)
答案 2 :(得分:2)
你去吧
ggplot(d, aes(Time, y, fill=Object)) +
geom_line(size=2, aes(colour = Object)) +
geom_ribbon(aes(ymin=lower, ymax=upper), alpha=.3)
答案 3 :(得分:1)
ggplot2
的{{1}}现在包含一个geom_ribbon()
参数,该参数有助于控制功能区轮廓的显示方式。
outline.type
由reprex package(v0.3.0)于2020-05-28创建
或者,如建议的那样,我们可以设置library(tidyverse)
huron <- tibble(year = 1875:1972, level = as.vector(LakeHuron))
huron %>%
ggplot(aes(year, level)) +
geom_ribbon(aes(ymin = level - 1, ymax = level + 1),
fill = "grey70", color = "red",
outline.type = "lower") +
geom_line(aes(y = level))
删除所有行。
linetype = 0
由reprex package(v0.3.0)于2020-05-28创建