scales
scales copied to clipboard
Feature request: label_2nd function to label every second break
Credit to Simon Woodwood for this function https://community.rstudio.com/t/how-to-automatically-skip-some-x-labels/65702/2
library(palmerpenguins)
library(tidyverse)
label_second <- function(x){
x[seq(2, length(x), 2)] <- ""
x
}
penguins %>%
ggplot() +
geom_jitter(
aes(
x = sex,
y = body_mass_g,
)) +
scale_y_continuous(breaks = scales::breaks_pretty(10), labels = label_2nd)

Thought label_2nd rather than label_second, as then users know that this does not relate to time
This would be particularly useful when facetting
label_nth <- function(x, nth = 1) replace(x, seq_along(x)%%nth!=0, "")
I think this would work better in stringr