使用ggplot2包绘制PCoA图
#加载R包
library(ggplot2)
#读取电脑中csv文件
data <- read.csv(file = file.choose(),header = T,sep = ",")
#
Bacteria_pcoa <-ggplot(data,aes(PC1,PC2))+theme_bw()#加载x、y轴,设置主题为黑白
+geom_point(aes(color=group2,shape=group2,fill=group2),stroke=0.5,size=5)#填充点的颜色、形状与大小
+scale_color_manual(values = rep(c("#02B1e6","#20e81d"),time=9))#点边框的颜色
+scale_fill_manual(values = rep(c("#02B1e6","#20e81d"),time=9))#点内部的颜色
+scale_shape_manual(values = rep(c(21,22),time=9))#点的形状
+theme(axis.text=element_text(colour='black',size=12,face = "bold"),axis.title=element_text(colour='black',size=15,face = "bold"))
+labs(x="PC1(25.34%)",y="PC2(16.17%)")#设置x、y轴轴标题
+geom_hline(yintercept=0,linetype=3) #添加水平轴线,y轴刻度为0,类型为3,虚线
+ geom_vline(xintercept=0,linetype=3) #添加垂直轴线,x轴刻度为0,类型为3,虚线
+theme(panel.grid = element_blank())#删除背景网格
+theme(plot.title=element_text(colour='black', size=15,face = "bold",hjust =0.52,vjust=0.5))#设置标题格式(颜色、字号、字形、位置)
+labs(title="细菌_PCoA")#设置标题内容
+theme(legend.title = element_blank(),legend.text=element_text(face="bold", color="black", size=15)) #legend函数,向绘图添加图例,
+scale_x_continuous(limits = c(-0.2,0.2))+scale_y_continuous(limits =c(-0.2,0.2) )#设置x、y轴范围