Wednesday, January 25, 2023

Heatmap in R









1. Create dataset

letters <- LETTERS[1:20]
animal_names <- c("Canidae","Felidae","Cat","Cattle",
                  "Dog","Donkey","Goat","Guinea pig",
                  "Horse","Pig","Rabbit","Badger",
                  "Bald eagle","Bandicoot","Barnacle",
                  "Bass","Bat","Bear","Beaver","Bedbug",
                  "Bee","Beetle")


2, Join the variable

plt <- ggplot(data,aes( X, Y,fill=count))
plt <- plt + geom_tile()
plt

3. Plot the heatmap

data <-cbind(Treatment,made,value) 

data <-data.frame(data) 


4. plot heatmap

plt <- ggplot(data,aes( X, Y,fill=count))
plt <- plt + geom_tile()
plt

5. Applying color

plt <- plt + theme_minimal()
plt 

5. setting gradient color as red and white

plt <- plt + scale_fill_gradient(low="white", high="red")
plt

5. title and sub-title

plt <- plt + labs(title = "Heatmap")
plt <- plt + labs(subtitle = "A simple heatmap using geom_tile()")
plt

5. Setting x and y labels

plt <- plt + labs(x ="Alphabets", y ="Random column names")
plt
Reference:Create Heatmap in R - GeeksforGeeks

No comments:

Post a Comment