[R] Specifying the gap between "dodge'd" bins groups?

hadley wickham h.wickham at gmail.com
Mon Feb 2 18:10:22 CET 2009

Hi Jason,

On Mon, Feb 2, 2009 at 9:10 AM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
> I'm looking at ggplot-static\position_dodge.html
> For ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position="dodge") , is it possible to specify the spacing between the dodge'd bin groupings?
> That is, I would like for there to be a small separation (horizontal space) between the "Ideal" and the "Fair" bars on the plot.  That way the reader can get a better idea of when each bin ends and the other begins.
> I think this "horizontal spacing" naturally occurs for discrete data, but for continuous data as is shown in the second figure, the bins all seem to right beside each other.  It would be nice if a small space could be added.

You can do something like this:

ggplot(diamonds, aes(x=price, fill=cut)) +
geom_bar(position=position_dodge(width=400), binwidth=500)



More information about the R-help mailing list