0

I have these stacked bar charts and the labels are touching, causing it to be difficult to differentiate. I would prefer if I was able to separate them a bit, as the information is important to present clearly!

Here is the plot: enter image description here

Here is my code:

  ggplot(data =GraphData, aes(x = factor(Year), y = value, fill = variable)) +
  geom_bar(position = "fill", stat = 'identity') + 
  geom_col(position = position_stack(), color = "black")+
  geom_text(data = GraphPercent, aes(y = GraphData$value, label = paste0(percent(value),"(", GraphData$value, ")")), 
            position = position_stack(vjust = 0.5), size = 3.5, col = c("black"))+
  scale_fill_grey(start = 0.6, end = 1)+
  theme(panel.background = element_blank(),axis.line = element_line(colour = "black"),)+
  xlab("Year") +
  ylab("Cases") 

Thanks a lot I really appreciate it.

Aaron left Stack Overflow
  • 36,704
  • 7
  • 77
  • 142
Colin
  • 3
  • 4
  • 1
    Hi Colin, for us to be able to help, we'll need your data set too. Run `dput(GraphData)` and paste in the output. – Aaron left Stack Overflow Jun 19 '18 at 21:50
  • Your font has a specified size (set by `theme()` and depending on the size of your plot and also in the end your image/pdf size, the text will be closer or further apart. So several options: 1) increase your plot size, especially here the height (maybe using `coord_fixed()`). 2) Add an `angle` to your text 3) make your font smaller either with direct `theme()` call or by general change of `theme` options. As a sidenote, your plot is in general not really readable like that and this won't change with less overlapping fonts. – tjebo Jun 20 '18 at 08:24
  • I can't provide the dataset unfortunately, but I will try Tjebo's suggestions and let you know, thanks! – Colin Jun 20 '18 at 19:43
  • If you can't provide the dataset because of confidentiality or file size, you could recreate your problem using one of R's built in datasets, or simulate data that lets others reproduce your plot. See suggestions on how to simulate data [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Jan Boyer Jun 20 '18 at 20:50
  • Thanks for getting back to me, I will keep working on it and if it is not possible, I will make sure I do that. – Colin Aug 13 '18 at 17:35

0 Answers0