0

I'm trying to add the curves name to my ggplot directly from the legend.

Here's my code

plott = ggplot(PL2, aes(P, growth.rate2020, color=Country, showlabels=TRUE)) + 
    geom_point()

What I want to see is the name of each country next to each curve

enter image description here

user438383
  • 5,716
  • 8
  • 28
  • 43
  • Are you searching for something like this : https://stackoverflow.com/questions/29357612/plot-labels-at-ends-of-lines ? – Carlos Sep 20 '21 at 10:34

1 Answers1

0

You can add geom_label and remove the legend guide:

library(tidyverse)

iris %>%
  ggplot(aes(Sepal.Length, Petal.Length, color = Species)) +
  geom_point() +
  geom_label(
    data = iris %>% group_by(Species) %>% summarise(across(everything(), mean)),
    mapping = aes(label = Species, x = 5)
  ) +
  guides(color = FALSE)
#> Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
#> "none")` instead.

Created on 2021-09-20 by the reprex package (v2.0.1)

danlooo
  • 10,067
  • 2
  • 8
  • 22