My question is similar to this link. In this example, 1 is coded for mutation, 0 for wildtype and NA for not available. My dataframe is set up identically, however it may contain two or more types of mutation per gene. I would like to generate a similar figure, except in cases where a gene has two types of mutations, I would like the square to be cut in half and both types of mutations to be colored in, similar to this example. Currently if a gene in a subject has two mutations, the second mutation fill over writes the first. Thank you in advance for taking out the time to help.
dat <- expand.grid(gene=1:10, subj=1:50)
dat$mut <- as.factor(sample(c(rep(0,300),rep(1,200)),500))
dat$mut[sample(500,300)] <- NA
dat[501,] = c(10,50,1) #included from comment below
ggplot(dat, aes(x=subj, y=gene, fill=mut)) +
geom_raster() +
scale_fill_manual(values = c("#8D1E0B","#323D8D"), na.value="#FFFFFF") +
scale_x_discrete("Subject") +
scale_y_continuous(breaks=1:10,
labels=c("D0","D1","D2","D3","D4","D5","D6","D7","D8","D9")) +
guides(fill=FALSE) +
theme(
axis.ticks.x=element_blank(), axis.ticks.y=element_blank(),
axis.text.x=element_blank(), axis.text.y=element_text(colour="#000000"),
axis.title.x=element_text(face="bold"), axis.title.y=element_blank(),
panel.grid.major.x=element_blank(), panel.grid.major.y=element_blank(),
panel.grid.minor.x=element_blank(), panel.grid.minor.y=element_blank(),
panel.background=element_rect(fill="#ffffff")
)