如何在换行悬停标签上添加换行符 [英] How to add line breaks to plotly hover labels
本文介绍了如何在换行悬停标签上添加换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种方法可以使多行显示悬停文本/使其能够识别文本中的特殊字符行'\ n'?
Is there a way to get plotly to display the hover text on multiple lines/get it to recognize special characters line '\n' in the text?
我想要做的一个虚拟版本是:
A dummy version of what I'm looking to do is:
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")
当然,它只是忽略分隔符并全部打印在一行上.我可以欺骗/R来识别该换行吗?
Which of course just ignores the separator and prints all on one line. Can I trick plotly/R into recognizing that line break?
推荐答案
只需使用HTML标签<br>
:
Just use the HTML tag <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")
此外,您还可以使用HTML标签来更改字体样式(以及更多)...
Additionally, you could use HTML tags to change the font styles as well (and much more)...
这篇关于如何在换行悬停标签上添加换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文