Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Margin adjustments when using ggplot's geom_tile()

Tags:

r

ggplot2

From the documentation for ggplot2's geom_tile() function, we have the following simple plot: alt text

# Generate data 
pp <- function (n,r=4) { 
    x <- seq(-r*pi, r*pi, len=n) 
    df <- expand.grid(x=x, y=x) 
    df$r <- sqrt(df$x^2 + df$y^2) 
    df$z <- cos(df$r^2)*exp(-df$r/6) 
    df 
} 
p <- ggplot(pp(20), aes(x=x,y=y)) 

p + geom_tile()

How do I remove the margins that border the tile? I have dug through this script on polishing plots for some hints to no avail. I have found how to remove the background panels using opts(panel.background=theme_blank()), but not how to change the margin size.

like image 933
Christopher DuBois Avatar asked May 10 '10 19:05

Christopher DuBois


1 Answers

Try this:

p + geom_tile() + 
    scale_x_continuous(expand=c(0,0)) + 
    scale_y_continuous(expand=c(0,0))
like image 168
rcs Avatar answered Nov 09 '22 05:11

rcs