【问题标题】:plotly histogram with log-bins用对数箱绘制直方图
【发布时间】:2017-01-03 19:35:14
【问题描述】:
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 轴标签看起来像的绘图图

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

但垃圾箱看起来像

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

也就是说,我希望箱子的宽度呈指数增长,但使用对数轴(这样箱子看起来宽度相同),并带有有用的轴标签,而不仅仅是显示对数美元

【问题讨论】:

  • 对否决票有任何反馈吗?

标签: r plotly


【解决方案1】:

我不知道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()

这是你想要的吗?

【讨论】:

    猜你喜欢
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 2019-07-11
    • 2012-08-31
    • 2021-04-08
    • 2011-04-16
    • 2019-11-28
    • 2021-09-29
    相关资源
    最近更新 更多