Comment ajouter des sauts de ligne aux étiquettes Plotly hover

y a-t-il un moyen d'obtenir plotly pour afficher le texte de hover sur plusieurs lignes/pour le faire reconnaître la ligne de caractères spéciaux 'n' dans le texte?

une version factice de ce que je cherche à faire est:

data <- data.frame(cbind(rnorm(10, 8), rnorm(10, 2)))
names(data)<-c("thing1", "thing2")

data$hovertext <- paste("here's a coordinate: ",
                         round(data$thing1,1), sep = "n")


p <- plot_ly(data, type = 'scatter', x = thing1, y = thing2, 
             text = hovertext, hoverinfo = 'text', mode = "markers")

ce qui, bien sûr, ne tient pas compte du séparateur et imprime tout sur une ligne. Puis-je piéger plotly/R en reconnaissant cette rupture de ligne?

18
demandé sur Martin Schmelzer 2016-01-19 16:56:29

1 réponses

il suffit D'utiliser la balise HTML <br>:

library(plotly)
data <- data.frame(cbind(rnorm(10, 8), rnorm(10, 2)))
names(data) <- c("thing1", "thing2")

data$hovertext <- paste("here's a coordinate:",
                     round(data$thing1,1), sep = "<br>")


p <- plot_ly(data, type = 'scatter', x = ~thing1, y = ~thing2, 
         text = ~hovertext, hoverinfo = 'text', mode = "markers")

de plus, vous pouvez utiliser des balises HTML pour changer les styles de police (et bien plus encore)...

35
répondu Martin Schmelzer 2017-04-02 16:55:00