plotly / plotly.R

An interactive graphing library for R
https://plotly-r.com
Other
2.56k stars 626 forks source link

add_annotations doesn't respect log scale #1743

Open sjmgarnier opened 4 years ago

sjmgarnier commented 4 years ago

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"))
daquity36 commented 1 year ago

Hey, I have the exact same problem..

kb- commented 1 year ago

This bug is also present in the Python version. I can't believe it's still there after 3 years!

GFuhr commented 1 month ago

Bug still present for python version in Sept 2024 :(