geom_sina plot doesn't show when linked to another plot via brushing in Shiny
Nobody has claimed this yet.
- Dominant language
- R
- Stars
- 2.7k
- Forks
- 641
- PR merge metrics
- No merged PRs in 30d
Description
Hello,
I'm attempting to link points from a geom_sina object to another plot (it will be a bar-plot but for now, I just have a scatterplot to illustrate the problem). The issue is that when I put the "key=key" aesthetic into geom_sina, the plot doesn't show up.The plot will show up if I remove the "key=key" aesthetic, but then I have no means by which to connect the plots. I think this might be a bug given that this works fine with geom_point.
library(plotly)
library(shiny)
library(tidyverse)
df = diamonds
df = df[sample(1:nrow(df), size=1000, replace=FALSE), ] %>%
rownames_to_column("key")
server <- function(input, output) {
output$my_points <- renderPlotly({
p = ggplot(df, aes(x=cut, y=price, label=clarity)) +
coord_flip() +
ggforce::geom_sina(aes(color=carat, key=key), alpha=.2) +
# gggforce::geom_sina(aes(color=carat), alpha=.2) + # this will make the plot show up, but doesn't link it to the other
# geom_point(aes(color=carat, key=key), alpha=.2) + # using geom_point works here
theme_light()
ggplotly(p, source="ggplotly_points")
})
selected_values <- reactive({
brush <- event_data("plotly_click", source="ggplotly_points")
if (is.null(brush)) {
TRUE
} else {
df$key == (brush$pointNumber + 1)
}
})
output$scatter <- renderPlotly({
df %>%
filter(selected_values()) %>%
plot_ly(
x = ~carat,
y = ~price,
alpha = 0.2
) %>%
toWebGL()
})
}
ui <- fluidPage(
plotlyOutput("my_points"),
plotlyOutput("scatter")
)
shinyApp(ui, server)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the supplied R Shiny example and compare the ggforce::geom_sina case with the working geom_point case. Trace the ggplotly conversion and key handling to identify why adding key=key prevents the plot from rendering; done means the sina plot displays and its clicked points still link to the second plot.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- data-visualization
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100