filmov
tv
Heatmap in R (3 Examples) | Base R, ggplot2 & plotly Package | How to Create Heatmaps
Показать описание
R code of this video:
##### Example data
data <- matrix(rnorm(100, 0, 10), nrow = 10, ncol = 10) # Create example data
colnames(data) <- paste0("col", 1:10) # Column names
rownames(data) <- paste0("row", 1:10) # Row names
##### Example 1
heatmap(data) # Apply heatmap function
##### Example 2
heatmap(data, Rowv = NA, Colv = NA) # Remove dendogram
##### Example 3
my_colors <- colorRampPalette(c("cyan", "deeppink3")) # Manual color range
heatmap(data, col = my_colors(100)) # Heatmap with manual colors
##### Example 4
library("reshape") # Load reshape package
data_melt <- melt(data) # Reorder data
library("ggplot2") # Load ggplot2 package
ggp <- ggplot(data_melt, aes(X1, X2)) + # Create heatmap with ggplot2
geom_tile(aes(fill = value))
ggp # Print heatmap
##### Example 5
ggp + scale_fill_gradient(low = "green", high = "black") # Manual colors of heatmap
##### Example 6
library("plotly") # Load plotly package
plot_ly(z = data, type = "heatmap") # Apply plot_ly function
##### Example 7
plot_ly(z = data, colorscale = "Greys", type = "heatmap") # Manual colors
##### Example data
data <- matrix(rnorm(100, 0, 10), nrow = 10, ncol = 10) # Create example data
colnames(data) <- paste0("col", 1:10) # Column names
rownames(data) <- paste0("row", 1:10) # Row names
##### Example 1
heatmap(data) # Apply heatmap function
##### Example 2
heatmap(data, Rowv = NA, Colv = NA) # Remove dendogram
##### Example 3
my_colors <- colorRampPalette(c("cyan", "deeppink3")) # Manual color range
heatmap(data, col = my_colors(100)) # Heatmap with manual colors
##### Example 4
library("reshape") # Load reshape package
data_melt <- melt(data) # Reorder data
library("ggplot2") # Load ggplot2 package
ggp <- ggplot(data_melt, aes(X1, X2)) + # Create heatmap with ggplot2
geom_tile(aes(fill = value))
ggp # Print heatmap
##### Example 5
ggp + scale_fill_gradient(low = "green", high = "black") # Manual colors of heatmap
##### Example 6
library("plotly") # Load plotly package
plot_ly(z = data, type = "heatmap") # Apply plot_ly function
##### Example 7
plot_ly(z = data, colorscale = "Greys", type = "heatmap") # Manual colors
Комментарии