在R中绘制饼图

时间:2012-10-27 19:25:01

标签: r pie-chart

totalReads=10000
mappedReads=8000
mappedTargetReads=6000
unmappedReads=totalReads-mappedReads
offtargetmappedReads=mappedReads-mappedTargetReads
data<-c(mappedReads,unmappedReads,mappedTargetReads,offtargetmappedReads)
round(data[1]/totalReads*100)->a
round(data[2]/totalReads*100)->b
round(data[3]/mappedReads*100)->c
round(data[4]/mappedReads*100)->d
pct<-c(a,b,c,d)
labels<-c("MappedReads","UnmappedReads","On-exon","Off-exon")
labels<-paste(labels,pct)
labels<-paste(labels,"%", sep="")
pie(c(mappedReads,unmappedReads,mappedTargetReads,offtargetmappedReads),labels=labels)

其中基本上独立地绘制了所有四个切片。但是这里mappedTargetReadsofftargetmappedReads是根据映射的读数进行计算的,因此,我想细分mappedReads切片,并在mappedTargetReadsofftargetmappedReads中表示{ {1}}。

或者是否可以在一个Rplot中将两个不同的饼图彼此相邻?

1 个答案:

答案 0 :(得分:2)

这会产生一个带有两个饼图的图:

par(mfrow = c(1,2))
pie(c(mappedReads,unmappedReads),labels=labels[1:2], main = "Global")
pie(c(mappedTargetReads,offtargetmappedReads),labels=labels[3:4],
    main = "MappedReads")

enter image description here