you need 3 columns, timestamp, value and std. And it's as simple as use your std column inside the aes(ymin, ymax):
library(tidyverse)
huron <- data.frame(year = 1875:1972,
value = LakeHuron,
std = runif(length(LakeHuron),0,1))
huron %>%
ggplot(aes(year, value)) +
geom_ribbon(aes(ymin = value - std, ymax = value + std), fill = "steelblue2") +
geom_line(color = "firebrick", size = 1)
In case you want to group your data, you should use fill = your_group and group = your_group inside the aes:
library(tidyverse)
huron <- data.frame(year = rep(1875:1972,2),
group = c(rep("a",98),rep("b",98)),
value = c(LakeHuron, LakeHuron + 5),
std = runif(length(LakeHuron)*2,0,1))
huron %>%
ggplot(aes(year, value, fill = group, group=group)) +
geom_ribbon(aes(ymin = value - std, ymax = value + std), fill =
"steelblue2") +
geom_line(color = "firebrick", size = 1)
I posted this tip here: https://typethepipe.com/vizs-and-tips/ggplot_geom_ribbon_shadow/ for more info. Hope it helps!