Reputation: 399
I have a data frame structured as follows:
df <- data.frame(combo = c("first", "second", "last"),
effect.size = cumsum(rnorm(3)),
upper.CI = cumsum(rnorm(3, mean = 3, sd=1)),
lower.CI = cumsum(rnorm(3, mean = -3, sd=1)))
I want to plot each combo with their associated confidence intervals. However, I am not sure how to plot extra points and connect them on the same line. The intended output is something like:
I am currently here, but can't figure out how to add the CI's:
ggplot(df, aes(x=effect.size, y=combo))+
geom_point()+
geom_vline(xintercept = 0, linetype = 2)+
theme_classic2()
All of the values I am trying to plot are singular numbers that are an output from a test, so I don't have a distribution of numbers to calculate CI's within ggplot.
Any help is appreciated.
Upvotes: 0
Views: 257
Reputation: 24722
You can use geom_pointrange
or geom_linerange
if you like.
ggplot(df, aes(effect.size, y=combo)) +
geom_pointrange(aes(xmin=lower.CI, xmax=upper.CI)) +
geom_vline(aes(xintercept = 0),linetype="dashed")
Upvotes: 1