在R Plotly中的直方图:设置断点数量

huangapple go评论60阅读模式
英文:

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 &lt;- rnorm(1000)

Base R

hist(x,breaks = 50)

pltoly

library(plotly)
plot_ly(x = ~x, type = &quot;histogram&quot;) # 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 = &quot;histogram&quot;, 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 = &quot;histogram&quot;, xaxis = list(size = diff(range(x))/50))

huangapple
  • 本文由 发表于 2023年2月14日 00:01:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438332.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定