我正在尝试根据示例代码here在ggplot2中使用geom_tile
制作标准化读取丰度值的热图。我当前的代码生成了所需范围的热图,但由于某些原因,热图中只显示了7个范围中的4个,我无法弄清楚问题是什么。当我在原始链接中跟踪示例时,它工作正常,所以我必须在代码中更改错误。任何人都可以帮我识别我的代码中导致此错误的错误吗?
我想要有以下配色方案:
-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
这是我的代码:
#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"))
这里是我的数据预览(实际数据有228行,包含6个不同实验中38个ID的每百万值读数):
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]
以下是我从上述数据得到的情节:
答案 0 :(得分:0)
我想我想出来了,如果我从scale_fill_manual中取出break参数,那么所有的图例都会显示出来:
ggplot(data = df, aes(x = label, y = X2)) + geom_tile(aes(fill=value1), colour= "black") + scale_fill_manual(values =c("white","yellow","orange","darkorange2","red","red3","red4"))