I have a data frame that contains four variables. (1) a variable indicating the period (2) estimates values (3) upper critical point of the confidence interval of (1) (4) lower critical point of the confidence interval of (1)
Specifically, I manually made the following data frame
> my.dt <- data.frame(year = c(2017, 2018, 2019),
estimate = c(-20.866263, -29.28182, -33.37095),
up = c(-20.866263 + 2*4.159101, -29.28182 + 2*4.372621, -33.37095 + 2*4.707303),
down = c(-20.866263 - 2*4.159101, -29.28182 - 2*4.372621, -33.37095 - 2*4.707303))
> my.dt
year estimate up down
1 2017 -20.86626 -12.54806 -29.18446
2 2018 -29.28182 -20.53658 -38.02706
3 2019 -33.37095 -23.95634 -42.78556
Here, how can I draw (pointwise) confidence interval
like below:

This can be done with the following code. You want to use geom_errorbar :-)
ggplot(my.dt, aes(x=year, y=estimate)) +
geom_point(size = 5) +
geom_errorbar(aes(ymin = down, ymax = up))

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