Reputation: 915
I am using R plotly to display datapoints. Each datapoint has texts attached to it, which I would like to display in an infobox when the corresponding datapoint is clicked.
My code is showed below. Currently "MESSAGE_BODY" is being displayed in the tooltip, but it will not do the trick when the text is lenghty, because the texts exceeds the limits of the tooltip.
Below my original code I provide a reproducible an example of what I mean by "Exceeds the limits".
Original code:
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))
Reproducible example:
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))
Upvotes: 1
Views: 769
Reputation: 2313
add <br>
to seperate text to the new line
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... ")
Upvotes: 1