0

I have a graph that has many categorical variables on the x axis, but they are all squished together. Using ggplot2 how can I wrap that text and/or lengthen the graph so it is readable? thanks!

My code:

ggplot(bureau_status_df3, aes(fill=Var1, y=Freq, x=Var2)) + 
  geom_bar(position='fill', stat='identity') + scale_fill_hue(h = c(100, 420))+
    ggtitle("Status by Violation Bureau") + 
 theme_minimal()

my graph photo

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Rachael G
  • 1
  • 1
  • 1
    If you want to make the graph wider, just resize the window to it's wider. If you are saving the image with `ggsave`, just choose a larger `width=` value. Options for wrapping here: https://stackoverflow.com/questions/21878974/wrap-long-axis-labels-via-labeller-label-wrap-in-ggplot2. You could aslo use `coord_flipped()` so the labels go go on the y axis and you have more room. – MrFlick Aug 23 '22 at 14:40
  • Horizontal boxplots as MrFlick explained. You could try to rotate the x axis' tick marks as a lesser alternative. – Bernhard Aug 23 '22 at 14:53
  • Or there's always something like `+ theme(axis.text.x = element_text(angle = 35, hjust = 1, vjust = 1))` to rotate the text. Sometimes you may also need to adjust the plot margin with the `plot.margin` argument of `theme()` as well. – Gregor Thomas Aug 23 '22 at 15:10
  • 1
    Great. I'll compare rotating vs changing the axes, Gregor- your code works great. Thank you! – Rachael G Aug 23 '22 at 15:14

0 Answers0