通过使用layout或,可以将多个简单绘图组合成单个图形中的面板par(mfrow=...).但是,更复杂的图表往往会在内部设置自己的面板布局,从而无法将其用作面板.有没有办法创建嵌套布局并将复杂的图形封装到单个面板中?
我有一种感觉,grid包可以实现这一点,例如通过在单独的视口中绘制面板,但无法弄清楚如何.这是一个演示问题的玩具示例:
my.plot <- function(){
a <- matrix(rnorm(100), 10, 10)
plot.new()
par(mfrow=c(2,2))
plot(1:10, runif(10))
plot(hclust(dist(a)))
barplot(apply(a, 2, mean))
image(a)
}
layout(matrix(1:4, 2, 2))
for(i in 1:4) my.plot()
# How to avoid reseting the outer layout when calling `my.plot`?
Run Code Online (Sandbox Code Playgroud)
我使用包中的heatmap.2函数gplots来生成热图.以下是单个热图的示例代码:
library(gplots)
row.scaled.expr <- matrix(sample(1:10000),nrow=1000,ncol=10)
heatmap.2(row.scaled.expr, dendrogram ='row',
Colv=FALSE, col=greenred(800),
key=FALSE, keysize=1.0, symkey=FALSE, density.info='none',
trace='none', colsep=1:10,
sepcolor='white', sepwidth=0.05,
scale="none",cexRow=0.2,cexCol=2,
labCol = colnames(row.scaled.expr),
hclustfun=function(c){hclust(c, method='mcquitty')},
lmat=rbind( c(0, 3), c(2,1), c(0,4) ), …Run Code Online (Sandbox Code Playgroud)