I'm trying to remove the margins around a plot from ggplot2
. I'm working in a waffle
context, so the reproducible example below is in this form.
I have followed the answers provided in Remove Plot Margins in ggplot2, but am still getting a strange result. I run the following code, and make the background of the plot yellow to highlight the margins.
library("waffle")
parts <- data.frame(
names = LETTERS[1:4],
vals = c(80, 30, 20, 10)
)
waffle(parts, rows = 8, xlab = "Each Square = X",legend_pos = "bottom") +
guides(fill = guide_legend(ncol=1)) +
theme(plot.margin = margin(0,0,0,0,unit = "cm"),
legend.margin = margin(b=0,unit="cm"),
plot.background = element_rect(fill="yellow"))
ggsave(file = "graphs/test.jpg")
The following image is what I see when I paste the jpg into Word.
The yellow border confirms that the margins are correctly specified, but get the white border around the graph inside of the dashed line. Is there a way to avoid this?