Have a look at the following plot:
library(plotly)
pd <- structure(list(x = c(11, 12, 13, 11, 12, 13), variable = structure(c(
1L,
1L, 1L, 2L, 2L, 2L
), levels = c(
"veryveryveryveryveryverylongname1",
"veryveryveryveryveryverylongname2"
), class = "factor"), value = c(
1,
2, 3, 4, 3, 2
)), row.names = c(NA, -6L), class = "data.frame")
pd
plot_ly(pd, x=~x, y=~value, color=~variable) |>
layout(list(hoverlabel=list(namelength=-1L)))
Problem: The hover label only shows veryveryvery...
so it is not easy to see from which trace it came. (I can use the color as a hint and look at the legend, but in case there are many traces the full name would be better.)
On this website https://community.plotly.com/t/how-to-display-the-whole-signal-name-with-the-hover-mode-is-x/47687 I found that the approach layout(list(hoverlabel=list(namelength=-1L)))
should work, but it has no effect.
What am I doing wrong? Is there another approach?
You almost have it.
All you to do is remove the outermost list()
inside layout()
.
For completeness, the R reference documentation describes the namelength
here.
plot_ly(pd, x = ~ x, y = ~ value, color = ~ variable) |>
layout(hoverlabel = list(namelength = -1L))