How to create second axes for both x and y variables by grouping in a ggplot2 heatmap

I will like to show the groups my variables belong to, on a ggplot2 heatmap, such as is shown with this barplot.

My section of the dataset is below with the code

library(reshape2)
library(ggplot)
Var1 = c("X119_172", "X115_172", "X124_178", "X120_175", "X114_172", "X128_170", "X141_337", "X141_338", "X142_341", "X112_363", "X141_341", "X112_362")
Y_tm = rep("TM1_TM2", 12)
X_tm = c("TM1_TM2", "TM1_TM2", "TM1_TM2", "TM1_TM2", "TM1_TM2", "TM1_TM2", "TM1_TM6", "TM1_TM6", "TM1_TM6", "TM1_TM6", "TM1_TM6", "TM1_TM6")
value = c(0.77,  0.79, -0.62,  0.76,  0.68, -0.44, -0.52, -0.31, -0.38,  0.68, -0.35,  0.65)
Var2 = rep("X112_176", 12)
df = data.frame(Var1, Var2, value, X_tm, Y_tm)
df.matrix = ggplot(data = df, aes(x=Var1, y=Var2, fill=value)) + geom_tile()
df.matrix + scale_fill_gradient2(low = 'blue', high = 'red', mid = 'white', midpoint = 0, limit = c(-1,1), space = 'Lab', name='Scale') + theme(axis.title.x = element_blank(), axis.title.y = element_blank(), axis.ticks.x = element_blank(), axis.ticks.y = element_blank(), legend.justification = c(1,0), legend.position = c(0.6, 0.7), legend.direction = 'horizontal') + guides(fill= guide_colorbar(title.position = 'top', title.hjust = 0.5))

How do I make the axis text to be only by the groups (X_tm for the x-axis, and Y_tm for the y-axis)?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.