简体   繁体   中英

How to log2 transform axes of my graph ploted by the package plotly in R?

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!

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM