0

I am making a series of bar plot graphs in ggplot and for some reason am generating a space underneath the bottom part of the bar plots and the x-axis (see photo). Anyone got any ideas how to remove them? I've tried setting ylim() (R doesn't like that), as well as using limits=c() within scale_y_continuous() to no effect. Thanks for any insight!

Code below (changed the variable names slightly since the report I'm working on is still in progress):

ggplot(scd, aes(x=reorder(jurisdiction, - yvar), y=yvar)) +
  geom_bar(stat="identity",fill = "steelblue") + 
  theme(axis.text.x = element_text(angle = 45, hjust = 1), plot.title = element_text(hjust = 0.5),
        panel.background = element_rect(fill = "transparent"),
        plot.background = element_rect(fill = "transparent", color = NA), 
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.border = element_rect(colour="black",fill=NA)) + 
  labs(title = "Graph Example") +
  xlab("") + 
  ylab("Y-Axis") +
  scale_y_continuous(labels = c("0%","2%","4%","6%","8%","10%","12%","14%","16%","18%"), breaks=c(0,2,4,6,8,10,12,14,16,18))

Image of Graph

babybonobo
  • 89
  • 8
  • 2
    add `expand=expansion(0, 0)` to your `scale_y_continuous` – r2evans Feb 13 '22 at 19:42
  • 1
    add `+ scale_y_continuous(expand=c(0,0))` to your code. – TarJae Feb 13 '22 at 19:45
  • That worked great--thanks all. For some reason adding the expand() command shifted the limits of the graph, but that was easily fixed by adding limits=c() to the scale_y_continuous() command (adding this note in case anyone else finds this down the line). Thanks for the help! – babybonobo Feb 13 '22 at 20:42

0 Answers0