Skip to content

Exponents in labels not captured properly #2006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danton267 opened this issue Sep 24, 2021 · 1 comment
Closed

Exponents in labels not captured properly #2006

danton267 opened this issue Sep 24, 2021 · 1 comment
Assignees
Labels

Comments

@danton267
Copy link
Member

danton267 commented Sep 24, 2021

library(plotly)
require(MASS) # to access Animals data sets
require(scales) # to access break formatting functions
data(Animals) # load data

# x and y axis are transformed and formatted
p <- ggplot(Animals, aes(x = body, y = brain)) + geom_point() +
     scale_x_log10(breaks = trans_breaks("log10", function(x) 10^x),
              labels = trans_format("log10", math_format(10^.x))) +
     scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
              labels = trans_format("log10", math_format(10^.x))) +
     theme_bw() 

ggplotly(p)

The axis labels results in only exponents being displayed, it is missing the base.

Also, annotation_logticks() does not work when it's added.

@cpsievert
Copy link
Collaborator

cpsievert commented Nov 1, 2021

Years ago I looked into the issue of translating R's plot expressions and it seemed like a very difficult problem to solve in general (see #571 for details). In the meantime, you'll have to resort to tickformat or ticktext/tickvals hacks, like so:

p <- ggplot(Animals, aes(x = log10(body), y = log10(brain))) + geom_point()
ggplotly(p) %>%
  layout(
    xaxis = list(
      ticktext = paste0("10<sup>", c(0, 2, 4), "</sup>"),
      tickvals = log10(c(10^0, 10^2, 10^4))
    ),
    yaxis = list(
      ticktext = paste0("10<sup>", c(0, 1, 2, 3), "</sup>"),
      tickvals = log10(c(10^0, 10^1, 10^2, 10^3))
    )
  )

(Although, at this point, you should probably just be using plot_ly() over ggplotly())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants