Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R ggplot geom_tile without fill color

Tags:

r

ggplot2

I am trying to add a geom_tile layer to a plot without the filled color (just the outline). Is there a way to get a transparent tile where only the boundary is visible?

Thanks

like image 230
dabsingh Avatar asked Jun 04 '12 22:06

dabsingh


2 Answers

If you only want the outlines as a single colour you can set fill = NA, and then set the na.value to NA

.data <- cbind( 
           expand.grid(x = 1:10, y = 1:10), z = runif(100))[sample(1:100,75), ]



ggplot(.data, aes(x = x, y = y)) + theme_bw() + 
   geom_tile(fill = NA, color = 'black', na.value = NA) 
like image 26
mnel Avatar answered Sep 28 '22 03:09

mnel


I think you are after alpha parameter. Minimal example:

  1. Create a plot with dummy data where you set color (for "boundary") and no fill:

    p <- ggplot(pp(20)[sample(20*20, size=200), ], aes(x = x, y = y, color = z))
    
  2. Add geom_tile() with alpha set to zero:

    p <- geom_tile(alpha=0)
    
  3. Add theme_bw() as transparent tiles look lame with a dark gray background :)

    p + theme_bw() 
    

enter image description here

like image 112
daroczig Avatar answered Sep 28 '22 03:09

daroczig