# Annotation of heatmap
iriscor <- cor(t(iris[, 1:4]))
df <- data.frame(
x = as.vector(row(iriscor)),
y = as.vector(col(iriscor)),
value = as.vector(iriscor)
)
annotation <- data.frame(
z = seq_len(nrow(iris)),
Species = iris$Species,
Leaves = ifelse(iris$Species == "setosa", "Short", "Long")
)
ggplot(df, aes(x, y)) +
geom_raster(aes(fill = value)) +
geom_tile(data = annotation,
aes(x = z, y = -5, spec = Species), height = 5) +
geom_tile(data = annotation,
aes(y = z, x = -5, leav = Leaves), width = 5) +
scale_listed(
list(scale_fill_brewer(palette = "Set1", aesthetics = "spec"),
scale_fill_brewer(palette = "Dark2", aesthetics = "leav")),
replaces = c("fill", "fill")
)
Run the code above in your browser using DataLab