三元散点图
目的:绘制NMF, 细胞比例,WGCNA的相关性三元散点图
工作路径:/media/sdc/yueyao/project/20200405_pearson
输入文件格式
OUT_ID | Soil | Root | Rhizosphere | ave_ra | enrichment |
---|---|---|---|---|---|
OTU_1005 | 0 | 0 | 0 | 0 | none |
OTU_1011 | 0 | 0 | 0.017502 | 0.005834 | none |
OTU_1015 | 0 | 0.006401 | 0 | 0.002134 | none |
OTU_1016 | 0 | 0 | 0.026254 | 0.008751 | none |
OTU_1022 | 0 | 0 | 0 | 0 | none |
OTU_1023 | 0 | 0 | 0.008751 | 0.002917 | none |
OTU_1024 | 0 | 0 | 0 | 0 | none |
OTU_1025 | 0 | 0 | 0 | 0 | none |
OTU_1026 | 0 | 0 | 0 | 0 | none |
OTU_1027 | 0 | 0 | 0 | 0 | none |
OTU_1029 | 0 | 0 | 0 | 0 | none |
OTU_1032 | 0 | 0.006401 | 0 | 0.002134 | none |
作图代码如下
install.packages("ggtern")
## 加载ggtern包
library("ggtern")
#读入数据,存到data变量中
data<-read.table("result.xls",header = T,sep = " ",row.names = 1)
#查看数据框data的前6行
head(data)
#建立数据的映射关系,绘制三元图
p1<-ggtern(data=data,aes(x=Root,y=Soil,z=Rhizosphere))+
geom_point(aes(size=ave_ra,color=enrichment),alpha=0.8)
p1
#手动设置点的颜色,“土壤”褐色,“根际”橙色,“根”绿色,未能显著富集到的为灰色
p2<-p1+scale_colour_manual(values = c("grey", "#f68b23","#00a070","#7e532f"))
p2
#尝试不同的主题
p3<-p2+theme_minimal()+
theme_legend_position(x = "topleft")
p3
p4<-p2+theme_bw()+
theme_legend_position(x = "tr")
p4
p5<-p2+theme_void()+
theme_legend_position(x = "tr")
p5
#保存图表为pdf格式
ggsave("p5.pdf",width = 4.4,height = 4,units = "in")
输出图片格式