无法将标题置于R中的饼图顶部

时间:2016-06-14 18:43:25

标签: r charts pie-chart

我使用自定义函数制作饼图,根据条件,我绘制一个饼图或两个饼图。我在输入文件中有两行的情况,对应于两个馅饼效果很好,但是当输入文件是单行对应单个饼时,我无法调整图例的字体大小并将标题添加到顶部那个阴谋。这是我的功能

pie_plot<-function(mean.IU,isoforms,gene.name,output.file,group,output.screen){
  n.isoform<-length(isoforms)
  color.pie<-as.vector(t(sapply(seq(1,0.1,length.out=n.isoform/5),function(i)rainbow(5,s=i))))

  if (nrow(mean.IU)==2){
    pdf(output.file,width=15)

    par(mar=c(0,0,0,0),oma=c(0,0,10,0),bg="seashell")
    layout(matrix(1:3,nrow=1),widths=c(2,1,2))
    pie(mean.IU[1,],col=color.pie,labels=ifelse(round(mean.IU[1,],3)<0.005,NA,paste(round(mean.IU[1,],3)*100,"%",sep="")),cex=max(0.4,1.71-0.121*sqrt(n.isoform)),radius=0.8)
    mtext(group[1],cex=2)
    plot.new()
    legend("center",legend=isoforms,title="Isoform",fill=color.pie,bty="n",cex=max(0.25,3.0-sqrt(n.isoform)*0.25),ncol=1)
    pie(mean.IU[2,],col=color.pie,labels=ifelse(round(mean.IU[2,],3)<0.005,NA,paste(round(mean.IU[2,],3)*100,"%",sep="")),cex=max(0.4,1.71-0.121*sqrt(n.isoform)),radius=0.8)
    mtext(group[2],cex=2)
    mtext(paste("Pie charts for gene ",gene.name,sep=""),outer=TRUE,cex=2.5,line=5,font=2)

    dev.off()
  }
  else{
    pdf(output.file,width=15)

    par(mar=c(0,0,0,0),oma=c(0,0,5,0),bg="seashell")
    layout(matrix(1:2,nrow=1),widths=c(7,3))
    pie(mean.IU[1,],col=color.pie,labels=ifelse(round(mean.IU[1,],3)<0.005,NA,paste(round(mean.IU[1,],3)*100,"%",sep="")),cex=max(0.4,1.71-0.121*sqrt(n.isoform)),radius=0.8)
    mtext(group[1],cex=2)
    plot.new()
    legend("center",legend=isoforms,title="Isoform",fill=color.pie,bty="n",cex=max(0.1,3.0-sqrt(n.isoform)*0.20),ncol= 1)
    mtext(paste("Pie chart for gene ",gene.name,sep=""),outer=TRUE,cex=2.5,line=5,font=2)
    dev.off()      
  }
}

我在哪里做错了?

1 个答案:

答案 0 :(得分:0)

我刚刚意识到情节边缘存在问题,当我将其更改为第二个条件时,一切都很顺利。

我已从par(mar=c(0,0,0,0),oma=c(0,0,5,0),bg="seashell")更改为par(mar=c(0,0,0,0),oma=c(0,0,10,0),bg="seashell")

相关问题