首页 > 解决方案 > 如何在R中绘制由包绘制的图表的log2变换轴?

问题描述

目前我在 R 中使用 plotly,我想知道我应该使用什么代码来 log2 转换其中一个轴?

非常感谢您的回答!

标签: rr-plotly

解决方案


log这是在 x 轴上进行变换的示例。但是,我不知道是否可以这样做log2

library(plotly)

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

另一种方法是使用ggplot2with scale_x_continuouswith trans = "log2",然后ggplotly

library(ggplot2)

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

ggplotly(p)

推荐阅读