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.
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) <- "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()