plotly / plotly/plotly.R

add_annotations doesn't respect log scale

Open
#1,743 3 comments 1 reaction 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

When using add_annotations with a log scale, the coordinates of the annotations are not automatically log-transformed.

exp_dat <- data.frame(x = 0:100, 
                      y = exp(0:100))
ann_dat <- data.frame(x = c(1, 10, 100), 
                      y = exp(c(1, 10, 100)),
                      label = c(1, 10, 100))

plot_ly(type = "scatter", mode = "lines+markers") %>%
  add_lines(., data = exp_dat, x = ~x, y = ~y) %>%
  add_annotations(., data = ann_dat, x = ~x, y = ~y, text = ~label) %>%
  layout(., yaxis = list(type = "log"))

The desired result can be obtained by manually log-transforming the coordinates, but it would be more intuitive if this wasn't necessary.

plot_ly(type = "scatter", mode = "lines+markers") %>%
  add_lines(., data = exp_dat, x = ~x, y = ~y) %>%
  add_annotations(., data = ann_dat, x = ~x, y = ~log10(y), text = ~label) %>%
  layout(., yaxis = list(type = "log"))

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 provided R example with add_annotations and a logarithmic y-axis, then inspect the add_annotations entry point and its handling of annotation coordinates. Done means annotations align correctly on the log scale without manually transforming y values.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.