Removing parts of a plot created with shape_plot() or forest_plot()

ckbplotr

14 Nov 2022

Modified:

20 Jul 2023

There are various ways to remove parts of plots (or make them not appear) created with shape_plot() and forest_plot(). Which will work best may depend on how you are using the code, some examples are:

Remove text by setting label to NA

my_results <- data.frame(
  risk_factor = c(  17,    20,  23.5,    25,    29),
  est         = c(   0, 0.069, 0.095, 0.182, 0.214),
  se          = c(0.05, 0.048, 0.045, 0.045, 0.081)
)

shape_plot(my_results,
           col.x = "risk_factor",
           xlims = c(15, 30),
           ylims = c(-0.25, 0.5),
           addaes = list(estimates = "label = NA"))

You could also set x or y to NA_real_.

Remove points by setting their colour to NA

my_results <- data.frame(
  subgroup   = c("men", "women", "35_49", "50_64", "65_79"),
  est        = c( 0.45,    0.58,    0.09,    0.35,     0.6),
  se         = c( 0.07,    0.06,    0.06,    0.05,    0.08)
)

forest_plot(my_results,
            colour   = NA,
            cicolour = "black")

Remove points by setting their size to zero

forest_plot(my_results,
            pointsize = 0)

Remove confidence interval lines by setting their colour to NA

forest_plot(my_results,
            cicolour = NA)

Remove points by removing that layer of the ggplot object

forest <- forest_plot(my_results,
                      printplot = FALSE)

## first check which layer in forest$plot
## is the geom_point() for points, then remove
forest$plot$layers[[2]] <- NULL
forest$plot