r语言 - 如何向绘图悬停标签添加换行符



有没有办法让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 = "n")

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

当然,这只是忽略分隔符并在一行上打印所有内容。我可以欺骗 plotly/R 识别该换行符吗?

只需使用 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")

此外,您还可以使用 HTML 标签来更改字体样式(以及更多)......

最新更新