I am trying to create a heatmap with long form data to assess the correlation between membership of individual groups on specific outcome measure scores. I have converted the data to long format as shown. Some individuals may be members of more than 1 group.
df1 <- data.frame(ID = c(1, 2, 3, 4, 5),
Group1= c(1, 1, 0, 1, 0),
Group2 = c(1, 0, 1, 0, 0),
Measurement = c("Pain", "Pain", "Fatigue", "Stiffness", "Fatigue"),
Score = c(2, 3, 3, 2, 3))
df1
ID Group1 Group2 Measurement Score
1 1 1 1 Pain 2
2 2 1 0 Pain 3
3 3 0 1 Fatigue 3
4 4 1 0 Stiffness 2
5 5 0 0 Fatigue 3
I am sure this is a very basic question so my apologies. I would like to create a heatmap-like plot in ggplot with a colour scale representing the scores and x axis= Group memberships, y-axis = Measurements
Running the code below yields the following:
fig1 <- ggplot(df1, aes(x = c("Group1", "Group2"),
y = "Measurement",
fill = "Score")) + geom_tile()
Error: Aesthetics must be either length 1 or the same as the data (5): x
Is there a way of having a list of categorical variables on the y and x axes as described?
Thanks
