I want to use multiple colors for a single value in a ggplot2 axis. For example:
library(tidyverse)
mtcars %>%
mutate(cyl = case_when(cyl == 4 ~ "4 \n n = 12 \n more text",
cyl == 6 ~ "6 \n n = 7 \n more text",
cyl == 8 ~ "8 \n n = 14 \n more text")) %>%
ggplot(aes(cyl)) +
geom_bar() +
theme(axis.text.x = element_text(colour = c("black", "blue", "red")))
I would like to color the 4, 6, 8 but keep the other text in black. Essentially, I want to color before the line break but not after, essentially using two different colors within the same label. I am thinking there might be a way to do this the with the ordering of scale_x_discrete
but I am unsure how to go about it
EDIT: This question does not have anything to do with changing the text color dependent on another variable.