Losing the grey margin padding in a ggplot

2019-02-02 09:42发布

问题:

A would like to plot geom_tile() without displaying the surrounding grey frame. Example:

library(ggplot2)
p <- ggplot(melt(volcano), aes(x = X1, y = X2, z = value,fill = value)) + geom_tile() 
print(p)

Produces the figure below, which would look better had not the theme background framed the heatmap proper. I imaging the padding is the same 4% as in base graphics. It's good to have it most of the time, but not always.

I assume the same solution to this problem could be applied to other geoms as well.

回答1:

just do print(p1 + scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0))) and that will get rid of the gray space around