I have longitudinal categorical data that I’d like to visualize as a heatmap-like figure (see heatmap-like plot, but for categorical variables).
The study has three grouping levels: study participant, visit session, & calendar recall diary. A predominant category for each visit was established from the calendar data. For example, a participant might have recorded Category A on 28 of 30 days and Category B on 2 of 30 days; they would be categorized as predominantly Category A at the visit-level).
Occasionally, there are ties in the calendar data. I would like the heatmap to reflect these ties.
Here is some sample data to work with:
dat <- data.frame(person=factor(paste0("id#", 1:5),
levels =rev(paste0("id#", 1:5))),
matrix(sample(LETTERS[1:3], 15, T), ncol = 3))
dat <- dat %>% mutate(X2 = case_when(person=="id#3" ~ "A;B;C", TRUE ~ X2))
I would like my heatmap to reflect this similar to this example output from excel: