I have a data set that looks like this
well time mm sem
x basal 83.96792 8.068338
x stimulus1 153.17250 8.338465
x recovery 60.45712 5.97283
x stimulus2 154.26550 6.533665
and a graph that is made from this code
ggline(df, x = 'time', y = 'mm', color = 'well', palette = c("#00AFBB", "#E7B800")) +
theme_grey()
I want to add SEM bars to each of the four data points with my already calculated SEM number (each of the four points is a sum of a duration so that's how I have an SEM for each point) to make the graph look like this
any idea on how to go about that?
You can write:
ggplot(df, aes(x = time, y = mm, group = well)+
geom_point()+
geom_line()+
geom_errorbar(aes(ymin = mm-sem, ymax = mm+sem), width = 0.2)
So, it should look like:
But based on your dataframe and your code, I think you are more looking for something like this:
ggplot(df, aes(x = factor(time,unique(time)), y =mm, group = well, color = time))+
geom_point()+
geom_errorbar(aes(ymin = mm-sem, ymax = mm+sem), width = 0.2)+
scale_color_manual(values = rep(c("#00AFBB", "#E7B800"),2))
Does it answer your question ?
Reproducible example
structure(list(well = c("x", "x", "x", "x"), time = c("basal",
"stimulus1", "recovery", "stimulus2"), mm = c(83.96792, 153.1725,
60.45712, 154.2655), sem = c(8.068338, 8.338465, 5.97283, 6.533665
)), row.names = c(NA, -4L), class = c("data.table", "data.frame"
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With