I am trying to get multiple heatmaps using facet_wrap and geom_tile function, I have 1000 samples.
My objective is to obtain a heatmap for each Parent_Gene that include the "Condition" in the “X” axis, "response value" as a “fill” and the Genes belonging to the same Parent_Gene in the “Y” axis.
ID | sl | condition | Gene | Response_Value | Parent_Gene |
---|---|---|---|---|---|
1 | S1 | disease1 | GeneKPN1 | 2.749526 | GeneKPN |
2 | S2 | disease2 | GeneKPN2 | 6.606618 | GeneKPN |
3 | S3 | disease1 | GeneBKJH1 | 4.697644 | GeneBKJH |
Here is my script so far. My issue is that I just want the genes belonging to the corresponding parent_gene depicted in each heatmap and not all the genes every time.
my_data <- read.csv("my_data.csv")
my_data$Parent_Gene <- gsub("([A-Z)]+)\\d+.*","\\1", my_data $Gene)
library(tidyverse)
gg<- ggplot(my_data, aes(x=Condition, y=Gene, fill= Response_Value))+
geom_tile(color="white", size=0.1)+
scale_fill_viridis(name="response levels")
gg + coord_equal()
gg + facet_wrap(~Parent_Gene, ncol=2)
gg <- gg + labs(x=NULL, y=NULL, title="Comparative response levels")