Plotly X Axis Intervals

I need to create plot with plotly but I want to determine x axis breaks intervals myself.

I need someting like this.

enter image description here

I searched a lot and couldn't find an answer.

Thanks for helping.

Upvotes: 1

Views: 740

Answers (1)

vestland
vestland

Reputation: 61094

It's not the x-axis itself that's the issue here, but rather the number of bins. You can adjust that using nbinsx like:

plot_ly(x, type = "histogram", nbinsx = 20)

Example with some sample data after comment:

Code 1:

library(plotly)
set.seed(1)
numbers <- rnorm(100,20, 20)
p1 <- plot_ly(x = ~numbers,type = "histogram")
p1

Plot 1:

enter image description here

Code 2:

p2 <- plot_ly(x = ~numbers,type = "histogram", nbinsx=20)
p2

Plot 2:

enter image description here

Code 2:

p3 <- plot_ly(x = ~numbers,type = "histogram", nbinsx=20)
p3

Plot 3:

enter image description here

code 3:

p3 <- plot_ly(x = ~numbers,type = "histogram", nbinsx=5)
p3

Upvotes: 1

Related Questions