davidgohel / ggiraph

make 'ggplot' graphics interactive
https://davidgohel.github.io/ggiraph
788 stars 74 forks source link

tooltip aes ignored by geom_boxplot_interactive #223

Closed jguppy closed 2 years ago

jguppy commented 2 years ago

Hi,

I've been trying to generate a grid_plot containing two _geom_smoothinteractive/_geom_pointinteractive plots, and a third _geom_boxplotinteractive.

The tooltip designation for the geom_smooth and geom_point work as described, however for the boxplot, the tooltip for the outliers shows the y value itself, rather than the tooltip value assigned. In this use case the ID of the outlier data point is particular interest and I would like it to link across as intended to the other plots in the grid (see example code below).

This occurs when generating a single boxplot as well. Looking at the code associated with geom_boxplot_interactive() line 89 looks to hard code the tooltip option rather than inherit provided aesthetics.

I can understand in cases where no tooltip is provided that this would be the standard use for most people but, this breaks functionality when linking in with the other plot types.

Is this intended? And is it possible to have this only set to the y value if no tooltip aes is provided?

Thanks for your help with this,

###Plot Marey map interactively
  Plot6 <- ggplot(data = DDD, aes(x = phys/1000000, y = gen))+
                            geom_smooth(method = "loess", span = 0.3,
                                                    method.args = list(degree = 2), se = T)+
                            geom_point_interactive(aes(tooltip = mkr, data_id = mkr))

###Plot Recombination Rate interactively  
  Plot7 <- ggplot(data = DDD, aes(x = phys/1000000, y = recomb))+ 
                            geom_smooth_interactive(method = "loess", span = 0.3,
                                                                       method.args = list(degree = 2), se = T)+
                            geom_point_interactive(aes(tooltip = mkr, data_id = mkr))

###Plot Intermarker distance boxplot interactively
  Plot8 <- ggplot(data = DDD, aes(y = IMD))+
                geom_boxplot_interactive(aes(tooltip = mkr, data_id = mkr, group = map))

###Combine interactive plots
  girafe(ggobj = plot_grid(plot_grid(Plot6, Plot7, align = "v", nrow = 2),
                                          Plot8, align = "v", nrow = 1, rel_widths = c(2,1)),
            width_svg=12, height_svg=6,
            options = list(opts_sizing(rescale = T, width = 1),
                                   opts_selection(type = "multiple", only_shiny = F),
                                   opts_toolbar(position = "bottomleft")))
sigmapi commented 2 years ago

@jguppy This is fixed now in latest github version. The issue is that the interactive parameters for geom_boxplot_interactive are attached to the boxplot itself, not to the points. Because the dataset is converted by boxplot stat and the point information is lost. The previous behavior was not optimal but at least it could show the y point.

Now you can supply interactive parameters for the outliers by prefixing them with outlier. prefix. For example:

Plot8 <- ggplot(data = DDD, aes(y = IMD))+
                geom_boxplot_interactive(aes(tooltip = mkr, data_id = mkr, group = map, 
                              outlier.tooltip=paste("I am an outlier at:", IMD )))