ggplot2 make missing value in geom_tile not blank

后端 未结 4 1251
孤独总比滥情好
孤独总比滥情好 2020-12-10 11:08

In the geom_tile() layer in the ggplot2 data visualization package for R, when a cell contains no data it is not drawn. E.g. http://docs.ggplot2.org/current/geo

4条回答
  •  萌比男神i
    2020-12-10 11:27

    For posterity, here is the right solution compatible with ggplot2 version 1.9.3

    + theme(panel.background=element_rect(fill="blue", colour="blue")
    
    • In joran's answer, the plot.background is the whole plot including the title and legend etc. The panel.background is the area where the data appears.

    • In the latest version of ggplot2, opts has been replaced with theme and theme_rect has been replaced with element_rect.

    • In specifying element_rect, color is the boundary of the rectangle while fill is the interior of the rectangle.

    I had originally used,

    + geom_rect(aes(xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf), fill="blue")
    

    but when adding geom_raster rather than geom_tile over the the background and generate pdf output, pdf viewers had a very hard time rendering the plot, using substantially more cpu cycles and memory.

提交回复
热议问题