Skip to content

[R-plotly] Hovertemplate fails in violin plot #1946

@PWbio

Description

@PWbio

I attempt to use the hovertemplate argument to format the hover text, but it cannot properly display.
However the argument works for type = "scatter". Similar issue was found in #1636 with box plot.

df <- tibble(x = sample(letters[1:3], 100, replace = T), y = rnorm(100))
df %>% plot_ly(
  x = ~x,
  y = ~y,
  split = ~x,
  type = 'violin',
  box = list(
    visible = TRUE
  ),
  hovertemplate = "%{y}", # not work
  hoveron = "kde",
  jitter = 1,
  alpha = 0.5,
  spanmode = "hard"
  )
)

Screen Shot 2021-04-23 at 23 55 03


Using text argument + hoverinfo will let the hover disappear completely

df %>% plot_ly(
  x = ~x,
  y = ~y,
  split = ~x,
  text = ~y, # using text argument
  type = 'violin',
  box = list(
    visible = TRUE
  ),
  hoverinfo = "text", # with hoverinfo
  hoveron = "kde",
  jitter = 1,
  alpha = 0.5,
  spanmode = "hard"
  )
)

image


Using hoverinfo = "y" comes along with kde

df %>% plot_ly(
  x = ~x,
  y = ~y,
  split = ~x,
  type = 'violin',
  box = list(
    visible = TRUE
  ),
  hoverinfo = "y",
  hoveron = "kde",
  jitter = 1,
  alpha = 0.5,
  spanmode = "hard"
  )

image


However, hoverinfo = "x" works properly,

df %>% plot_ly(
  x = ~x,
  y = ~y,
  split = ~x,
  type = 'violin',
  box = list(
    visible = TRUE
  ),
  hoverinfo = "x",
  hoveron = "kde",
  jitter = 1,
  alpha = 0.5,
  spanmode = "hard"
  )

image

R version = 4.0.5, R-plotly version = 4.9.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions