【发布时间】:2016-03-09 14:58:35
【问题描述】:
我正在使用 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))
【问题讨论】: