Тёмный

How to plot barplots similar to those in journal articles using R and ggplot2 and other packages 

Rajendra Choure
Подписаться 8 тыс.
Просмотров 2,9 тыс.
50% 1

#datavisualization #rprogramming #barcharts #ggplot2 #barplot
#research
This is a complete tutorial to plot publication-ready bar plots.
In this video, I have demonstrated how to plot a barplot similar to those we see in research articles in scientific journals. Here I have plotted the barplot using ggplot2 functions. The bar plots are in grayscale and mapped to a categorical variable. I have discussed how to rearrange the bars as per our requirement. Error bars also are plotted and customized. Some journals require error bars only at top of bars, I have discussed using ggAnnotate package function geom_halferrorbar().
The originalplots are form :
Mikuláss KR, Nagy K, Bogos B, Szegletes Z, Kovács E, Farkas A, Váró G, Kondorosi É, Kereszt A. Antimicrobial nodule-specific cysteine-rich peptides disturb the integrity of bacterial outer and inner membranes and cause loss of membrane potential. Ann Clin Microbiol Antimicrob. 2016 Jul 28;15(1):43. doi: 10.1186/s12941-016-0159-8. PMID: 27465344; PMCID: PMC4964015.
Data used is not original. I just made up the data to make similar plots.
Loink to dwonload data: docs.google.co...
#the code
setwd("D:\\RGC work\\Rworks\\bargraphasyouseeinpublications")
to read xlsx file
library(readxl)
for half error bars
install.packages("remotes")
remotes::install_github("azzoam/ggAnnotate")
library(ggAnnotate)
df1 = read_xlsx("data.xlsx",range="A1:C6")
df1$Ab = factor(df1$Ab,levels=c("Chloroform+SDS" ,"Polymyxin B" , "NCR335", "NCR247" , "NCR001"))
library(ggplot2)
p1 = ggplot(df1,aes(Ab,MillerUnit,fill=Ab,label=MillerUnit))+
geom_col()+
geom_halferrorbar(aes(ymax=MillerUnit+SD),width=0.2,size=1,color="black")+
scale_fill_grey()+
geom_text(vjust=-1.5)+
theme_classic()+
scale_y_continuous(expand=c(0,0))+
expand_limits(y=c(0,150))+
theme(legend.position = "none",axis.text.x = element_text(angle=90,vjust=0.2,hjust=0.9),text=element_text(size=14,face="bold",colour = "black"))+
labs(x="",y="Miller Units %")
df2 = read_xlsx("data.xlsx",range="A8:C14")
df2$Ab = factor(df2$Ab,levels=c("Control", "CCCP" , "Polymyxin B", "NCR335" , "NCR247" , "NCR001" ))
library(ggplot2)
p2 = ggplot(df2,aes(Ab,`Relative Fluorescence` ,fill=Ab ))+
geom_col()+
geom_halferrorbar(aes(ymax=`Relative Fluorescence` +SD),width=0.2,size=1,color="black")+
scale_fill_grey()+
theme_classic()+
scale_y_continuous(expand=c(0,0))+
expand_limits(y=c(0,0.8))+
theme(legend.position = "none",axis.text.x = element_text(angle=90,vjust=0.2,hjust=0.9),text=element_text(size=14,face="bold",colour = "black"))+
labs(x="",y="Relative Fluorescence(red/green) %")+
geom_hline(yintercept=0.25,linetype=3,size=2,color="grey40")
for arranging multiiple graphs together
library(patchwork)
p = p1/p2
p+plot_annotation(tag_levels = "a")
Facebook page:
/ rajendrachoureisc
Mail Id:
rajuchoure@gmail.com
youtube playlist:
• R programming tutorials

Опубликовано:

 

13 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 21