plotly / plotly/plotly.R

geom_sina plot doesn't show when linked to another plot via brushing in Shiny

未关闭
#1,858 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
R
星标
2.7k
派生
641
PR 合并指标
30 天内没有已合并 PR

描述

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)

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先运行提供的 R Shiny 示例,并将 ggforce::geom_sina 情况与正常工作的 geom_point 情况进行比较。跟踪 ggplotly 转换和 key 处理,以确定为什么添加 key=key 会导致绘图无法渲染;当 sina 图显示出来,并且其中被点击的点仍然链接到第二个图时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
r
领域
data-visualization
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。