plotly / plotly/plotly.R

Selective scatter hover disturbed for unequal marker sizes

Ouverte
#2,059 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Langage dominant
R
Étoiles
2.7k
Forks
641
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

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

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par exécuter la reproduction R fournie et comparez les graphiques de marqueurs de même taille et de tailles différentes. Étudiez la manière dont les traces scatter de base et de surbrillance se font concurrence lors du hover, puis vérifiez que les points mis en surbrillance restent faciles à survoler tandis que le hover sur les points de base reste supprimé avec des tailles de marqueur différentes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
plotly, r
Domaine
data-visualization
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.