与所有其他地块大小相同的拼凑而成的空地块空间
我正在使用拼凑的网格在网格中绘制一系列相同大小的图。我的网格是 5 x 6,预计最后 2 行中我只有 4 个图,而不是 5 个。我想要空图,以便图显示为常规网格。
XXXXX
XXXXX
XXXXX
XXXXX
XXXX
XXXX
使用cowplot,我可以使用NULL
,但发现间距很奇怪,所以改用拼凑。 plot_spacer()
没有按我的预期工作,因为它改变了行其余部分的对齐方式。
library(tidyverse)
library(latex2exp)
library(patchwork)
genCircle <-
function(center = c(0.0, 0.0),
rad = 1.0,
npoints = 100) {
# fcn for circle plots
r = rad
tt <- seq(0, 2 * pi, length.out = npoints)
xx <- center[1] + r * cos(tt)
yy <- center[2] + r * sin(tt)
return(data.frame(x = xx, y = yy))
}
dat = genCircle()
line1 = sprintf("$A = %0.2f$, $B = %0.3f$",
1.6,
3.7
)
line2 = sprintf("$\\hat{C} = %0.1f$,$ \\hat{%s} = %0.1f$",
12.6,
"D",
86.3
)
p1 <- ggplot(data = dat, mapping = aes(x = x, y = y)) +
geom_path(size =0.3) +
geom_abline(color = 'gray77', size = 0.1) +
coord_fixed() +
ggtitle(TeX(line1)) + labs(subtitle = TeX(line2)) +
theme(plot.title = element_text(size = 9, hjust = 0, margin=margin(b=0)), plot.subtitle = element_text(size = 9, hjust = 0, margin=margin(b=0)), legend.title = element_blank(), legend.margin=margin(l = -2, unit='pt'), axis.text.x=element_blank(), axis.ticks.x=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank(), axis.title = element_blank(), plot.margin = unit(c(0.1,-0.1,0,0), "cm"))
(p1|p1|p1) / (p1|p1|p1) / (p1|p1|plot_spacer())
有没有一种简单的方法来保持网格结构?
I am plotting a series of identically sized plots in a grid using patchwork. My grid is 5 x 6, expect for the final 2 rows I have only 4 plots in the row not 5. I want to have empty plots so that the plots are displayed as a regular grid.
XXXXX
XXXXX
XXXXX
XXXXX
XXXX
XXXX
With cowplot I could use NULL
, but found the spacing was odd so switched to patchwork. plot_spacer()
is not working as I expected as it changes the alignment of the rest of the row.
library(tidyverse)
library(latex2exp)
library(patchwork)
genCircle <-
function(center = c(0.0, 0.0),
rad = 1.0,
npoints = 100) {
# fcn for circle plots
r = rad
tt <- seq(0, 2 * pi, length.out = npoints)
xx <- center[1] + r * cos(tt)
yy <- center[2] + r * sin(tt)
return(data.frame(x = xx, y = yy))
}
dat = genCircle()
line1 = sprintf("$A = %0.2f$, $B = %0.3fquot;,
1.6,
3.7
)
line2 = sprintf("$\\hat{C} = %0.1f$,$ \\hat{%s} = %0.1fquot;,
12.6,
"D",
86.3
)
p1 <- ggplot(data = dat, mapping = aes(x = x, y = y)) +
geom_path(size =0.3) +
geom_abline(color = 'gray77', size = 0.1) +
coord_fixed() +
ggtitle(TeX(line1)) + labs(subtitle = TeX(line2)) +
theme(plot.title = element_text(size = 9, hjust = 0, margin=margin(b=0)), plot.subtitle = element_text(size = 9, hjust = 0, margin=margin(b=0)), legend.title = element_blank(), legend.margin=margin(l = -2, unit='pt'), axis.text.x=element_blank(), axis.ticks.x=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank(), axis.title = element_blank(), plot.margin = unit(c(0.1,-0.1,0,0), "cm"))
(p1|p1|p1) / (p1|p1|p1) / (p1|p1|plot_spacer())
Is there a simple way to keep the grid structure?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
放置空字段
对于在特定位置具有空图的常规网格,
patchwork::plot_layout
采用设计参数,其中可以使用 #For a regular grid with empty plots at specific positions,
patchwork::plot_layout
takes a design argument where empty fields can be place with #