Bar plot of Group Means with Individual Observations

October 27, 2016
By

[This article was first published on Easy Guides, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

ggpubr is great for data visualization and very easy to use for non-“R programmer”. It makes easy to simply produce an elegant ggplot2-based graphs. Read more about ggpubr: ggpubr .

Here we demonstrate how to plot easily a barplot of group means +/- standard error with individual observations.

Example data sets

d <- as.data.frame(mtcars[, c("am", "hp")])
d$rowname <- rownames(d)
head(d)
##                   am  hp           rowname
## Mazda RX4          1 110         Mazda RX4
## Mazda RX4 Wag      1 110     Mazda RX4 Wag
## Datsun 710         1  93        Datsun 710
## Hornet 4 Drive     0 110    Hornet 4 Drive
## Hornet Sportabout  0 175 Hornet Sportabout
## Valiant            0 105           Valiant

Install ggpubr

The latest version of ggpubr can be installed as follow:

# Install ggpubr
if(!require(devtools)) install.packages("devtools")
devtools::install_github("kassambara/ggpubr")

Bar plot of group means with individual informations

  • Plot y = “hp” by groups x = “am”
  • Add mean +/- standard error and individual points: add = c(“mean_se”, “point”). Allowed values are one or the combination of: “none”, “dotplot”, “jitter”, “boxplot”, “point”, “mean”, “mean_se”, “mean_sd”, “mean_ci”, “mean_range”, “median”, “median_iqr”, “median_mad”, “median_range”.
  • Color and fill by groups: color = “am”, fill = “am”
  • Add row names as labels.
library(ggpubr)
# Bar plot of group means + points
ggbarplot(d, x = "am", y = "hp",
          add = c("mean_se", "point"),
          color = "am", fill = "am", alpha = 0.5)+ 
  ggrepel::geom_text_repel(aes(label = rowname))
Bar plot of Group Means with Individual Observations

Bar plot of Group Means with Individual Observations


To leave a comment for the author, please follow the link and comment on their blog: Easy Guides.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers

Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)