Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop labels in gghighlight_line R

Tags:

plot

r

label

I am plotting time series of several countries with gghighlight_line. I have managed to draw a faceted plot with the trend of each country using the following code:

oecd %>%
  filter(country %in% c("Germany", "France", "United Kingdom", "United States", "Canada", "Japan", "Italy", "Netherlands", "Spain")) %>%
gghighlight_line(., aes(year, pop_65, colour = country, group= country), predicate = max(pop_65) > 0, label_key = " ") +
  scale_x_discrete( breaks = c(2000, 2005, 2010, 2015)) +
   facet_wrap(~ country) +
  theme_minimal()

And producing the following plot:

enter image description here

Now, I am trying to drop the label associated with each line and I wonder whether there is such an option in gghighlight_line. Many thanks in advance

like image 208
Edu Avatar asked Oct 19 '25 13:10

Edu


1 Answers

You can add the argument use_direct_label = FALSE to remove labels from the lines.

gghighlight_line(., aes(year, pop_65, colour = country, group= country), predicate = 
                   max(pop_65) > 0, label_key = " ", use_direct_label = FALSE)

Note that this not only removes them from the lines; it also places your labels directly on the plot legend. If for some reason you want to hide them altogether, you can just add at this at the end:

oecd %>%
  filter(country %in% c("Germany", "France", "United Kingdom", "United States", 
"Canada", "Japan", "Italy", "Netherlands", "Spain")) %>%
gghighlight_line(., aes(year, pop_65, colour = country, group= country), predicate = 
max(pop_65) > 0, label_key = " ") +
  scale_x_discrete( breaks = c(2000, 2005, 2010, 2015)) +
   facet_wrap(~ country) +
  theme_minimal() +
  theme(legend.position = "none")  # remove legend
like image 165
Carlos Xavier Bonilla Avatar answered Oct 22 '25 03:10

Carlos Xavier Bonilla