如何添加换行符以绘制悬停标签标签、换行符

由网友(谈爱、你卜配)分享简介:有没有办法在多行上显示悬停文本/让它识别文本中的特殊字符行''?Is there a way to get plotly to display the hover text on multiple lines/get it to recognize special characters line '' in th...

有没有办法在多行上显示悬停文本/让它识别文本中的特殊字符行' '?

Is there a way to get plotly to display the hover text on multiple lines/get it to recognize special characters line ' ' 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 = "
")


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

这当然会忽略分隔符并将所有内容打印在一行上.我可以欺骗 plotly/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)...

阅读全文

相关推荐

最新文章