我正在尝试将森林图与值的数据表对齐。数据表在最后一个数据点之前结束。我的代码和带有虚拟标签的绘图如下。感谢您的帮助!!
p <-
ggplot(forest_plot_data, aes(x = est, y = order, xmin = low, xmax = upp))+
geom_vline(xintercept = 1, linetype='dashed', color='black')+
geom_pointrange(shape = 22, size=0.8) +
theme_classic() +
scale_y_discrete(limits = forest_plot_data$order) +
scale_x_continuous(name='Adjusted odds ratio (95% confidence interval) of mortality')+
theme(axis.text.y = element_blank(),
axis.title.y = element_blank(),
axis.title.x = element_text(family='serif', size=14),
axis.text.x = element_text(family='serif', size=12),
plot.margin = margin(40,20,60,-1),
axis.ticks.y = element_blank(),
axis.line.y = element_blank())
data_table1 <- ggplot(data = forest_plot_data) +
geom_text(aes(x=0, y = order, label=group), hjust=0, family='serif', size=5, vjust=0) +
geom_text(aes(x=0.052, y = order, label=var), hjust=0, family='serif', size=5, vjust=0) +
geom_text(aes(x=0.09, y = order, label=label), hjust=1, family='serif', size=5, vjust=0)+
theme_void() +
theme(plot.margin = margin(20,-3,40,20))
p_total <-
plot_grid(data_table1, p, ncol=2, align='h',axis='b')
p_total +
annotate("richtext", x=0.01, y=0.96, label='**Characteristic**',
family='serif', size=5, hjust=0, fill=NA, label.color=NA)+
annotate("richtext", x=0.4, y=0.96, label="**aOR (95% CI)**",
family='serif', size=5, hjust=0, fill=NA, label.color=NA)
这是使用 matplotlib 或 seaborn 等库中的plot_grid 时出现的一个典型问题,当由于轴刻度、刻度标签或图形大小不一致而导致图形未对齐时。以下是调试和解决问题的步骤: