I am trying to make a heatmap of normalized read abundance values with geom_tile
in ggplot2 based on the example code here. My current code produces a heatmap for the desired ranges, but for some reason only 4 out of the 7 ranges are shown in heatmap and I cannot figure out what is the issue. When I followed the example in the original link it worked fine, so I must have changed something incorrectly in my code. Can anyone please help me to identify the error in my code that is causing this?
I want to have the following color scheme:
-Inf < value <= 0 -> white
0 < value <=1 -> yellow
1< value <=10 -> orange
10< value <= 100 -> darkorange2
100< value <= 1000 -> red
1000 <value <= 10000 -> red3
10000 < value <= 32000 -> red4
Here is my code:
#re-order the labels in the order of appearance in the data frame
df$label <- factor(df$X1, as.character(df$X1))
# make the cuts
df$value1 <-cut(df$value,breaks=c(Inf,0,1,10,100,1000,10000,32000),right = T)
ggplot(data = df, aes(x = label, y = X2)) + geom_tile(aes(fill=value1), colour= "black") + scale_fill_manual(breaks=c("(-Inf,0]", "(0,1]", "(1,10]", "(10,100]", "(100,1000]", "(1000,10000]", "(10000,32000]"),values =c("white","yellow","orange","darkorange2","red","red3","red4"))
here is a preview of my data (actual data has 228 rows featuring reads per million values for 38 IDs in 6 different experiments):
head(df)
X1 X2 value label value1
1 merged_read_17785-997_aka_156_aka_21 RPM.MT1 91.783028 merged_read_17785-997_aka_156_aka_21 (10,100]
2 merged_read_133362-79_aka_156_aka_21 RPM.MT1 6.403467 merged_read_133362-79_aka_156_aka_21 (1,10]
3 merged_read_147828-69_aka_156_aka_20 RPM.MT1 4.268978 merged_read_147828-69_aka_156_aka_20 (1,10]
4 merged_read_162443-60_aka_156_aka_21 RPM.MT1 0.000000 merged_read_162443-60_aka_156_aka_21 (-Inf,0]
5 merged_read_262156-32_aka_156_aka_21 RPM.MT1 5.691971 merged_read_262156-32_aka_156_aka_21 (1,10]
6 merged_read_22905-759_aka_159_aka_21 RPM.MT1 140.164780 merged_read_22905-759_aka_159_aka_21 (100,1e+03]
And here is the plot that I get from the above data: