2
ggplot(scount_all, aes(x=classes, y=frequency, group=seasons,fill=seasons)) +
  scale_fill_manual(name = "Seasons",values=bwPalette(4))+
  geom_bar(colour="black",stat="identity", position="dodge")+
  geom_text(aes(ymax=frequency,label = paste(sprintf("%s", frequency)),
                hjust= 0.5,vjust=-2,group=seasons),
            size = 2, position = position_dodge(width=.9)) +
  theme_bw()+
  theme(legend.key = element_rect(colour = "black")) +
  guides(fill = guide_legend(override.aes = list(colour = NULL)))

And this is the figure I get

enter image description here

As you can see, the numbers are overlapping in some, and invisible in others. How can I increase the width of the bars by a little bit so that the numbers are visible? Five digit is the largest number in my data.

maximusyoda
  • 595
  • 3
  • 8
  • 17
  • 1
    Why not to rotate the text to the vertical direction ...`geom_text(angle = 90,...)`? – agstudy Sep 16 '14 at 19:15
  • The answer given here may be helpful http://stackoverflow.com/questions/12040245/how-to-increase-the-space-between-the-bars-in-a-bar-plot-in-ggplot2 – Meso Sep 16 '14 at 19:17
  • last resort. Affects readability. If I don't get a solution, I'll make it vertical. – maximusyoda Sep 16 '14 at 19:17
  • @Meso I saw that solution. Opts is deprecated. And in theme the binwidth works with histogram. I don't know how to make it work with geom_bar or theme directly – maximusyoda Sep 16 '14 at 19:18
  • Have you tried to read [**the help text for `geom_bar`**](http://docs.ggplot2.org/0.9.3/geom_bar.html)? See the second example. – Henrik Sep 16 '14 at 19:21
  • I used width. Thanks! But now, I am not able to center it....Any easy way to center text? – maximusyoda Sep 16 '14 at 19:36
  • Please _show some effort_ and [**search**](http://stackoverflow.com/search?q=[r]+geom_bar+geom_text+center) before asking. Several relevant answers among the hits. – Henrik Sep 16 '14 at 19:41
  • I don't know man. I have used hjust, vjust,size etc to adjust it, which should show that I'm not putting lazy questions on SO. Obviously, I have missed an answer. And I thank you for showing me the right way. Sometimes people miss basic answers. Not asking for the address to heaven. No reason to be condescending to new users by implying I didn't try myself. The self-righteousness in SO is too damn high. – maximusyoda Sep 16 '14 at 19:52
  • could you provide the data you are working with? – Paulo E. Cardoso Sep 16 '14 at 20:24
  • Hi @PauloCardoso In a little bit. Thank you. – maximusyoda Sep 16 '14 at 20:41

1 Answers1

7

ggplot2 allows you to adjust the width like this:

 + geom_bar(stat = "identity", width = 1)

The width is, I think, from 0 to 1 where 1 means that the bars take up 100% of the available space and there's no space in between. If you like the amount of white space between them but want them wider, then just make your plot dimensions overall wider.

shirewoman2
  • 1,842
  • 4
  • 19
  • 31