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 grouped geom_smooth/geom_path

jacob-long opened this issue · comments

This may be a duplicate of #139. What I'd like to be able to do is highlight paths generated by geom_smooth().

Here is code:

library(ggplot2)
library(gghighlight)
ggplot(mpg, aes(displ, hwy, group = drv, colour = drv)) +
 geom_smooth(se = F) +
 gghighlight(drv == "4")

image

Which omits the label, unlike the similar code with geom_line()

library(ggplot2)
library(gghighlight)
ggplot(mpg, aes(displ, hwy, group = drv, colour = drv)) +
 geom_line() +
 gghighlight(drv == "4")

image

It's possible this is a user error, but I assume you would like users to be able to apply these labels to smooths and paths.

I should note that geom_path() has the same issue:

ggplot(arrange(mpg, displ), aes(displ, hwy, group = drv, colour = drv)) +
  geom_path() +
  gghighlight(drv == "4")

image

If I ask for a direct label, I get an error:

ggplot(arrange(mpg, displ), aes(displ, hwy, group = drv, colour = drv)) +
 geom_path() +
 gghighlight(drv == "4", use_direct_label = T)
Error: No layer can be used for labels
Backtrace:
 1. ggplot2:::`+.gg`(...)
 2. ggplot2:::add_ggplot(e1, e2, e2name)
 4. gghighlight:::ggplot_add.gg_highlighter(object, p, objectname)
In addition: Warning message:
Tried to calculate with group_by(), but the calculation failed.
Falling back to ungrouped filter operation... 

Oh, good catch, thanks. This is because use_direct_label now supports geom_point() and geom_line() only. I expect geom_path() can be supported, but geom_smooth() cannot.

Hi! Thanks for a great package! Just following up a few years later, could geom_path() get support? I'm running into the same issue currently. 😅