admin管理员组

文章数量:1122846

I am trying to align a forest plot in R with a data table of the values. The data table ends prior to the last data point. My code and plot with dummy labels are below. Thanks for your help!!

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)

本文标签: rplotgrid graphs not aligningStack Overflow