英文:
Histogram in R Plotly: set number of breaks
问题
我想要在R中为Plotly直方图选择分割数量,就像hist基础R中的"breaks"选项一样。
数据
x <- rnorm(1000)
基础R
hist(x, breaks = 50)
Plotly
library(plotly)
plot_ly(x = ~x, type = "histogram") # 如何添加breaks选项?
谢谢您的帮助。
英文:
I would like to choose the number of breaks for a plotly histogram in R like the option "breaks" in hist base R.
Data
x <- rnorm(1000)
Base R
hist(x,breaks = 50)
pltoly
library(plotly)
plot_ly(x = ~x, type = "histogram") # how to add breaks option ?
Thanks for your help.
答案1
得分: 1
尝试这样做:
library(plotly)
plot_ly(x = ~x, type = "histogram", nbinsx = 30)
英文:
Try this :
library(plotly)
plot_ly(x = ~x, type = "histogram", nbinsx = 30)
答案2
得分: 1
我找到了一个自定义解决方案,使用 xaxis.size 选项。
plot_ly(x = ~x, type = "histogram", xaxis = list(size = diff(range(x))/50))
英文:
I found a custom solution with the xaxis.size option
plot_ly(x = ~x, type = "histogram", xaxis = list(size = diff(range(x))/50))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论