绘图导航
  • 基础绘图
  • 高级绘图
  • 微生物
  • 转录组

R语言|绘制三元相图

 二维码 9
作者:图图来源:图图云平台

vcd包绘制三元相图


【示例文件】

new_otu_table.txt


#install.packages("vcd")

library(vcd)

data = read.table("new_otu_table.txt",head=T,sep="\t",comment.char = "")

data1=head(data,n=20)

c=data1[c("A5","A7","B1")]

d<-as.matrix(c)

d<-d+0.000000000000000000001

colors<-c("#DC143C","#0000FF","#20B2AA","#FFA500","#9370DB","#98FB98","#F08080","#1E90FF","#7CFC00","#808000","#7B68EE","#483D8B","#6181BD4E","#F348004E","#64A10E4E","#9300264E","#464E044E","#049a0b4E","#4E0C664E","#D000004E")

ternaryplot(d,prop_size = TRUE,grid_color = "black",labels_color = "black",main ="ternaryplot",labels = "outside",col=c("#DC143C","#0000FF","#20B2AA","#FFA500","#9370DB","#98FB98","#F08080","#1E90FF","#7CFC00","#808000","#7B68EE","#483D8B","#6181BD4E","#F348004E","#64A10E4E","#9300264E","#464E044E","#049a0b4E","#4E0C664E","#D000004E"))

grid_legend(0.85, 0.7, 19,colors,data1[,1],frame = FALSE,size=1)

dev.off()





R自带数据集绘图示例


Arthritis数据集


#查看R自带数据集绘图示例

?ternaryplot()

# Arthritis数据集

## Build table by crossing Treatment and Sex

tab <- as.table(xtabs(~ I(Sex:Treatment) + Improved, data = Arthritis))

## Mark groups

col <- c("red", "red", "blue", "blue")

pch <- c(1, 19, 1, 19)

## plot

ternaryplot(

            tab,

            col = col,

            pch = pch,

            prop_size = TRUE,

            bg = "lightgray",

            grid_color = "white",

            labels_color = "white",

            main = "Arthritis Treatment Data"

           )

## legend

grid_legend(0.8, 0.7, pch, col, rownames(tab), title = "GROUP")



“作图帮”微信公众号同步更新

作图帮二维码.jpg


可添加下方微信进入【生信作图交流群】,群内免费分享绘图代码与示例数据

公司二维码.png




推荐使用谷歌浏览器点击下载