# geom_bar and binwidth

Hi. I want to plot per vs the frequency of per; I want to count the frequencies, but I want to combine the binwidths of the per's. geom_bar does not support binwidth. What do you suggest? Thank you.

library(ggplot2)
t <- c(0,5,2,5,1,2,0,0,0,1,0,1,1,3)
c <- c(10,16,16,16,10,20,20,20,21,18,6,6,6,22)
per <- t/c
df <- data.frame(cbind(t,c,per))

ggplot(data = df, aes(x = per)) +
geom_bar(stat="count", binwidth=.05) +
xlab(seq(0,1,.1)) +
labs(title = "Frequency", x = "Percent Matches", y = "Frequency")

Could you explain more what this would mean?

As it stands the graph gives me every value of per on the horizontal axis. I would like to combine say 1 <= per <1.05, 1.051 <= per <1.10, etc. I thought binwidth was the command for this.

`geom_bar()` doesn't has a `binwidth` argument because it doesn't calculate bins like `geom_histogram()` but it has the `width` argument that I think you can use for what you are trying to do (if I'm understanding you correctly).

``````library(ggplot2)
t <- c(0,5,2,5,1,2,0,0,0,1,0,1,1,3)
c <- c(10,16,16,16,10,20,20,20,21,18,6,6,6,22)
per <- t/c
df <- data.frame(cbind(t,c,per))

ggplot(data = df, aes(x = per)) +
geom_bar(stat="count", width=.05) +
xlab(seq(0,1,.1)) +
labs(title = "Frequency", x = "Percent Matches", y = "Frequency")
`````` Created on 2021-05-13 by the reprex package (v2.0.0)

Andresrcs, that is what I needed. Thank you.

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.