KKolo
KKolo

Reputation: 35

Create BoxPlot in R with PreSummarized Data

I have aggregated cost data that is already summarized. I do not have access to the raw data. I have the mean, standard deviation, median, and IQR. The data looks like this:

enter image description here

I would like to create boxplots in R using this data. Any help would be appreciated.

Upvotes: 0

Views: 161

Answers (1)

DaveArmstrong
DaveArmstrong

Reputation: 21992

How about this:

dat <- data.frame(
  Mean_Cost = c(300, 760, 500), 
  Std = c(20,55,100), 
  Median_Cost = c(200, 222, 467), 
  LowerIQR = c(150, 100, 333), 
  UpperIQR = c(220, 300, 500), 
  Group = c(1,2,3))


ggplot(dat, aes(xmin = Group-.25, xmax=Group+.25, ymin=LowerIQR, ymax=UpperIQR)) + 
  geom_rect(fill="transparent", col = "black") + 
  geom_segment(aes(y=Median_Cost, yend=Median_Cost, x=Group-.25, xend=Group+.25)) + 
  scale_x_continuous(breaks=1:3, labels=c("Group 1", "Group 2", "Group 3")) + 
  theme_classic() + 
  labs(x="", y="Cost")

enter image description here

Upvotes: 1

Related Questions