I want to make the background colored with one variable (RPKM), since most value were range from 1 to 40, and the biggest value is 800, the final picture was almost blue, make it impossible to distinguish approximate value such as 2 and 3. In pheatmap
, I could solve this problem by using breaks that assign more colors for 1 to 40, and make value bigger than 100 with same color. I had tried to do the same thing with scale_fill_gradientn
, scale_color_brewer
, but without success, could some one help me?
\1. My data is like this:
head(data3, n=14)
Gene_H Index RPKM Usage Species Dif_index
1 BORCS5 1 NA 0.9300 H 1
2 BORCS5 1 4.663070 0.4200 R 1
3 BORCS5 2 NA 1.0000 H NA
4 BORCS5 2 4.663070 1.0000 R NA
5 BORCS5 3 NA 1.0000 H NA
6 BORCS5 3 4.663070 0.8700 R NA
7 BORCS5 4 NA 1.0000 H NA
8 BORCS5 4 4.663070 1.0000 R NA
9 ALKBH3 1 0.000000 1.0000 H 1
10 ALKBH3 1 5.330331 0.1400 R 1
11 ALKBH3 2 0.000000 1.0000 H NA
12 ALKBH3 2 5.330331 1.0000 R NA
13 ALKBH3 3 0.000000 1.0000 H NA
14 ALKBH3 3 5.330331 1.0000 R NA
\2. My code is:
ggplot(data3)+geom_point(aes(x=Index, y=Usage))+ylim(0,1)+
geom_point(aes(x=Dif_index, y=Usage), color="red")+facet_wrap(Gene_H~Species, ncol=2)+
theme(strip.text.x = element_blank(), axis.text.y=element_blank(), panel.grid.major=element_blank(),
panel.grid.minor=element_blank(), panel.margin=unit(0.1, "lines"))+
geom_rect(aes(fill=RPKM), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)
\4. I had tried with cut
and scale_fill_brewer
, but it output error that I failed to solve
geom_rect(aes(fill=cut(RPKM, c(seq(0,40,by=0.5),seq(41,800,by=20)))), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)+
scale_fill_brewer(type="seq", palette="YlGn")
Warning messages:
1: In RColorBrewer::brewer.pal(n, pal) :
n too large, allowed maximum for palette YlGn is 9
Returning the palette you asked for with that many colors
2: Removed 5 rows containing missing values (geom_point).
3: Removed 122 rows containing missing values (geom_point).
4: In RColorBrewer::brewer.pal(n, pal) :
n too large, allowed maximum for palette YlGn is 9
Returning the palette you asked for with that many colors
\5. With scale_color_discrete
, it would divide the color to different kind as follow, but I want the color to change gradient.
geom_rect(aes(fill=cut(RPKM, c(seq(0,40,by=0.5),seq(41,800,by=20)))), xmin=-Inf, xmax=Inf, ymin=-Inf, ymax=Inf)+
scale_color_discrete()