If your data is a grid-like data, how about adding another geom_tile()
for NA by subset()
?
# 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
}
pp20 <- pp(20)[sample(20*20, size = 200),]
df_grid <- expand.grid(x = unique(pp20$x), y = unique(pp20$x))
df_merge <- merge(pp20, df_grid, by = c("x", "y"), all = TRUE)
# Missing values
ggplot(df_merge, aes(x = x, y = y)) +
geom_tile(data = subset(df_merge, !is.na(z)), aes(fill = z)) +
geom_tile(data = subset(df_merge, is.na(z)), aes(colour = NA),
linetype = 0, fill = "pink", alpha = 0.5)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…