Cut Top Tick Mark (two axis)

Hi, I'm creating a chart w/ secondary axis using ggplot2.
And want to cut both Y-axis lines at the top tick mark.
Found it is easiest to specify "limits=" to do that.
But, can do that only for one of the axis at a time.

Thought someone may have dealt w/ this before, and can suggest.
Thanks!

Reproducible example:

library(ggplot2)
data <- data.table(
  rnorm(20, 50, 70))
data$ratio <- rnorm(20, 0.8, 0.2)
data$year <- seq(2001, 2020, by = 1)
colnames(data)[1] <- "amount"
data <- data %>% mutate_all(as.numeric)

ggplot(data, aes(x = year, y = amount)) +
  geom_line(color = "red") + ggplot2::scale_y_continuous(breaks = scales::extended_breaks(n = 10),
                                                  limits = c(-300, 300), expand = c(0,0),
                                                  sec.axis = ggplot2::sec_axis(~./(max(data$amount)/100),
                                                  breaks = scales::extended_breaks(n = 10))) + theme_classic()

Two-Axis Chart

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.