How break y axis (descontinuous axis) in facet_grid graphs

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?

Have you tried? Set Axis Break for ggplot2

Regards,
Grzegorz

1 Like

Thank you!! I'm trying, but still no luck! rs

Regards,
Gabi

Maybe you could add

facet_grid(scales = 'free')

1 Like

Thank you! But it doesn't make any difference, I need to break the y axis because of an outlier in forest plantation land use change (%), a value above 800.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.