I have this dummy dataset:
dat <- data.frame(ID = c(1:8),
col1=c("A B",NA,NA,"B C","A C","A",NA,"C"),
col2=c("A D","B G",NA,NA,NA,NA,"E","C E"),
col3=c("A A A A",NA,"B B C B B",NA,NA,"A D","D C","C E"),
col4=c(NA,NA,NA,"B A B",NA,NA,NA,"E"),
row.names = c("row1","row2","row3","row4","row5","row6","row7","row8"))
And I am trying to make a heatmap of this dataframe with the categorical variables A,B,C,D,E,G colored uniquely. Had there been only one value for one cell, it would be easy to plot a heatmap. This would be the code:
dat <- dat %>% gather(key = "variable", value = "value", col1:col4)
ggplot(dat3, aes(variable, ID)) + geom_tile(aes(fill = value))
But as there are more than one value and in some cells, the values are even repeating, it's difficult to code for it. To plot more than 2 variables in the same cell, I'm thinking of splitting the cell into 2 triangle, the upper triangle colored as per one value and the other being colored differently as per the 2nd value. Can anyone help on how to code for it?
In excel desired plot would look something like this raw image