用log-bin描绘直方图

时间:2017-01-03 19:35:14

标签: r plotly

library(plotly)

对于这些数据:

exDT2 <- structure(list(outflow = c(-150, -195, -200, -200, -200, -200, 
-250, -250, -250, -250, -255, -300, -300, -300, -300, -300, -305, 
-305, -350, -350, -400, -400, -435, -450, -450, -450, -450, -450, 
-455, -455, -464, -470, -470, -500, -500, -500, -500, -500, -500, 
-5000)), .Names = "outflow", row.names = c(NA, -40L), class = c("data.table", 
"data.frame"))

我想要一个x轴标签看起来像的情节图 good label

plot_ly(exDT2, x = ~-outflow, type = "histogram") %>% layout(xaxis = list(title = "Title", type = "log"))

但是看起来像垃圾箱 good bins

plot_ly(exDT2, x = ~log(-outflow), type = "histogram") %>% layout(xaxis = list(title = "Title"))

也就是说,我希望这些容器的宽度呈指数增长,但是使用对数轴(使得容器看起来宽度相同),并且使用有用的轴标签,而不是仅显示log-dollars < / p>

1 个答案:

答案 0 :(得分:0)

我不知道是否可以plotly完成此操作,但如果您对ggplot2ggplotly开放,也许您可​​以尝试:

ggplot(exDT2, aes(-outflow)) + 
geom_histogram(binwidth = 0.2, fill="blue") + 
scale_x_log10(breaks=c(100, 200,500,1000, 5000)) + theme_bw()
ggplotly()

这就是你想要的吗?