plotly / plotly/plotly.R

bug with the font parameter for annotation

Ouverte
#780 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

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

Description

I want to add an annotation to a plotly heatmap. There is a bug with the font parameter. I've followed the example given here.

library(plotly)

### heatmap data ### 
x <- 1:3; y <- 3:5
dd <- transform(expand.grid(x=x, y=y), z=x+y)

### plotly graphic ###
pp <- plot_ly(data=dd, x=~x, y=~y, z=~z, type="heatmap",
              hoverinfo = 'text',
              text = ~paste('<em>x</em>: ', dd$x, 
                            '</br> <em>y</em>: ', dd$y,
                            '</br> <em>z</em>: ', dd$z)) %>%
  layout(xaxis=list(title="<em>xaxis title</em>"))

### add annotation ###
pp <- pp %>% 
  add_annotations(  x = 1,
                    y = 4,
                    text = "<em>MY ANNOTATION</em>",
                    xref = "x",
                    yref = "y",
                    showarrow = TRUE,
                    arrowhead = 7,
                    ax = 10,
                    ay = 30,
                    font = list(color = 'red',
                                family = 'sans serif',
                                size = 24)
  )

That does not yield the expected result:

rplot_annotation

In fact, the problem lies in the fact that plotly_build generates three annotation layouts, one for each parameter of the font list:

> bpp <- plotly_build(pp)
> annotation <- bpp$x$layout$annotations
> length(annotation)
[1] 3
> sapply(annotation, function(x) x$font)
[1] "red"        "sans serif" "24"  

Thus, here is a way to get the expected result:

myannotation <- annotation[[1]]
myannotation$font <-  list(color = 'red',
                           family = 'sans serif',
                           size = 24)
bpp$x$layout$annotations <- myannotation
bpp

rplot_annotation_good

> packageVersion("plotly")
[1] ‘4.5.2’

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 l’exemple de heatmap R fourni et inspectez la sortie de plotly_build(pp), en particulier x$layout$annotations. Suivez la manière dont add_annotations gère la liste font ; c’est terminé lorsque color, family et size restent un seul objet font sur une annotation au lieu de produire trois annotations.

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

Évaluation

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

Recevez les nouvelles issues par e-mail

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