Fig3-E 2020-12-07

2022-04-16  本文已影响0人  RashidinAbdu

1.用Excel准备数据并存为CSV格式,数据格式与内容为:


image.png

读取数据:

e<-read.csv(file.choose())
e
image.png

2.开始作图:

library(ggplot2)
ep<-ggplot(e,aes(x=Pairwise.connections,y=Percentage.change.from.monoculture,fill=pos))+geom_bar(stat="identity")
ep
image.png

然后对图例的文字,位置,坐标轴等进行修改:

ep<-ep+theme(legend.position="bottom")#图例调整到最低部分
ep
image.png

去除legend title:

ep<-ep+theme(legend.title = element_blank())
ep
image.png

对坐标轴标签进行角度变化:

ep<-ep+theme(axis.text.x = element_text(angle = 90, hjust = 1))
ep

得到:


image.png

调整横坐标名字的格式:

ep<-ep + theme(axis.title.x = element_text(size = 15, color = "black", face = "bold", vjust = 0.5, hjust = 0.5))
ep

得到:


image.png

调整纵坐标的名称格式:

ep<-ep + theme(axis.title.y = element_text(size = 15, color = "black", face = "bold", vjust = 0.5, hjust = 0.5))
ep

得到:


image.png

调整横坐标标签的间隔:

ep<-ep + scale_x_continuous(breaks=seq(0, 14, 1))
ep

得到


image.png

给纵轴标签间隔进行调整:

ep<-ep + scale_y_continuous(breaks=seq(-40, 150,20 ))
ep

得到:


image.png

删除垂直网格线:

ep<-ep + theme(panel.grid.major.x = element_blank() ,panel.grid.minor.x = element_blank())
ep

得到:


image.png

添加图片名称:

ep<-ep + labs(title="Synergistic versus non-synergistic
interactions")
ep

总的代码:

library(ggplot2)#加载包
 e<-read.csv(file.choose())#读取数据
head(e)
#作图
ep<-ggplot(e,aes(x=Pairwise.connections,y=Percentage.change.from.monoculture,fill=pos))+geom_bar(stat="identity")
ep<-ep+theme(legend.position="bottom")#图例调整到最低部分
ep<-ep+theme(legend.title = element_blank())
ep<-ep+theme(axis.text.x = element_text(angle = 90, hjust = 1))
ep<-ep + theme(axis.title.x = element_text(size = 15, color = "black", face = "bold", vjust = 0.5, hjust = 0.5))
ep<-ep + theme(axis.title.y = element_text(size = 15, color = "black", face = "bold", vjust = 0.5, hjust = 0.5))
ep<-ep + scale_y_continuous(breaks=seq(-100, 150,50 ))
ep<-ep + scale_x_continuous(breaks=seq(0, 14, 1))
ep<-ep + labs(title="Synergistic versus non-synergistic interactions")
ep<-ep + theme(panel.grid.major.x = element_blank() ,panel.grid.minor.x = element_blank())
ep<-ep+theme(panel.grid.major.y = element_line(colour = "black")  ,panel.grid.minor.y = element_blank())
ep
image.png
上一篇 下一篇

猜你喜欢

热点阅读