image.png
重复的图片是Figure2中的直方图
image.png
直方图的数据相对比较简单,只需要准备一列x和一列y即可
另存为csv格式,存储到Rstudio的工作目录下。这边我命名为 example_1.csv
df<-read.csv("example_1.csv",header=T)
df
使用geom_col()函数
ggplot(df,aes(x=x,y=y))+
geom_col()
image.png
width=1
这个参数ggplot(df,aes(x=x,y=y))+
geom_col(width = 1)
image.png
color
参数ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black")
image.png
fill
参数ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black",fill="grey")
image.png
labs()
函数ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black",fill="grey")+
labs(x="Niche width",y="Number of ESVs")
image.png
theme()
进行设置ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black",fill="grey")+
labs(x="Niche width",y="Number of ESVs")+
theme(panel.background = element_blank())
image.png
ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black",fill="grey")+
labs(x="Niche width",y="Number of ESVs")+
theme(panel.background = element_blank(),
axis.line = element_line())
image.png
geom_vline()
函数ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black",fill="grey")+
labs(x="Niche width",y="Number of ESVs")+
theme(panel.background = element_blank(),
axis.line = element_line())+
geom_vline(xintercept = 4,lty="dashed",color="red")
image.png
geom_rect()
函数ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black",fill="grey")+
labs(x="Niche width",y="Number of ESVs")+
theme(panel.background = element_blank(),
axis.line = element_line())+
geom_vline(xintercept = 4,lty="dashed",color="red")+
geom_rect(aes(xmin=4.02,xmax=4.5,ymin=0,ymax=1200),
fill="red",alpha=0.2)
image.png
ggplot(df,aes(x=x,y=y))+
geom_col(width = 1,color="black",fill="grey")+
labs(x="Niche width",y="Number of ESVs")+
theme(panel.background = element_blank(),
axis.line = element_line())+
geom_vline(xintercept = 4,lty="dashed",color="red")+
geom_rect(aes(xmin=4.02,xmax=4.5,ymin=0,ymax=1200),
fill="red",alpha=0.2)+
annotate("text",x=0,y=1250,label="Specialist microbes")+
annotate("text",x=4,y=1250,label="Generalist microbes")