From the following dataframe df:
df <- data.frame(Date=1:5,
Cat1=c(1,0,1,0,0),
Cat2=c(1,1,1,0,0),
Cat3=c(0,1,1,0,1),
Cat4=c(0,0,1,1,0),
Mask=c(0,1,1,0,0))
df <- tidyr::pivot_longer(df, -1)
A tile plot is plotted as follows:
ggplot(df%>%filter(name!="Mask"),
aes(x = Date, y = factor(name, levels = rev(unique(name))),
fill = as.factor(value))) +
geom_tile(color = "black") +
scale_fill_manual(values = c("white", "grey50")) +
theme_void() +
theme(legend.position = "none",
axis.text = element_text(size = 15),
axis.title.x = element_text(size = 15),
plot.margin = margin(20, 20, 20, 20))
with the following output:
In ggplot, How it is possible to implement a texture by using the column Mask==1 in order to fill the Date?


