R格子: How to add empty plots with border to fill the gaps of defined layout

标签 r plot lattice

我想在 2x3 布局中创建一系列包含 6 个或更少绘图的图形。如果有一个图形少于 6 个图,我希望有边框来查看布局的结构。

例如这段代码给出了下图:

n <- 3
data0 <- expand.grid(g = LETTERS[1:3], x=1:10)
data0$y <- data0$x + rnorm(nrow(data0))
xyplot(y~x|g, data=data0, layout=c(2,3), as.table=TRUE)

enter image description here

我想创建这样的东西:

enter image description here

知道如何做到这一点吗?

最佳答案

我刚刚添加了另外 3 个具有 NA 值的组:

data0 <- expand.grid(g = LETTERS[1:6], x=1:10)
data0$y <- data0$x + rnorm(nrow(data0))
data0[data0$g %in% LETTERS[4:6],c('x', 'y')] <- NA
xyplot(y~x|g, data=data0, layout=c(2,3), as.table=TRUE)

enter image description here

关于R格子: How to add empty plots with border to fill the gaps of defined layout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60550563/

相关文章:

python - 在卫星 map 上绘制数据

python - 将 matplotlib 数据单位转换为规范化单位

r - 向 ggplot 添加自定义颜色

r - ggplot2:如何调整图例中的线型和顺序?

graph - 帮助使用 xplot 查看 tcptrace 输出图

r - 格子条形图的刻度标签不正确

r - 如何绘制带有水平误差条(带有错误标记的条形图)的图表?

r - 将 abline 添加到 xyplot(半对数)

r - 如何将日期和分钟添加到 R 中的日期时间对象?

r - 您如何测试自定义期望?