英文:
Adding an empty space in the middle of a facet_wrapped plot
问题
我正在尝试在使用ggplot2的facet_wrap功能时在中间引入一个空白空间。
我有八个因子变量的值,我正在使用,结果的网格看起来像这样:
然而,如果可能的话,我想要最终得到这个:
这自然是一个带有一个空洞的正方形。我正在使用基本的方向,所以没有“无方向”的图表,但我有从西北到东南的一切。
我知道有手动解决方案,我愿意尝试,但这似乎在自动化的意义上应该是可行的 - 只是在中间插入一个空白空间。我不需要改变顺序或其他任何东西,只是在那里插入一个空间。
提前感谢!
英文:
I'm trying to introduce an empty space in the middle when using ggplot2's facet_wrap feature.
I have eight values of the factor variable I'm using, and the resulting grid looks like this:
However, if possible, I'd like to end up with this:
This is, naturally, a square with a hole in it. I'm using cardinal directions, so there's not a "no direction" graph, but I do have everything from northwest to southeast.
I'm aware there are manual solutions to this, which I'm willing to do, but this seems like it should be feasible in an automated sense--to just stick something empty in the middle. I don't need to change the order or anything, just jam a space in there.
Thanks in advance!
答案1
得分: 3
一种选择是使用 ggh4x::facet_manual
,通过 design
参数可以指定面板的布局,例如,使用 "#"
可以指定一个空面板并将 "hole" 移动到中间:
library(ggplot2)
library(ggh4x)
dat <- data.frame(
facet = LETTERS[1:8],
x = 1,
y = 1
)
design = "
ABC
D#E
FGH
"
ggplot(dat, aes(x, y)) +
geom_point() +
ggh4x::facet_manual(~facet, design = design)
<!— —>
英文:
One option is ggh4x::facet_manual
which via the design
argument allows to specify the layout for the panels, e.g. using a "#"
you could specify an empty panel and move the "hole" to the middle:
library(ggplot2)
library(ggh4x)
dat <- data.frame(
facet = LETTERS[1:8],
x = 1,
y = 1
)
design = "
ABC
D#E
FGH
"
ggplot(dat, aes(x, y)) +
geom_point() +
ggh4x::facet_manual(~facet, design = design)
<!-- -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论