0

Currently I am using plotly in R, and I wonder what code should I use to log2 transform one of the axes ?

Thank you very much for your answer!

camille
  • 15,634
  • 17
  • 33
  • 53
Jimmy Lee
  • 97
  • 6
  • 1
    [See here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) on making an R question that folks can help with. That includes a sample of data, all necessary code, and a clear explanation of what you're trying to do and what hasn't worked. – camille Apr 05 '19 at 14:21

1 Answers1

0

Here is an example to do log transform on the x-axis. However, I don't know if it is possible to do log2.

library(plotly)

mtcars %>%
  plot_ly(x = ~disp, y = ~mpg) %>%
  add_markers(marker = list(opacity = 0.8)) %>%
  layout(xaxis = list(type = "log"))

An alternative is to use ggplot2 with scale_x_continuous with trans = "log2", and then ggplotly

library(ggplot2)

p <- ggplot(mtcars, aes(x = disp, y = mpg)) +
  geom_point() +
  scale_x_continuous(trans = "log2")

ggplotly(p)
www
  • 37,164
  • 12
  • 37
  • 72