0

Is there a way to customize the distance between the x axis factor and the plot in ggplot?

library(ggplot2)
female <- ggplot(gender_and_age[(1:7),], aes(x = gender_and_age, y = count)) + geom_bar(stat = 'identity', fill = 'lightpink1')+ theme_light() + geom_text(aes(label = sprintf("%.2f%%", count/sum(count) * 100)),  vjust = -.5)

return this plot female

I want to set a space between "13-17","18-24","25-34", "35-44", "45-45","55-64","65+" and the plot

This is what I want

enter image description here

pogibas
  • 27,303
  • 19
  • 84
  • 117
  • @ycw I think that the OP is not asking about moving the label `gender_and_age` but rather separating the x-axis ticks from the histogram. He needs to adjust lower ylim. – G5W Sep 17 '17 at 11:25
  • @G5W I could be wrong. But based on the last sentence of the post, it looks like the OP wants more space between "all the x-axis labels" and "the plot", which is the link I am referencing is about. Please provide a solution for the OP related to the adjustment of ylim, or we can wait for OP to clarify. – www Sep 17 '17 at 11:33
  • that's what I want exactly @G5W https://scontent-cai1-1.xx.fbcdn.net/v/t1.0-0/p173x172/21751356_1126278870837197_1879416366894612147_n.jpg?oh=4a32a76ef01611b40d5a304b345287bb&oe=5A4164CB – norhan abdelaziz Sep 17 '17 at 11:52
  • You could get some space between the bars and the labels by adjusting `ylim` but that is not exactly what you are asking for. It would make the grid bigger. – G5W Sep 17 '17 at 11:54
  • 3
    @norhanabdelaziz ; using the link posted by ycw, you can do `p + theme(axis.text.x = element_text(margin=margin(t=20, r=0, l=0, b=0)))` : change `t` to suit – user20650 Sep 17 '17 at 13:13

0 Answers0