bug with the font parameter for annotation
Nessuno ha ancora preso questa issue.
- Lingua principale
- R
- Stelle
- 2.7k
- Fork
- 641
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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:

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

> packageVersion("plotly")
[1] ‘4.5.2’
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo l’esempio di heatmap in R fornito e ispeziona l’output di plotly_build(pp), in particolare x$layout$annotations. Traccia il modo in cui add_annotations gestisce la lista font; il lavoro è completato quando color, family e size rimangono un unico oggetto font su un’annotazione invece di produrre tre annotazioni.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- r
- Ambito
- data-visualization
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100