15  Multiple estimates per row

If the data supplied to forest_plot() contains more than one estimate for a value of the col.key, then they will all be plotted on top of each other:

my_resultsAB <- data.frame(
  analysis = factor(c(rep("Observational", 5), rep("Genetic", 5)),
                    levels = c("Observational", "Genetic")),
  subgroup = c("men", "women", "35_49", "50_64", "65_79",
               "men", "women", "35_49", "50_64", "65_79"),
  est      = c( 0.45, 0.58, 0.09, 0.35, 0.6,
                0.48, 0.54, 0.06, 0.3, 0.54),
  se       = c(0.07, 0.06, 0.06, 0.05, 0.08,
               0.12, 0.11, 0.11, 0.09, 0.15),
  n        = c(593, 640, 318, 552, 363,
               NA, NA, NA, NA, NA)
)

row_labels <- data.frame(
  subgroup = c("women", "men",
               "65_79", "50_64", "35_49"),
  group    = c("Sex", "Sex",
               "Age (years)", "Age (years)", "Age (years)"),
  label    = c("Women", "Men",
               "65 - 79", "50 - 64", "35 - 49")
)

forest_plot(my_resultsAB,
            col.key    = "subgroup",
            row.labels = row_labels,
            scalepoints   = TRUE)

You can use the colour and addaes arguments to change the colour of points and text for different estimates. Then also create a function that will adjust the row position, and supply the name fo the function to the data_function argument. (Use the col.keep argument so that the data will contain any additional columns needed.)

# create 'mycolour' column, according to analysis type
my_resultsAB <- dplyr::mutate(my_resultsAB,
                              mycolour = dplyr::if_else(analysis == "Observational",
                                                        "black",
                                                        "red"))

# function to decrease/increase 'row' for Observational/Genetic
move_rows <- function(datatoplot){
  datatoplot <- dplyr::mutate(datatoplot,
                              row = dplyr::if_else(analysis == "Observational",
                                                   row - 0.15,
                                                   row + 0.15))
  
  ## add rows to the data frame to create annotations 
  datatoplot <- dplyr::add_row(datatoplot,
                               auto_estcolumn = c("Observational","Genetic"),
                               row            = c(0.5, 0.8),
                               panel          = "1",
                               mycolour       = c("black", "red"))
  return(datatoplot)
}


# add the col.keep, colour, data.function, and addaes arguments
forest_plot(my_resultsAB,
            col.key       = "subgroup",
            row.labels    = row_labels,
            scalepoints   = TRUE,
            col.keep      = "analysis",
            colour        = "mycolour",
            data.function = "move_rows",
            addaes        = list(col.right = "colour = mycolour"))