Lolivano
Lolivano

Reputation: 152

Histogram in R Plotly: set number of 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.

Upvotes: 0

Views: 259

Answers (2)

Lolivano
Lolivano

Reputation: 152

I found a custom solution with the xaxis.size option

plot_ly(x = ~x, type = "histogram", xaxis = list(size = diff(range(x))/50))

Upvotes: 1

nimliug
nimliug

Reputation: 413

Try this :

library(plotly)
plot_ly(x = ~x, type = "histogram", nbinsx = 30)

Upvotes: 1

Related Questions