我想獲得多頁面二維格子面板圖在多個頁面上具有相同的調節佈局。垂直排列應該是多頁格子面板排列
CCC
BBB
AAA
在每頁上。我知道如何手動執行此操作,但代碼很難看,特別是如果最後一頁未完全填充。
在2010年的SO線程中,我讀到這是ggplot2的「列表」。
library(lattice)
d = expand.grid(f1 = as.factor(letters[1:10]),
f2 = as.factor(LETTERS[1:3]),
x = 0:10)
d$y = rnorm(nrow(d))
xyplot(y~x|f1+f2,data=d,cex=0.5,pch=16,layout=c(5,3,2))
請注意,所有A位於第一頁,其次是B,然後是B和C在最後一頁。
編輯下面的Gabor的想法
library(lattice)
library(latticeExtra)
# Note: changed so that it does not fill the three pages
d <- expand.grid(f1 = as.factor(letters[1:8]),
f2 = as.factor(LETTERS[1:3]),
x = 0:10)
d$y <- rnorm(nrow(d))
page <- factor((as.numeric(d$f1) - 1) %/% 5 + 1)
# The second (=last) page has different panel sizes
# Using aspect does not help
for(pg in levels(page)) {
p <- xyplot(y ~ x|f1+f2, data = d[pg == page, ], cex = .5, pch = 16,
layout = c(5, 3))
print(useOuterStrips(p))
}
中,我從來沒有在最後一頁上找到針對不同面板尺寸的滿意解決方案。非常好。我已經通過你的解決方案,這是對數據包功能的簡化。不知道它是否一般,但似乎在這裏工作:'packet.panel.bycolumn < - 函數(佈局,condlevels,頁面,行,列,跳過){x < - c(layout [1] *(page - 1 )+列,行); if(x [1] <= length(condlevels [[1]]))x}' – 2012-03-13 00:21:45
很好的簡化,謝謝!我直接從默認函數中獲取代碼並根據需要進行修改;我應該更多地考慮它實際上在做什麼! – Aaron 2012-03-13 01:06:48
太棒了!我會寫信給Deepayan,使之成爲latticeExtra的一部分。 – 2012-03-13 14:11:57