gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:28:05 26 4
gpt4 key购买 nike

我想在 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值(value)观:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com