How to Create a Nice Box and Whisker Plot in R

plot of chunk nice-box-and-whisker-plot


How to Create a Nice Box and Whisker Plot in R

R codes are provided for creating a nice box and whisker plot in R with summary table under the plot.

# Load required R packages
library(ggpubr)

# Data preparation
df <- ToothGrowth
head(df)
##    len supp dose
## 1  4.2   VC  0.5
## 2 11.5   VC  0.5
## 3  7.3   VC  0.5
## 4  5.8   VC  0.5
## 5  6.4   VC  0.5
## 6 10.0   VC  0.5
# Create basic boxplot
ggboxplot(df, x = "dose", y = "len", add = "jitter")

plot of chunk nice-box-and-whisker-plot

# Create a box plot with summary table
ggsummarystats(
  df, x = "dose", y = "len", add = "jitter",
  color = "supp", palette = "npg",
  ggfunc = ggboxplot
)

plot of chunk nice-box-and-whisker-plot



Version: Français





No Comments

Give a comment

Want to post an issue with R? If yes, please make sure you have read this: How to Include Reproducible R Script Examples in Datanovia Comments