gghighlight highlighting lines with certain labels

655 Views Asked by At

I am trying to build a time-series plot and highlight certain lines based on the country that line belongs to. However, I couldn't find a way to highlight based on label names. I tried the following code, and although it worked, it also raised an error.


graph <- final_data %>%
  filter(X %in% country_names) %>%
  ggplot(aes(x=year,
             y=obesity_proportions,
             colour=X)) +
  geom_line() + 
  gghighlight(X == "United States of America",
              label_key = X) +
  theme_minimal()


Here is the output graph:

The output graph

However, it also raised an error with this graph. Here is the error code:


Warning message:
Tried to calculate with group_by(), but the calculation failed.
Falling back to ungrouped filter operation...

How can I fix this error and is there a better way to highlight by country?

0

There are 0 best solutions below