I'm trying to create a bar chart in ggplot2 showing a histogram for a large data set.
ggplot(data = score.data, aes(x = score)) + geom_bar(binwidth = .25, width=.9)
My employer's graphic design policy is to have a small amount of separation between bars. But no matter what I set the width parameter to, the plot is generated with no space between bars whatsoever. Is there a different parameter I should be using to accomplish this?
EDIT: Following jeremycg's suggestion in the comments, I've included some of my data.
score <- c(6.25, 4.75, 6, 1.5, 6, 5, 6, 2.75, 6, 2.5, 5.25, 6, 3.75, 6,
6.25, 5, 6.75, 2, 2.75, 3.25, 5.625, 6.5, 4, 5, 3)
I'd convert it to a factor, except I want to show bins of size .25 - there are a small number of values between the quarters (as you can see above, where one value is 5.625). And stat_bin
only works for data that ggplot thinks is continuous.
dput(head(score.data))
. If you have integers as yourscore
, you could tryggplot(data = score.data, aes(x = factor(score))) + geom_bar()
– jeremycg