Using the example data below and the respective plot, I simply want to add text for each of the three cyl groups at the top, e.g. for cyl = 4, I want to add a label like "abc", for cyl = 6 a label like "xyz" and so on.
I know that ggplot doesn't like secondary axes, and in my case I don't even want to display additional data, I just want to add second/alternative axis labels.
library(tidyverse)
mtcars |>
mutate(cyl = as.character(cyl)) |>
ggplot() +
geom_tile(aes(x = cyl, y = gear, fill = disp))
This is what I have:
This is what I want:
Any ideas?


sec_axistakes many of the same arguments asscale_x_continuous, includingbreaks=andlabels=. Just provide an "identity" transform (~ .) and provide both arguments, as in... + scale_x_continuous(sec.axis = sec_axis(~ ., breaks = c(4, 6, 8), labels = c("abc", "def", "ghi")))