Export from ggplot2 dark theme with no white border?

Viewed 1172

I want my plots to have dark background to match a slide theme that I am using. I have everything the way I want it, but I cannot figure out how to remove the white border from the overall image. I am looking for something like theme(plot.border = element_line(color = "#1e1e1e")) but there does not seem to be a plot.border attribute.

No matter what I do to my export size, it always includes it. I never even knew there was a border in the past because I was always using white on white, but now it is revealed!

I've tried a bunch of stuff and cannot get rid of that stupid line, and I really don't want to have to crop my images to remove, or take manual screenshots from RStudio :)

Here's the code, and see below for the image it's creating...

p<- ggplot(barchart.data, aes(x=x_labs, y=ests, fill=l_labs)) + 
  geom_bar(stat="identity", color=fill_colors, position=position_dodge(), fill=fill_colors) +
  geom_text(aes(y=ests+perrs+0.02, label=sprintf("%1.1f%%", 100*ests)), vjust=0.5, hjust=0, size=bar.font, color="white") +
  geom_errorbar(aes(ymin=ests-nerrs, ymax=ests+perrs), width=.2, position=position_dodge(.9), color="white", size=0.25) + 
  labs(title=chtit, x=xaxis, y = yaxis) + 
  theme_classic() + 
  scale_y_continuous(limits = c(0,1.1), breaks=c(0, 0.2, 0.4, 0.6, 0.8, 1)) + 
  theme(legend.position="none", legend.text = element_text(color = "white")) +
  theme(title = element_text(colour = "white")) +
  theme(axis.text = element_text(size=12, color = "white"), axis.line = element_line(color = "white")) +
  theme(axis.title = element_text(size=12, color = "white")) +
  coord_flip() +
  theme(panel.grid.major.x = element_line(colour = "white",size=0.25))+
  theme(aspect.ratio = 1) +
  theme(panel.background = element_rect(fill = "#1e1e1e")) +
  theme(plot.background = element_rect(fill = "#1e1e1e")) +
  guides(fill = guide_legend(reverse = TRUE))
  return(p)

screenshot of plot with unwanted white borderw

0 Answers
Related