'How to control stripe transparency using ggforestplot/geom_stripes?
I was hoping to have some help in modifying the stripe transparency/shading color in the ggforestplot package. Please see the image below ("lighten" indicates the stripes I need to lighten). What is the best way of modifying the following code to do that?
Thank you so much for any pointers!
# Load and attach the packages
library(ggforestplot)
library (ggplot2)
library(tidyverse)
# Reproducible dataset
df <- ggforestplot::df_linear_associations %>% filter( trait == "BMI", dplyr::row_number() <= 30)
# Draw a forestplot
ggforestplot::forestplot(
df = df,
name = name,
estimate = beta,
se = se)+
geom_point(shape = 15, size = 5) +
geom_stripes( odd ="#00000000", even = "#00000000") +
theme(legend.position="none",
panel.background = element_rect(fill = "transparent",colour = NA),
plot.background = element_rect(fill = "transparent",colour = NA))
Solution 1:[1]
The issue is that ggforestplot::forestplot already adds a geom_stripes layer with hard-coded default values for odd and even. Adding another geom_stripes will have no effect on this underlying stripes layer and will simply result in overplotting of the points, vertical lines, ... . To adjust the transparency you could (and TBMK need to) hack the internals:
# Load and attach the packages
library(ggforestplot)
library(ggplot2)
library(tidyverse)
# Reproducible dataset
df <- ggforestplot::df_linear_associations %>% filter( trait == "BMI", dplyr::row_number() <= 30)
# Draw a forestplot
p <- ggforestplot::forestplot(
df = df,
name = name,
estimate = beta,
se = se) +
geom_point(shape = 15, size = 5) +
theme(legend.position="none",
panel.background = element_rect(fill = "transparent"))
p$layers[[1]]$aes_params$odd <- "#00000000"
p

Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Maurits Evers |

