1

#1 I am creating a coefficient forest plot. I would also like to include two columns to right of the plot, one with a string including the point estimate and CI, and another with the p-value.

I am using ggplot() with geom_point() for the forest plot and geom_text() for the point estimate/CI and p value.

I would like to know how to limit the rightward border of the geom_point() plot but NOT the rightward border of the geom_text() plot. Essentially, I want to create white space to the right of my plot for my text column so that it doesn't overlap with the CI line.

#2 The coefficient plot includes a new plot for each of my model sets (determined by unique values in the associated df column). I created a row meant to be used as headings for the geom_text() output. Is there a way to assign this row as headings for the geom_text() and prevent it from creating another section of the plot (see where it now appears as the bottom plot in the image).

Thank you.

lcfplot <- lcftable %>%
  ggplot(mapping = aes(x = estimate, xmin = conf.low, xmax = conf.high, y = model)) + #y = model rather than term
  geom_pointrange() +
  scale_x_continuous(trans = scales::pseudo_log_trans(base = 10), breaks = c(0, 0.5, 1.0, 2.0, 5.0)) +
  geom_vline(xintercept = 1) +
  geom_point(size = 1.0) +
  facet_wrap(exposure~., ncol = 1, scale = "free_y") +
  xlab("Incident Odds Ratio, IOR (95% Confidence Interval)") +
  geom_text(aes(x = 6, label = estimate_lab), hjust = 0, size = 3) +
  geom_text(aes(x = 5, label = p.value), hjust = 0, size = 3) +
  theme(panel.background = element_blank(),
        panel.spacing = unit(0, "lines"),
        panel.border = element_rect(fill = NA, color = "white"),
        strip.background = element_rect(colour="white", fill="white"),
        strip.placement = "outside",
        text = element_text(size = 12),
        strip.text = element_blank(),#element_text(face = "italic", size = 10, hjust = 0.2),
        plot.title = element_text(face = "bold", size = 11, hjust = 1.2),
        axis.title.x = element_text(size = 10, vjust = -1, hjust = -0.15),
        axis.title.y = element_blank(),
        panel.grid.major.x = element_line(color = "#D3D3D3",
                                  size = 0.3, linetype = 2),
        plot.margin = unit(c(1, 3, 0.5, 0.5), "inches")) +
  geom_errorbarh(height = 0)

I have also tried creating these plots separately and merging them, but this doesn't work because the text doesn't align with the plot.

coefficient forest plot

stefan
  • 90,330
  • 6
  • 25
  • 51

0 Answers0