bug with the font parameter for annotation
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- R
- Estrellas
- 2.7k
- Forks
- 641
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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’
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza ejecutando el ejemplo de mapa de calor en R proporcionado e inspecciona la salida de plotly_build(pp), especialmente x$layout$annotations. Rastrea cómo add_annotations maneja la lista font; estará terminado cuando color, family y size permanezcan como un único objeto font en una anotación, en lugar de producir tres anotaciones.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- r
- Área
- data-visualization
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100