I created a heatmap of two conditions (Inoculated and Mock control) and two genotypes (Resistant and susceptible), so there are 4 treatments in the column and in the rows there are shared genes with normalized expression data. In the heatmap, my mock treatments from both genotypes are clustered together, while inoculated treatments are clustered together for both genotypes. I want to cluster one genotypes mock and inoculated treatment (side by side). How can I change the following code to get the desired results? TIA.
data <- read.csv("R&S_heatmap.csv")
rnames <- data[,1]
mat_data <- data.matrix(data[,2:ncol(data)])
rownames(mat_data) <- rnames
# creates a own color palette from red to green
my_palette <- colorRampPalette(c("white", "red", "green"))(n = 299)
# creates a 5 x 5 inch image
png("h2_default_clustering.png",
width = 5*250,
height = 5*250,
res = 300,
pointsize = 2)
row_distance = dist(mat_data, method = "manhattan")
row_cluster = hclust(row_distance, method = "ward.D")
col_distance = dist(t(mat_data), method = "manhattan")
col_cluster = hclust(col_distance, method = "ward.D")
heatmap.2(mat_data,
cellnote = mat_data,
main = "Gene Expression",
notecol = "black",
density.info = "none",
trace = "none",
margins = c(30,25),
col = my_palette,
Rowv = as.dendrogram(row_cluster),
Colv = as.dendrogram(col_cluster))