這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān)怎樣使用R語(yǔ)言ggplot2畫柱形圖,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
創(chuàng)新互聯(lián)-云計(jì)算及IDC服務(wù)提供商,涵蓋公有云、IDC機(jī)房租用、眉山服務(wù)器托管、等保安全、私有云建設(shè)等企業(yè)級(jí)互聯(lián)網(wǎng)基礎(chǔ)服務(wù),聯(lián)系電話:18980820575
今天要模仿的圖片來(lái)自于論文 Core gut microbial communities are maintained by beneficial interactions and strain variability in fish。期刊是 Nature microbiology
今天重復(fù)的圖片是Figure3中的柱形圖
數(shù)據(jù)是三列:第一列用來(lái)做X,第二列做Y,第三列做誤差條
df1<-read.csv("Figure3_d.csv",header=T)
library(ggplot2)
ggplot(df1,aes(x=group,y=value))+
geom_col(aes(fill=group),color="black")
下面的代碼就不詳細(xì)介紹了,爭(zhēng)取錄制一期視頻來(lái)介紹
ggplot(df1,aes(x=group,y=value))+
geom_hline(yintercept = 0.5,lty="dashed")+
geom_hline(yintercept = 1,lty="dashed")+
geom_col(aes(fill=group),color="black")+
theme_bw()+
theme(panel.background = element_blank(),
panel.grid = element_blank(),
plot.title = element_text(hjust=0.5),
legend.position = "none")+
scale_y_continuous(expand = c(0,0),
limits = c(0,1.5))+
scale_x_discrete(labels=c("Positive\ninteractions","Negative\ninteractions"))+
annotate("segment",x=1,y=0.8,xend=1,yend=1)+
annotate("segment",x=2,y=0.4,xend=2,yend=0.5)+
labs(x=NULL,
y="Absolute fold change\nin growth from co-cultures\ncompared to monocultures",
title = "Average growth fold change in\nco-cultures")+
annotate("segment",x=1.1,y=1.2,xend=1.9,yend=1.2)+
annotate("segment",x=1,y=1.15,xend=1.1,yend=1.2)+
annotate("segment",x=1.9,y=1.2,xend=2,yend=1.15)+
annotate("text",x=1.5,y=1.3,label="P=0.0006")+
scale_fill_manual(values = c("#ff8080","#90bff9"))
x<-1:28
y<-sample(-100:150,28,replace = F)
df2<-data.frame(x,y)
df2$group<-ifelse(df2$y>0,"A","B")
df2$x<-factor(df2$x)
ggplot(df2,aes(x,y))+
geom_col(aes(fill=group),color="black")
df2$group<-factor(df2$group,
labels = c("Synergistic interactions",
"Non-synergistic interactions"))
ggplot(df2,aes(x,y))+
geom_hline(yintercept = -50,lty="dashed")+
geom_hline(yintercept = 50,lty="dashed")+
geom_hline(yintercept = 100,lty="dashed")+
geom_col(aes(fill=group),color="black")+
theme_bw()+
theme(panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(angle = 90,hjust=0.5,
vjust = 0.5),
plot.title = element_text(hjust = 0.5),
legend.position = "bottom",
legend.title = element_blank())+
scale_y_continuous(expand=c(0,0),
limits=c(-100,150),
breaks = c(-100,-50,0,50,100,150))+
labs(x="Pairwise interactions",
y="Percentage change from\nmonoculture",
title = "Synergistic versus non-synergistic\ninteractions")+
scale_fill_manual(values = c("#ff8080","#90bff9"))
library(cowplot)
pdf("Rplot11.pdf",width = 8,,height = 4)
plot_grid(p1,p2,ncol = 2,nrow=1,labels = c("d","e"))
dev.off()
上述就是小編為大家分享的怎樣使用R語(yǔ)言ggplot2畫柱形圖了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。