Using this code:
ggplot(mtcars, aes(x=mtcars$mpg, y = mtcars$wt, color = as.factor(mtcars$cyl))) + geom_point()
I get a nice plot that looks like this:
For my purposes, I would like the legend to look something like this:
In words, I would like the background of the legend text for the color legend to match the label's respective color. Is there any simple way to do this?
EDIT: In my current code, I'm using ggtext with scale_color_hue(labels = colorLabels) where colorLabels looks like this <span style='color:red'>MyLabel</span> to have the text itself colored, but I don't like it so much and I want to see how I feel with the colors swapped. Switching color:red with background-color:red just removes the text color, doesn't actually color the background.


