I want to draw a black border for every tile even though my data set is missing values for some combinations of x and y
library(dplyr)
set.seed(10)
df = data.frame(x=factor(sample(1:5, 5)), y=factor(sample(1:5, 5)), z=factor(sample(1:5, 5)))
ggplot(df, aes(x=x, y=y, fill=z)) + geom_tile(size=0.5, color="black")
It will work if I fill NA for the missing xy values. Also, the legend now shows the "NA" label, which I want to hide.
Is there a way to draw every tiles without filling in NA?
# fill in NA for missing combinations of x and y before drawing geom_tile
df2 = df %>% complete(x,y)
ggplot(df2, aes(x=x, y=y, fill=z)) + geom_tile(size=0.5, color="black") + scale_fill_brewer(palette="Set1", na.value="white")