Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Label grouped geom_smooth/geom_path #144

Open
jacob-long opened this issue Apr 3, 2020 · 2 comments
Open

Label grouped geom_smooth/geom_path #144

jacob-long opened this issue Apr 3, 2020 · 2 comments

Comments

@jacob-long
Copy link

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... 
@yutannihilation
Copy link
Owner

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.

@roaldarbol
Copy link

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. 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants