Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 将使用paste()生成的字符传递给多行文字()_R_Expression_Heatmap_Gplots - Fatal编程技术网

R 将使用paste()生成的字符传递给多行文字()

R 将使用paste()生成的字符传递给多行文字(),r,expression,heatmap,gplots,R,Expression,Heatmap,Gplots,我想尝试通过调用heatmap.2来生成热图的函数。除此之外,我还想通过调用add.expr生成绘图的标题,例如: add.expr=c(mtext(text=titlestring, side=3, line=4, cex=1) heatmap.2 (as.matrix(matToPlot[,(1:totCols)]), Rowv=FALSE, Colv=FALSE, dendrogram="none", breaks=seq(0,1,by=1/len

我想尝试通过调用heatmap.2来生成热图的函数。除此之外,我还想通过调用add.expr生成绘图的标题,例如:

add.expr=c(mtext(text=titlestring, side=3, line=4, cex=1)
 heatmap.2 (as.matrix(matToPlot[,(1:totCols)]),
         Rowv=FALSE, Colv=FALSE, dendrogram="none", 
         breaks=seq(0,1,by=1/length(methColors)),
         col=methColors, trace="none",colsep=colsep,sepcolor=c("sky blue"),
         #main=paste(titlestring,subtitlestring,chromstring,sep="\n"),
         add.expr=c(mtext(text="Read coverage of Dox Plus on 5kb flanked CpG
          Island promoters in mm9", side=3, line=4, cex=1),
         mtext(text="Island set represents island for which ChIP data is avilable
          and is order by mean(H3K4me3)-mean(H3K27me3) within islands", side=3, line=2, cex=0.8),
         mtext(text="H3K27me3", side=1, adj=0.125, line=3),
         mtext(text="H3K4me3", side=1, adj=0.375, line=3),
         mtext(text="H3K4me1", side=1, adj=0.625, line=3),
         mtext(text="Methylation", side=1,adj=0.9, line=3))) 
标题字符串是另一个函数传递给该函数的字符向量:

titlestring<-paste("Mean bin methylation",samplename, "on 5kb flanked CpG Island promoters in mm9")

titlestring如果您的主要问题是关于使用函数添加次要标题,则可以使用main=c(titlestring,substring),在这里您可以随意更改向量字符串。示例取自mtcars集合(可使用?热图找到)

require(图形)
需要(GR设备)

不值得这么大惊小怪,但理想情况下,我希望主标题和副标题能够有不同的字体大小,并控制它们的位置。如果我使用literals使用add.expr()添加标题,我可以做到这一点,例如:

add.expr=c(mtext(text=titlestring, side=3, line=4, cex=1)
 heatmap.2 (as.matrix(matToPlot[,(1:totCols)]),
         Rowv=FALSE, Colv=FALSE, dendrogram="none", 
         breaks=seq(0,1,by=1/length(methColors)),
         col=methColors, trace="none",colsep=colsep,sepcolor=c("sky blue"),
         #main=paste(titlestring,subtitlestring,chromstring,sep="\n"),
         add.expr=c(mtext(text="Read coverage of Dox Plus on 5kb flanked CpG
          Island promoters in mm9", side=3, line=4, cex=1),
         mtext(text="Island set represents island for which ChIP data is avilable
          and is order by mean(H3K4me3)-mean(H3K27me3) within islands", side=3, line=2, cex=0.8),
         mtext(text="H3K27me3", side=1, adj=0.125, line=3),
         mtext(text="H3K4me3", side=1, adj=0.375, line=3),
         mtext(text="H3K4me1", side=1, adj=0.625, line=3),
         mtext(text="Methylation", side=1,adj=0.9, line=3))) 
然而,使用main,我得到了一个我可以接受的结果,但效果不太好(比较这两个图):


您的titlestring命令出现错误,因为samplename未知。为什么不在热图通话中使用main=titlestring这样的功能?@RuthgerRighart:谢谢。使用main确实是一种可能性,但由于我想添加一个次要标题,我仍然更喜欢使用add.expr(),因为它更灵活。samplename是一个由调用函数根据其参数之一生成的字符向量,因此定义了它(如我所述,我还验证了titlestring对内部函数可见)。是否不可能使用从另一个函数传递的字符向量调用mtext()?我不确定您到底想要什么,最好有一个数据示例。请在答案框中找到可能的解决方法,希望对您有所帮助@露丝·格里格哈特:我在下面添加了一个我想要的例子。但是,我认为我想用add.expr()做的事情和用main做的事情之间的区别并不是那么重要,所以我不会在这方面浪费更多的时间。非常感谢你的帮助!