add_tooltip makes some points to vanish

77 views
Skip to first unread message

Mathieu Kessler

unread,
Oct 6, 2014, 1:29:20 PM10/6/14
to gg...@googlegroups.com
Hi!
When I add tooltips, some (seemingly arbitrary) points disappear after 1 s aprox.
For instance, using the mtcars dataset:

mtcars %>% 
  ggvis(~wt, ~mpg, fill = ~factor(cyl)) %>% 
  layer_points(key := ~disp ) %>% 
  add_tooltip(function(df) df$displ)

Points at rows 1,5,10, 12 and 13 disappear...

I am using ggvis 0.3.0.1 on linux with R 3.1.1.

Does that occur to someone else? 
Thx! Mathieu

Winston Chang

unread,
Oct 6, 2014, 4:09:46 PM10/6/14
to Mathieu Kessler, gg...@googlegroups.com
Hi - this happens when the key isn't unique. You can add a new column
called "id" with unique keys like so:

mtcars %>% dplyr::mutate(id = 1:n()) %>%
ggvis(~wt, ~mpg, fill = ~factor(cyl)) %>%
layer_points(key := ~id) %>%
add_tooltip(function(df) df$displ)

That said, it probably would be good for ggvis to give a warning when
non-unique keys are used, since we've seen this issue come up before.

-Winston
> --
> You received this message because you are subscribed to the Google Groups
> "ggvis" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ggvis+un...@googlegroups.com.
> To post to this group, send email to gg...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mathieu Kessler

unread,
Oct 7, 2014, 4:43:06 AM10/7/14
to gg...@googlegroups.com, mkess...@gmail.com
Dear Winston,
Thank you very much for the reply.
I could not get your code to work, it seems to me that the function used in add_tooltip should make use of the key variable.
The following slight modification works fine:

mtc=mtcars %>% dplyr::mutate(id = 1:dim(mtcars)[1])
mtc  %>% 
  ggvis(~wt, ~mpg, fill = ~factor(cyl)) %>% 
  layer_points(key := ~id) %>% 
  add_tooltip(function(df) mtc$disp[mtc$id==df$id])

though I don't know if something simpler for the specification of the function in add_tooltip could be used...

Thank you very much for your help, and for the great work on ggvis, which is an awesome package, I am using more and more!

Mathieu

Winston Chang

unread,
Oct 7, 2014, 12:07:24 PM10/7/14
to Mathieu Kessler, gg...@googlegroups.com
Oh right, I just copied that part of the code from your original example - I only modified the code to make the disappearing-point problem go away. Glad you got it figured out!

-Winston
Reply all
Reply to author
Forward
0 new messages