How can I increase the space between the bars in a bar plot in ggplot2 ?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can always play with the
widthparameter, as shown below:Compare with the following other settings for
width:So far, so good. Now, suppose we have two factors. In case you would like to play with evenly spaced juxtaposed bars (like when using
spacetogether withbeside=TRUEinbarplot()), it’s not so easy usinggeom_bar(position="dodge"): you can change bar width, but not add space in between adjacent bars (and I didn’t find a convenient solution on Google). I ended up with something like that:The vector used for the $x$-axis is “injected” in the data.frame, so that so you change the outer spacing if you want, while
widthallows to control for inner spacing. Labels for the $x$-axis might be enhanced by usingscale_x_discrete().