ggplotly: log argument cancels axis labels

前提是你 提交于 2019-12-01 19:06:05

问题


I just discovered the newish ggplotly function that makes ggplot2 graphs into interactive plotly visualizations. This is great. But I also ran into an odd effect, possibly a bug.

If I use the log= argument to change the axis scales, the axis labels disappear. log="x" will cause the x axis label to disappear, log="y" will cause the y axis label to disappear, and log="xy" will cause both to disappear.

The same thing happens if I use scale_x_log10() and scale_y_log10() functions instead of the log argument.

Is there a workaround for this?

Example (y axis label is visible, x axis label disappears):

qplot(wt, mpg, data=mtcars, colour=factor(cyl), log="x")
ggplotly()

or

qplot(wt, mpg, data=mtcars, colour=factor(cyl)) + scale_x_log10()
ggplotly()

回答1:


You can get axis names if you supply them as arguments to scale_... function.

qplot(wt, mpg, data=mtcars, colour=factor(cyl)) + scale_x_log10("wt")
ggplotly()



回答2:


or maybe this?

ggplot(data = mtcars, aes(x = log10(wt), y=mpg, colour = factor(cyl))) + 
  geom_point() + 
  scale_x_continuous("wt, log10-scaling")

ggplotly()



回答3:


Maybe this:

gg <- ggplot(mtcars, aes(x=wt, y=mpg)) + 
  geom_point() + coord_trans(y="log10")
ggplotly(gg) %>% layout(yaxis = list(type="log", autorange=TRUE))



来源:https://stackoverflow.com/questions/34569347/ggplotly-log-argument-cancels-axis-labels

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!