简体   繁体   中英

Dot-and-whisker coefficient plots using only mean and 95% confidence interval estimates (not the data that produced them)

I have this:

workday <- data.frame(Measure = c("A", "A", "A"),
                      Session = c("Welcome", "Class 1", "Lunch Talk"),
                      Mean  = c(7.10, 8.90, 4.47),
                      Ci95  = c(0.40, 0.56, 0.33))

I need to create a coefficient plot similar to this from the package dwplot , where y-axis represents different categorical values of Session . The estimated mean should be a point, and the lower and upper 95% confidence intervals should be plotted as a horizontal line running through its corresponding mean.

I don't have the raw data used to produce the estimated mean ( Mean ) and 95% confidence intervals ( Ci95 ) - just the values themselves, as seen in workday . This is equivalent to a dwplot() with an argument position = identity from ggplot2 .

I can get here:

workday %>%
  ggplot(aes(x=Mean, y=Session)) + 
  geom_point(position="identity") +
  ggtitle("A")

在此处输入图像描述

But it obviously does not include the horizontal confidence interval line I need.

How can I use ggplot2 (or dwplot ) to produce the desired result?

Maybe try this:

library(tidyverse)
#Code
workday %>%
  mutate(Low=Mean-Ci95,High=Mean+Ci95) %>%
  ggplot(aes(x=Session, y=Mean)) + 
  geom_point() +
  geom_errorbar(aes(ymin=Low,ymax=High),width=0)+
  ggtitle("A")+
  coord_flip()

Output:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM