I would approach this problem in the following way: first, convert the column names in your count matrix to sample names; second, generate a second data.frame with the factors you want to divide the plot by. Then, you can use the annotation_col
parameter to divide the plot in the way you want.
matrix <- structure(list(S1 = c(0, 0, 0.04, 0.001, 0.31, 0),
S2 = c(0, 0, 0, 4e-04, 0, 0),
S3 = c(0, 0, 0, 0, 0.02, 0),
S4 = c(0.103, 0, 0, 0, 0.038, 0),
S5 = c(0.244, 0.1354, 0.0874, 0.01, 0.003, 0.008),
S6 = c(0.001, 0.094, 0.139, 0.016, 0.03, 0.001)),
class = “data.frame”,
row.names = c(“OTU1”, “OTU2”, “OTU3”, “OTU4”, “OTU5”, “OTU6”))
environment <- structure(list(category = structure(c(1L, 1L, 3L, 3L, 2L, 2L),
.Label = c(“Leaf”, “Root”, “Soil”), class = “factor”),
season = structure(c(1L, 1L, 1L, 2L, 2L, 1L),
.Label = c(“dry”, “wet”), class = “factor”)),
class = “data.frame”,
row.names = c(“S1”, “S2”, “S3”, “S4”, “S5”, “S6”))
pheatmap(matrix,
annotation_col = environment,
cluster_rows = TRUE,
cluster_cols = FALSE,
show_colnames = TRUE,
cluster_distance_rows = “euclidean”,
clustering_method = “complete”,
fontsize = 10,
fontsize_row = 10)
Read more here: Source link