Reputation: 1611
I would like to modify all y-axis labels on a chart except for the last one. In the example below, think of y as a cumulative count of cylinders. Thus, a car can have 1+, 2+, etc., but it cannot have more than 8.
How would I modify the code below to add the "+" sign to all y-axis elements except the last one? I would like my labels to be (4+, 5+, 6+, 7+, 8)?
library(tidyverse)
mtcars %>%
ggplot(aes(x = mpg, y = cyl)) +
scale_y_continuous(labels = function(x) paste0(x, "+"))
Upvotes: 0
Views: 25
Reputation: 5898
Try: library(tidyverse)
mtcars %>%
ggplot(aes(x = mpg, y = cyl)) +
scale_y_continuous(labels = function(x) c(paste0(x[-length(x)], "+"), max(x)))
Upvotes: 1