R ggplot geom_tile without fill color

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

thank

+5
source share
2 answers

I think after the parameter alpha. Minimal example:

  • Create a graph with dummy data, where you set color(for the "border") and no fill:

    p <- ggplot(pp(20)[sample(20*20, size=200), ], aes(x = x, y = y, color = z))
    
  • Add geom_tile()c alphato the value zero:

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

    p + theme_bw() 
    

enter image description here

+12
source

If you only need outlines in the form of a single color, you can set fill = NAand then set na.valuetoNA

.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) 
+4
source

All Articles