我正在使用R plotly来显示数据点。每个数据点都附有文本,当我点击相应的数据点时,我想在信息框中显示它。
我的代码如下所示。目前" MESSAGE_BODY"正在显示在工具提示中,但是当文本长度不足时,它不会起作用,因为文本超出了工具提示的限制。
在我的原始代码下面,我提供了一个可重现的例子,我的意思是"超越限制"。
原始代码:
plot_ly(PLS.scores,
x = Comp1,
y = Comp2,
type = "scatter",
mode = "markers",
color = as.factor(TARGET),
colors = c("red", "green"),
text = paste("Message:", MESSAGE_BODY))
可重复的例子:
install.packages("plotly")
library(plotly)
texts <- c("This is a short text and it works fine with the tool tip",
"This text also work fine with the tooltip",
"So does this one",
"This text however, is so lengthy that it exceeds the limits if the tooltip. Therefore it would be extremely nice to be able to show such lengthy texts in a separate window with scrollbars! Or at least it is so lenghty that i hope you get the point... ")
dataX <- c(1,2,3,1)
dataY <- c(2,1,3,3)
TARGET <- c(1,0,1,0)
df <- data.frame(dataX,dataY,TARGET,texts)
plot_ly(df,
x = dataX,
y = dataY,
type = "scatter",
mode = "markers",
color = as.factor(TARGET),
colors = c("red", "green"),
text = paste("Message:", texts))
答案 0 :(得分:1)
添加<br>
以将文字分隔到新行
texts <- c("This is a short text and it works fine with the tool tip",
"This text also work fine with the tooltip",
"So does this one",
"This text however, is so lengthy that it exceeds the limits if the tooltip. <br> Therefore it would be extremely nice to be able to show such lengthy texts in a separate window with scrollbars!<br> Or at least it is so lenghty that i hope you get the point... ")