Is there a way to customize the hover text in a contour plot in R plotly using data from sources other that the text
argument? Here is a minimal reproducible example:
library(plotly)
x <- y <- 0:100
z <- outer(X = x, Y = y, function(x, y) 2*x + 3*y)
sum <- outer(X = x, Y = y, function(x, y) x + y)
product <- outer(X = x, Y = y, function(x, y) x * y)
difference <- outer(X = x, Y = y, function(x, y) x - y)
plot_ly(
type = "contour",
x = x,
y = y,
z = z,
text = sum,
hovertemplate = "x is %{x}<br>y is %{y}<br>z is %{z}<br>sum is %{text}<extra></extra>"
)
The text
argument allows me to display the sum
data. I would also like to display the product
and difference
data; however, I am unsure how to go about it.
The following question has an answer (using the annotations
argument), which does not work with the contour
trace: https://stackoverflow.com/questions/42170476/custom-hoverinfo-text-on-plotly-r-chart-that-is-different-to-the-text-paramete
This question also has an answer; however, the user relies on ggplot2
: https://stackoverflow.com/questions/50024089/r-plotly-map-hover-text-reading-from-2-data-frames
Finally, I learned about the customdata
argument, but it requires me to code in JavaScript (https://plotly-r.com/supplying-custom-data.html). There seems to be a way to NOT use JS with this argument, but I only have evidence that it works for sankey diagrams (https://github.com/plotly/plotly.js/pull/4621).
Your help will be very much appreciated.