Heatmap in R (3 Examples) | Base R, ggplot2 & plotly Package | How to Create Heatmaps

preview_player
Показать описание
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
Рекомендации по теме
Комментарии
Автор

Thanks for the great walk-through! Many other videos go through so many unnecessary steps, but you kept it concise and still hit so many comparative points!

RUJedi
Автор

Thank you for details explaining. I have known many kind of heatmap code.

einandaraung
Автор

really thank you for providing us remakable video

meseretmuche
Автор

This was very useful. thank you so much :)

elizabeth
Автор

I did all the steps and finally the viewer doesn't shows the plot_ly heat map... What should I do... And also I wanted to change the direction and overlapping x1 axis value for that what I have to do

rajaranidreamhome
Автор

Hi,

How can I use the row names from my file on the heatmap, currently it just says Row 1 all the way to Row 6 rather than the actual title?

heatmap(as.matrix(my data[, -1]))

This is the script I'm using, its the only way I could get it to work as its not a matrix apparently. Thank you

YummiestOrphan
Автор

If we copy your script and apply on our original data not on the save data by R then it's gives numeric error. Please tell me how to resolve numeric error issues. Thanks in anticipation.💐

RjAtifAyub
Автор

Thank you for all your videos. They're all very useful. Can you explain, please, how to make a spectral analysis by R in one of your videos? Periodogram or something else. Or maybe you've already done it...

Apsaalooke
Автор

What if you wanted more colors than 100 in example 3, how would you do that?

samemery
Автор

Great explanation. I have two groups (A and B). How can I get a heat map? For example, data<- data.frame(groups=c("A", "A", "A", "B", "B", "B"), E1= c(2, 3, 4, 5, 6, 7), E2= c(3, 5, 6, 8, 9, 7) ).

infotainment
Автор

How to creat heat map analysis when i have more then 2 data (i mean to say i have 2 experiment data and i want to creat both data show in one heat map Graph )

muhammadusmanali
Автор

Thank you for a detailed tutorial!!
I have a question, what are the codes for inserting colour key on the heatmap?

shandrymmasetshaba
Автор

Great video!!! But when i do create some heatmap using ggplot2, how can i set the values? (in your video for example, the heatmap values were setted as -20 to +20). Thanks!!

hugooliveira
Автор

thank you for the tutorial! but how can I create a heatmap with more than 2 colors using the ggplot2 package?

lihe
Автор

I want to change color for each columns how I do, because for some column I need positive value or some negative

hr_foods
Автор

Have made heatmap successfully except I have 68 labels in data instead I am getting only 34 row labels in the heatmap. Heatmap is perfect but this number of row labels are half

ankitkachchhi