我一直在从多个data.framework中进行绘制,基本上,posterior.m包含了90%置信区间的中位数。
ggplot() +
geom_line(data=posterior.m, aes(x=time,y=NO.y)) +
geom_line(data=posterior.05, aes(x=time,y=NO.y), linetype = "dotted") +
geom_line(data=posterior.95, aes(x=time,y=NO.y), linetype = "dotted")
基本上,posterior.m包含90%置信区间的中位数。 低05是在数据帧posterior.05和高95是在posterior.95。简而言之,这是一个有3条线的图。
问题是,我如何使用 geom_ribbon()
或类似于在中位数与下位数和中位数与上位数之间进行填充。或者干脆在下位数和上位数之间进行填充。我无法做到这一点,因为它们不是同一个数据框架的一部分。
谅谅
使用 mtcars
作为数据集的例子,可以这样实现。
在你的例子中,你必须通过 time
并可能重新命名你的vars。
library(dplyr)
library(ggplot2)
mtcars1 <- mtcars %>%
group_by(cyl) %>%
summarise(y_med = median(mpg))
#> `summarise()` ungrouping output (override with `.groups` argument)
mtcars2 <- mtcars %>%
group_by(cyl) %>%
summarise(y_05 = quantile(mpg, probs = .05))
#> `summarise()` ungrouping output (override with `.groups` argument)
mtcars3 <- mtcars %>%
group_by(cyl) %>%
summarise(y_95 = quantile(mpg, probs = .95))
#> `summarise()` ungrouping output (override with `.groups` argument)
mtcars_join <- left_join(mtcars1, mtcars2, by = "cyl") %>%
left_join(mtcars3, by = "cyl")
ggplot(mtcars_join, aes(cyl)) +
geom_ribbon(aes(ymin = y_med, ymax = y_95), fill = "red") +
geom_ribbon(aes(ymin = y_05, ymax = y_med), fill = "blue") +
geom_line(aes(y = y_med)) +
geom_line(aes(y = y_05), linetype = "dotted") +
geom_line(aes(y = y_95), linetype = "dotted")
创建于2020-06-14由 重读包 (v0.3.0)