How to remove all whitespace outside the plot


If I do a very simple ggplot as an example:

ggplot() +
    geom_rect(aes(xmin = 0, xmax = 1, ymin = 0, ymax = 1), fill = 'red', colour = NA) +
    coord_fixed(expand = 0)+
    theme(axis.ticks = element_blank(),
        axis.text = element_blank(),
        plot.margin = unit(c(0, 0, 0, 0), 'cm'),
        axis.title = element_blank())

So I've used the expand=0 option to coord_fixed and some theme settings to remove whitespace within and around the plot.

I seem to still have small amounts of space to the left and bottom of the plot. I'd like to reduce this to only the plot area (ie, in this simple example, just a red square). What haven't I removed?

Thanks in advance for your help.


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.