26

I am trying to create a scatterplot matrix with interactive selection between geom items in individual matrix plots. This works when I am dealing with geom_points (inside ggpairs()). When a user selects points in any of the 3 bottom-left individual matrix plots, then they can see the points highlighted in the other matrix plots. Below is a simple example:

library(GGally)
library(ggplot2)
library(plotly)
dat = mtcars[,1:3]
p <- ggpairs(dat)
ggplotly(p)

However, in my case, I am aiming to use geom_hex instead of geom_points. I am hoping to develop a way that a user can highlight a hexagon(s) in an individual matrix, and see all hexagons in the other individual matrices that contain at least one of the observations that composed that original hexagon(s).

I believe this may be a step more complicated, because hexagons are binning summaries that group together several observations. Below is my progress so far toward this goal:

my_fn <- function(data, mapping, ...){
  p <- ggplot(data = data, mapping = mapping) + geom_hex(binwidth=3)
  p
}
p <- ggpairs(dat, lower = list(continuous = my_fn))
ggplotly(p)

When I hover over individual hexagons, I receive interactive information about their count number (which I like). However, when I attempt to select hexagon(s) in one matrix, I do not see corresponding hexagons that contain at least one observation of the original hexagon.

I am relatively familiar with Shiny and R. If you know of a method that I can use to possibly solve this problem, please kindly share!

=============== Session Info ===============

R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X Mavericks 10.9.5

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] data.table_1.10.0  shiny_0.14.2       hexbin_1.27.1      plotly_4.5.6.9000 
[5] ggplot2_2.2.0.9000 GGally_1.3.0      

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8        colourpicker_0.3   RColorBrewer_1.1-2 plyr_1.8.4        
 [5] prettyunits_1.0.2  base64enc_0.1-3    tools_3.3.2        progress_1.1.2    
 [9] digest_0.6.10      jsonlite_1.1       tibble_1.2         gtable_0.2.0      
[13] viridisLite_0.1.3  lattice_0.20-34    DBI_0.5-1          crosstalk_0.3.1   
[17] yaml_2.1.14        stringr_1.1.0      dplyr_0.5.0        httr_1.2.1        
[21] htmlwidgets_0.8    grid_3.3.2         reshape_0.8.6      R6_2.2.0          
[25] purrr_0.2.2        tidyr_0.6.0        reshape2_1.4.2     magrittr_1.5      
[29] scales_0.4.1.9000  htmltools_0.3.5    assertthat_0.1     mime_0.5          
[33] xtable_1.8-2       colorspace_1.3-2   httpuv_1.3.3       labeling_0.3      
[37] stringi_1.1.2      miniUI_0.1.1       lazyeval_0.2.0     munsell_0.4.3 
  • 1
    When I try your first example, only points in the current plot are highlighted. Points in the other plots are not highlighted. Am I missing a setting or option? – oshun Jan 10 '17 at 21:04
  • Hello @oshun. Thanks for letting me know. Are you using the "Box select" or "Lasso select" options in plotly? –  Jan 11 '17 at 05:46
  • 1
    Tried both. What versions are you using? I tried on R 3.3.2 and plotly 4.5.6. – oshun Jan 11 '17 at 23:18
  • @oshun I see. Sorry, I added that information as an edit. I am using R 3.3.2 and plotly 4.5.6.9000. –  Jan 12 '17 at 02:12
  • 1
    Updated plotly but still don't see points highlighted in other subplots. Regardless, the hex bins aggregate data differently, as you point out, so determining which hexagons in other subplots to highlight probably requires a stricter rule than "contains at least one of the same original observations." You could try manually binning data, then visualizing with shiny + `nearPoints`, but this might be redundant if your original `ggplotly` example already highlights points across subplots. – oshun Jan 13 '17 at 03:52
  • Hello @oshun. I really appreciate your comments. I am thinking of taking my goal a step down, and not necessarily linking between subplots. I am aiming to now simply return observations that are in a clicked geom_hex. Would an idea like that still seem out of reach, in your opinion (http://stackoverflow.com/questions/41583889/obtain-observations-in-geom-hex-using-plotly-and-shiny) ? –  Jan 14 '17 at 20:56
  • Have you checked echarts4r connect() options ? -> https://echarts4r.john-coene.com/articles/connect.html – David Muñoz Tord Jun 28 '23 at 08:52

0 Answers0