如何添加换行符以绘制悬停标签 [英] How to add line breaks to plotly hover labels

查看:13
本文介绍了如何添加换行符以绘制悬停标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)...

这篇关于如何添加换行符以绘制悬停标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆