Manually adding suffixes to the legend ticks in ggplot

Viewed 37

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.

1 Answers

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