【问题标题】:Format the tick in plotly histogram's x-axis在绘图直方图 x 轴中格式化刻度
【发布时间】:2019-10-15 03:38:15
【问题描述】:

我在下面有一个简单的数据框d,我想根据其值的频率创建一个直方图。我试图将初始值设置为0,然后通过5 在x 轴上显示这些值,但这些值似乎都不起作用,因为值从1 开始,然后显示8。我更希望有一个明确的情节解决方案作为首选,没有ggplot() 干扰。

d<-data.frame(c(1,5,7,5,4,5,6,7,8,9,10,15,13))
x <- list(
  tick0=0,
  dtick=5

)

# Create the plotly histogram

plot_ly(alpha = 0.9) %>%
  add_histogram(x = as.factor(d[,1]),source="subset") %>%
  # Add titles in plot and axes
  layout(barmode = "overlay",xaxis=x,margin=list(b=100))

【问题讨论】:

    标签: r plotly r-plotly


    【解决方案1】:

    类似下面的方法有点不同,但我认为结果就是你想要的。

    d<-data.frame(x = c(1,5,7,5,4,5,6,7,8,9,10,15,13))
    
    gg <- ggplot(d, aes(x)) + geom_histogram() + stat_bin(breaks = c(0, 5, 10, 15), binwidth = 5)
    
    ggplotly(gg)
    

    【讨论】:

    • 感谢这很有用,可能会使用它,但如果存在,我希望有一个清晰的情节解决方案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多