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

geom_line does not work with a text aesthetic #5373

Closed
davidhodge931 opened this issue Jul 28, 2023 · 3 comments
Closed

geom_line does not work with a text aesthetic #5373

davidhodge931 opened this issue Jul 28, 2023 · 3 comments

Comments

@davidhodge931
Copy link

library(tidyverse)

ggplot2::economics |>
  mutate(text = glue::glue("Unemployment: {unemploy}")) |>
  ggplot(aes(x = date,y = unemploy)) +
  geom_line(aes(text = text))
#> Warning in geom_line(aes(text = text)): Ignoring unknown aesthetics: text

Created on 2023-07-28 with reprex v2.0.2

@davidhodge931
Copy link
Author

Requires group = 1 within the aes to work if a text aesthetic is added. Is fine without it, if a text aesthetic is not added

@teunbrand
Copy link
Collaborator

The warning tells you that geom_line() isn't supposed to work with a text aesthetic. Is this in any way related to how {plotly} uses such an aesthetic? Perhaps the larger issue here is that unrecognised aesthetics may influence the grouping even if they're not part of the proper geom. Mind that ?aes_group_order mentions 'all discrete variables in the plot', not 'all discrete mappings used in a layer' in the context of default groups.

@davidhodge931
Copy link
Author

Ah, grouping issue - thanks @teunbrand

library(tidyverse)

p <- ggplot2::economics |>
  mutate(text = glue::glue("Unemployment: {unemploy}")) |>
  ggplot(aes(x = date,y = unemploy)) +
  geom_line(aes(text = text, group = 1))

plotly::ggplotly(p, tooltip = "text")

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

2 participants