yutannihilation / gghighlight

Highlight points and lines in ggplot2

Home Page:https://yutannihilation.github.io/gghighlight/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Label only one point from a geom_point, or label only one geom from multiple geoms

rexdouglass opened this issue · comments

I want to plot points with a linear trend, and I want gghighlight to color in only a subset of the lines and points and label only either the lines or the final point.

Instead, gghighlight doesn't label smooth geoms at all and labels every single geom_point individual over and over again.

Is there a correct method for handling this use case?

p2 <-  ggplot(data=all_long %>% filter(days_since_100_confirmed>0) ) + 
       geom_point(aes(x=days_since_100_confirmed, y=deaths_fd, color=country )) + 
       geom_smooth(data=all_long %>% filter(days_since_100_confirmed>0) %>% filter(days_since_100_confirmed<30) , aes(x=days_since_100_confirmed, y=deaths_fd, color=country) , method = lm, se = FALSE) + 
       gghighlight(country %in% c("US","China","Italy") ,
                    label_params =
                     list(
                      size = 3,
                      segment.alpha=0)
                   ) +
       scale_x_continuous(breaks=seq(0, 61, by = 5)) + 
       scale_y_log10(labels = comma_format()) + 
       xlab("Days Since 100 Confirmed") + 
       ylab("Number of Deaths") + 
       guides(color=FALSE) + theme_bw()
p2

Could you provide a reproducible example? I cannot help you because I don't know what all_long is.

@rexdouglass
I'm closing this, but feel free to file a new issue with a reprex :)