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_interactive wrong labels with few data points #299

Open
tvroylandt opened this issue Jun 18, 2024 · 2 comments
Open

geom_line_interactive wrong labels with few data points #299

tvroylandt opened this issue Jun 18, 2024 · 2 comments

Comments

@tvroylandt
Copy link

tvroylandt commented Jun 18, 2024

Hi,

Thanks for this package @davidgohel !

Trying to do some slopecharts between two dates, I noticed that geom_line_interactive produce some issue when your line is only made of 2 or 3 points.

Reproducible example below:

library(tidyverse)
library(ggiraph)

# this one is fine
iris_plot_ok <- ggplot(
  iris,
  aes(
    x = Sepal.Length,
    y = Sepal.Width,
    color = Species,
    tooltip = Species,
    data_id = Species
  )
) +
  geom_line_interactive(linewidth = 1)

girafe(ggobj = iris_plot_ok)

# this one is not
iris_plot_not_ok <- ggplot(
  iris |>
    group_by(Species) |>
    slice(1:2) |>
    ungroup(),
  aes(
    x = Sepal.Length,
    y = Sepal.Width,
    color = Species,
    tooltip = Species,
    data_id = Species
  )
) +
  geom_line_interactive(linewidth = 1)

girafe(ggobj = iris_plot_not_ok)

In the first case, everything is fine.
In the second one, the tooltip is wrong. It's mixed or produced NA. Adding group = Species doesn't change anything

Capture d’écran 2024-06-18 à 09 02 17
Capture d’écran 2024-06-18 à 09 02 49

My current solution is to produce all points behind this one with y = ax+b and use geom_point_interactive with transparent settings. Not really optimal

@sstein93
Copy link

sstein93 commented Oct 11, 2024

Thanks for this awesome package @davidgohel! It's overall been really useful!

I was wondering if there is an update on this issue? I am experiencing the same thing. What's interesting is this bug seems to depend on the number of points on the x-axis.

In the example below with only 2 points on the x-axis:

test <- data.frame(x = c(rep(1, 8), rep(2, 8), rep(3,8), rep(4, 8)), 
                   y = rep(1:8, 4), 
                   id = rep(str_split("abcdefgh","") %>% unlist(),4)) 
ptest <- ggplot2::ggplot(test %>% dplyr::filter(x <=2), 
                     aes(x = x, y = y, color = id, group = id)) +
  ggiraph::geom_point_interactive(aes(data_id = id, tooltip = id)) +
  ggiraph::geom_line_interactive(aes(data_id = id, tooltip = id)) 
  • The first line (red) is mapped correctly to data_id = "a"
  • The second line (yellow) is mapped incorrectly to data_id = "c" instead of "b". I.e., data_id index + 1
  • The third line (light green) is mapped to incorrectly to data_id "e" instead of "c", i.e., data_id index + 2
  • The fourth line (dark green) is mapped to data id "g" instead of "d", i.e. data_id index + 3
  • Line 5-8 are being mapped to data id "NA" since I think they would be mapped to idx +4, +5, +6, +7 if they existed.

Screenshot 2024-10-11 at 11 23 12 AM

Screenshot 2024-10-11 at 11 25 18 AM

Screenshot 2024-10-11 at 11 26 10 AM

Screenshot 2024-10-11 at 11 27 19 AM

Screenshot 2024-10-11 at 11 28 11 AM

If I instead have 3 points on the x-axis, the bug changes a little where:

  • the first two line (a and b) are mapped correctly
  • The 3rd and 4th lines are each mapped to idx + 1 (i.e. c -> d, and d -> e)
  • The 5th and 6th lines are each mapped to idx + 2 (i.e. e -> g, and f -> h)
test <- data.frame(x = c(rep(1, 8), rep(2, 8), rep(3,8), rep(4, 8)), 
                   y = rep(1:8, 4), 
                   id = rep(str_split("abcdefgh","") %>% unlist(),4)) 
ptest <- ggplot2::ggplot(test %>% dplyr::filter(x <=3), 
                     aes(x = x, y = y, color = id, group = id)) +
  ggiraph::geom_point_interactive(aes(data_id = id, tooltip = id)) +
  ggiraph::geom_line_interactive(aes(data_id = id, tooltip = id))

If I instead have 4 points on the x-axis, the bug changes to:

  • First 3 lines are mapped correctly (a ,b ,c)
  • Lines 4-6 are mapped to data id index + 1 (d->e, e->f, f->g)
  • Lines 7 and 8 are mapped to NA but would likely be data id index + 2 if they existed in the data
test <- data.frame(x = c(rep(1, 8), rep(2, 8), rep(3,8), rep(4, 8)), 
                   y = rep(1:8, 4), 
                   id = rep(str_split("abcdefgh","") %>% unlist(),4)) 
ptest <- ggplot2::ggplot(test %>% dplyr::filter(x <=4), 
                     aes(x = x, y = y, color = id, group = id)) +
  ggiraph::geom_point_interactive(aes(data_id = id, tooltip = id)) +
  ggiraph::geom_line_interactive(aes(data_id = id, tooltip = id)) 

Thanks again for all of the work you have put into this package!
Shayna

@crystalluckett-sanofi
Copy link

@davidgohel is there any update on this? I am also having this issue.

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