Home > OS >  Manually adding suffixes to the legend ticks in ggplot
Manually adding suffixes to the legend ticks in ggplot

Time:06-12

How can I manually add an arbitrary suffix to the legend ticks in ggplot?

For example, can I add something to the below code to generate the below plot with those unique legend ticks?

ggplot(iris, aes(Sepal.length, Sepal.Width, color = Species))   geom_point()

enter image description here

Note that I manually added "(s)" to the end of the legend ticks using Photoshop.

CodePudding user response:

We can use the labels argument in scale_color_discrete. This can take an rlang style lambda function that pastes an "(S)" at the end.

ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species))   
  geom_point()  
  scale_color_discrete(labels = ~paste(.x, "(S)"))

enter image description here

  • Related