Hello everyone,
I need to break the Y axis from the second line of this facet_grid plot to improve the others plots visualization.
Here is a data for example:
library("tidyverse")
# Create example data -----------------------------------------------------
n <- 100
set.seed(232153)
my_data <- tibble(
x1 = rnorm(n),
x2 = rnorm(n),
g1 = sample(LETTERS[1:3], size = n, replace = TRUE),
g2 = sample(LETTERS[4:6], size = n, replace = TRUE),
)
# Augment data ------------------------------------------------------------
my_data <- my_data %>%
mutate(x1_A_D = case_when(g1 == "A" & g2 == "D" ~ x1,
TRUE ~ NA_real_),
x2_A_D = case_when(!is.na(x1_A_D) ~ x2,
TRUE ~ NA_real_))
# Visualise ---------------------------------------------------------------
my_data %>%
ggplot(aes(x = x1, y = x2)) +
geom_line() +
geom_smooth(aes(x = x1_A_D, y = x2_A_D),
method = "lm", linetype = "dashed") +
theme_minimal() +
facet_grid(vars(g2), vars(g1))
Can someone help (save) me please?