plotly / plotly/plotly.R

Selective scatter hover disturbed for unequal marker sizes

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

还没有人认领这个 Issue。

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

描述

Hi -

I would like to create a scatter plot in which the hover tooltip is shown for a small number of highlighted points and hidden for the majority of 'base' points. This works well if the markers for the 'highlight' and 'base' points are the same size, but it is very hard to get the hover to activate if there is any difference between the 2 trace's marker sizes. I have created an illustration for this below - apologies the code is quite long, but hopefully it makes it easy to understand the problem I'm describing.

Is there a way to avoid the 'base' trace interfering with the hover for the 'highlight' trace whilst having different sized markers for the two traces?

library(plotly)
library(dplyr)

# Create 'base' points data - hover not to be shown
n <- 1e4
baseData <- tibble(
  x = rnorm(n),
  y = 2*x + rnorm(n, sd = 5),
  type = "Base")

# Create 'highlight' points data - hover to be shown
### Add a point in bottom right quadrant that won't overlap with base points
highlightData <- tibble(
  x = c(rnorm(10), 3.5),
  y = c((2*x[1:10] + rnorm(10, sd = 5)), -18),
  type = "Highlight")

# Create plots with equal and unequal sized markers
plots <- lapply(
  c(20, 19), # Define base points size for each plot 
  function(baseSize) {
    # Show legend for first plot only
    showLeg <- ifelse(baseSize == 20, TRUE, FALSE)
    
    plot_ly(colors = c("#66C2A5", "#FC8D62")) %>% 
      # Create trace with no hover for base data
      add_trace(
        data = baseData,
        x = ~x, y = ~y, color = ~type,
        legendgroup = ~type, showlegend = showLeg,
        alpha  = 0.1, 
        type = "scatter", mode = 'markers',
        hoverinfo = "skip",
        marker = list(size = baseSize)) %>%
      # Create trace WITH hover for highlight data
      add_trace(
        data = highlightData,
        x = ~x, y = ~y, color = ~type,
        legendgroup = ~type, showlegend = showLeg,
        type = "scatter", mode = 'markers', 
        hoverinfo = "all",
        marker = list(
          size = 20,
          color = 'rgba(255, 182, 193, .9)',
          line = list(color = 'rgba(152, 0, 0, .8)',
                      width = 2)))
  })

# Create & append subplot titles
# Update title
annotations = list( 
  list( 
    x = 0.2,  y = 1.0,  
    text = "Equal Sized Markers - Easy Hover...",  
    xref = "paper",  yref = "paper",  
    xanchor = "center", yanchor = "bottom", showarrow = FALSE),  
  list( 
    x = 0.8, y = 1,  
    text = "Unequal Sizes - Hover only easy in bottom right point...",  
    xref = "paper", yref = "paper",  
    xanchor = "center", yanchor = "bottom", showarrow = FALSE))

subplot(plots[[1]], plots[[2]]) %>%
  layout(annotations = annotations) 

Thank you for your help and (as always) for this fantastic package!

Ben

贡献指南

打开贡献指南

从这里开始

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

调研方向

首先运行提供的 R 复现,并比较等大小和不等大小标记的图。调查基础 scatter trace 和高亮 scatter trace 在 hover 期间如何竞争,然后确认即使使用不同的标记大小,高亮点仍然易于 hover,而基础点的 hover 仍保持被抑制。

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

评估

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

把新 issue 发到你的邮箱

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