admin管理员组

文章数量:1402287

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)))

Which produces this plot:

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 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?

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)))

Which produces this plot:

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/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?

Share Improve this question edited Mar 21 at 14:24 EricLavault 16.1k3 gold badges27 silver badges56 bronze badges asked Mar 21 at 12:49 NoskarioNoskario 6764 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

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))

本文标签: How do I make that the whole trace name in R plotly plot is shownStack Overflow