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 plot1<-ggplot(data=dept_name_1, aes(x=dept, y=mean_total, fill=class)) + geom_col(position="dodge2") + ggtitle("Bar Chart of Total Mean by dept & class")+ theme(plot.title = element_text(hjust = 0.5)) plot2<-ggplot(data=dept_name_1, aes(x=class, y=mean_total, fill=dept)) + geom_col(position="dodge2") + ggtitle("Bar Chart of Total Mean by class & dept")+ theme(plot.title = element_text(hjust = 0.5)) marrangeGrob(grobs=list(plot1, plot2), nrow=2, ncol=1)