Boxplot in R

In this post I am going to show how to draw boxplot using R studio with existing data set. For this I am uisng sleep data set.
image
Boxplots
  • are a perfect way to compare distributions of different groups
  • allow a good overview: min, max, median,
  • quartiles 1 and 3, outliers
  • they often come together with ANOVA
  • standard tool for scientific publications
sleepboxplot = boxplot(data = sleep, extra ~ group,
                        main = "Change in sleep duration",
                        col.main = "red", ylab="change in hrs", xlab="drug")
image
to include the mean to the boxplot we can use below script.
attach(sleep)
means = by(extra, group, mean)
points(means, col = "red")
horizontalboxplot = boxplot(data = sleep, extra ~ group, ylab="", xlab="", horizontal = T)
image
To view the Hirizental box plot with filling colors, we can use below syntax
horizontalboxplot = boxplot(data = sleep, extra ~ group, ylab="", xlab="", horizontal = T, col = c("blue", "red") )
image
Thank You !!!
Boxplot in R Boxplot in R Reviewed by Pubudu Dewagama on 11:11:00 PM Rating: 5

No comments: