Reputation: 8454
I have the simple dataframe d
below and I want to creata a histogram based on the frequency of its values. I am trying to set the inital value as 0
and then display the values in the x-axis by 5
but neither of those seems to work since values begin from 1
and then display 8
. I would prefer a clear plotly solution on this as first choice, without ggplot()
interference.
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))
Upvotes: 0
Views: 449
Reputation: 281
Something like the below approaches it a little differently but I think the result is what you are looking for.
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)
Upvotes: 1