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)
)
@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