plotly / plotly/plotly.R

[R-plotly] Hovertemplate fails in violin plot

Open
#1,946 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied R violin-plot examples and compare their hover behavior with the working scatter case and related box-plot issue #1636. Trace the violin hover handling from the R example into the relevant plotly.R entry point; done when hovertemplate and hoverinfo display the requested y text without losing the KDE hover information.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.