Skip to content

Instantly share code, notes, and snippets.

@cpsievert
Last active April 14, 2017 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cpsievert/b873740854cbfcc7a6c7ce891447c3fb to your computer and use it in GitHub Desktop.
Save cpsievert/b873740854cbfcc7a6c7ce891447c3fb to your computer and use it in GitHub Desktop.
library(plotly)
library(tidyr)
library(crosstalk)
m <- gather(mtcars, variable, value, -vs)
msd <- SharedData$new(m, ~variable)
gg <- ggplot(msd, aes(factor(vs), value)) +
geom_jitter(alpha = 0.3)
bscols(widths = c(11, 6, 6),
filter_select("id", "Select a variable", msd, ~variable, multiple = FALSE),
ggplotly(gg, dynamicTicks = TRUE) %>% layout(margin = list(l = 30)),
plot_ly(msd, x = ~jitter(vs), y = ~value) %>% add_markers(alpha = 0.3)
)
@jcheng5
Copy link

jcheng5 commented Apr 14, 2017

Some issues I'm seeing (this is with ggplot2 and plotly installed from GitHub master just now, and crosstalk installed from CRAN):

  1. Selecting points on the left plot don't cause highlighting on the right
  2. When I make a selection on the right plot, it highlights the points on the left; but when I clear the selection on the right plot by double-clicking, the highlighting on the left doesn't reset.
  3. When I make a selection on a plot, it should cancel the selection on the other plot--it doesn't (i.e. the selection outline on the other plot remains).
  4. When I change the selected variable, the y-axis range doesn't seem to update correctly on the left plot (it does on the right though).
  5. When the select box pops down over the plots, mouse clicks that are intended for the dropdown seem to get intercepted by the plots. (I had heard rumors of this bug but this is the first time I can remember seeing it)

@cpsievert
Copy link
Author

Sorry, I didn't make this example with the intention of doing (1).

If I did, I would have done, msd <- SharedData$new(m) and would have added highlight(off = "plotly_deselect"), which would solve (2) and (3). The default "off event" is a relayout which can be triggered via the home button

I'm aware of (4), and partially why I made the example, plotly/plotly.R#944

Thanks for bringing up (5), I've seen this before too, but I think it's something that needs to be addressed in plotly.js

I just wanted to show the two different ways of acheiving jitter and acheviing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment