library(openxlsx) library(dplyr) library(ggplot2) library(gridExtra) df<-read.xlsx("http://kanggc.iptime.org/book/data/subtotal-e.xlsx") df dept_name_1 <- df %>% group_by(dept, class) %>% summarise(mean_total = mean(total)) dept_name_1 dept_name_2 <- df %>% group_by(dept, class) %>% summarise(sd_total = sd(total)) dept_name_2 plot1<-ggplot(data=dept_name_1, aes(x=dept, y=mean_total, fill=class)) + geom_col(position="dodge2") plot2<-ggplot(data=dept_name_2, aes(x=dept, y=sd_total, fill=class)) + geom_col(position="dodge2") marrangeGrob(grobs=list(plot1, plot2), nrow=2, ncol=1)