Customize Bar plot in R -GGplot2- in 5 steps : Beautiful publication ready bar plot

Rajendra Choure
Rajendra Choure
32.6 هزار بار بازدید - 3 سال پیش - #barplot
#barplot #errorbars #ggplot2 #Rprogramming
#R  #datavisualisation  #Rprogramming #ggplot #datanalysis #barplotcustomisation

This video discuss customisation of barplot in ggplot2 R. Reordering of categories, adding error bars, plot titles, themes and color palletes have been discussed.

library(tidyverse) # for summarizing the data to get means and sds of categories
library(ggsci) # for color palettes of scieintifc journals
library(ggpubr) # for theme pubr

iris_plot =  gather(iris,FlPrt,Length,1:4)

 iris_plot= group_by(iris_plot, Species,FlPrt)

 iris_plot=summarise(iris_plot,mnL=mean(Length),sdL=sd(Length))

iris_plot=  ggplot(iris_plot,aes(reorder(Species,mnL),mnL,fill=reorder(FlPrt,mnL)))+
 geom_bar(stat="identity",position="dodge")+
 geom_text(mapping=aes(label=mnL),position=position_dodge(width=0.9),
           cex=2.5,vjust=-4)+
 labs(title="Iris: Measurment of floral organs",
      subtitle="Length abd width of srpal abd petal",
      x="Species",y="Length ib cm",
      caption="Data: iris dataset by Edgar Anderson",fill="Description")+
 geom_errorbar(mapping=aes(ymin=mnL-sdL,ymax=mnL+sdL),
               width=0.2,position=position_dodge(width=0.9))+
 theme_classic()+scale_fill_jco()

0:00 Introduction
0:49 Install and load  required packages
1:34 Prepare data
2:34 initiate ggplot
3:36 Reorder categories of bars
4:56 Add value labels to bars
6:02 titles of plot elements
7:05 Add error bars
8:39 add theme to plot
10:16 Add color palettes
11:20 concluding remarks
3 سال پیش در تاریخ 1400/01/22 منتشر شده است.
32,636 بـار بازدید شده
... بیشتر