I'm trying to prepare a figure for print. The panel of the ggplot will have a dark background and the image itself will be set against a dark background, so the whitespace surrounding the figure needs to be managed. However, I can't seem to remove some visible whitespace on the left side of the plot which I assume is some type of axes padding as it does not appear on an empty ggplot (which doesn't have axes).
Here's what I'm referring to.
And to show you that it seems to stem from the axes, here's a picture without the caption, to show that it's also at the bottom for the x-axis.
A Reprex follows:
library(tidyverse)
p <- ggplot(data = mtcars, aes(x = disp, y = mpg)) +
geom_line(color = "red")
q <- p +
labs(caption = "My Chart Thing") +
theme_minimal() +
theme(legend.position = "bottom", panel.background = element_rect(fill = "#44475a", color = "#44475a"),
panel.grid = element_blank(),
text = element_text(color = "#8be9fd"),
axis.line=element_blank(),
axis.text = element_blank(),
axis.ticks=element_blank(),
axis.title = element_blank(),
panel.border=element_blank(),
panel.spacing = unit(0, "cm"),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
plot.margin = margin(0, 0, 0, 0, "cm"),
plot.caption = element_text(hjust=0.02, size=rel(2.2), color = "#44475a")) +
guides(color = FALSE, linetype = FALSE, fill = FALSE)
q
z <- ggplot() +
labs(caption = "My Chart Thing") +
theme_minimal() +
theme(legend.position = "bottom", panel.background = element_rect(fill = "#44475a", color = "#44475a"),
panel.grid = element_line(color = "#282a36"),
text = element_text(color = "#8be9fd"),
axis.line=element_blank(),
axis.text = element_blank(),
axis.ticks=element_blank(),
axis.title = element_blank(),
panel.border=element_blank(),
panel.spacing = unit(0, "cm"),
panel.grid.major=element_blank(),
panel.grid.minor=element_blank(),
plot.margin = margin(0, 0, 0, 0, "cm"),
plot.caption = element_text(hjust=0.02, size=rel(2.2), color = "#44475a")) +
guides(color = FALSE, linetype = FALSE, fill = FALSE)
z
Created on 2019-12-17 by the reprex package (v0.3.0)
Is there some theme specification I'm missing which handles this? Many thanks in advance.