how to order column by a different column value r

Viewed 24

I created heatmap with ggplot geom_tile(). For some reason the colors in the heatmap are not sorted as the values in column 'value' according to 'GFP_wide' in the variable column, (event that the values are already sorted). So my question is how do I make my heat map be sorted according to the variable GFP_wide? Thank you in advance!

I have the following data set:

GFP_long<-data.frame(Entrez.Symbol<-c("TRIP11","SIN3B","SF3B1","PSMD14","RAD51","BARD1", 
                                 "BRCA1","BRCA1","U5200KD","SETD5","TRIP11","SIN3B",  
                                 "SF3B1","PSMD14","RAD51","BARD1","BRCA1","BRCA1",
                                 "U5200KD","SETD5"),
                     variable<-c("GFP_my","GFP_my","GFP_my","GFP_my","GFP_my","GFP_my","GFP_my",  
                           "GFP_my","GFP_my","GFP_my","GFP_wide","GFP_wide","GFP_wide","GFP_wide",
                            "GFP_wide","GFP_wide","GFP_wide","GFP_wide","GFP_wide","GFP_wide"),
                      value<-c(1.015,0.336,0.315,0.254,0.286,0.157,0.275,0.230,0.772,0.364,
                         0.020,0.055,0.071,0.102,0.109,0.139,0.146,0.146,0.151,0.179))

colnames(GFP_long)<-c("Entrez.Symbol","variable","value")

So it looks like this:

Entrez.Symbol variable value
1         TRIP11   GFP_my 1.015
2          SIN3B   GFP_my 0.336
3          SF3B1   GFP_my 0.315
4         PSMD14   GFP_my 0.254
5          RAD51   GFP_my 0.286
6          BARD1   GFP_my 0.157
7          BRCA1   GFP_my 0.275
8          BRCA1   GFP_my 0.230
9        U5200KD   GFP_my 0.772
10         SETD5   GFP_my 0.364
11        TRIP11 GFP_wide 0.020
12         SIN3B GFP_wide 0.055
13         SF3B1 GFP_wide 0.071
14        PSMD14 GFP_wide 0.102
15         RAD51 GFP_wide 0.109
16         BARD1 GFP_wide 0.139
17         BRCA1 GFP_wide 0.146
18         BRCA1 GFP_wide 0.146
19       U5200KD GFP_wide 0.151
20         SETD5 GFP_wide 0.179

My ggplot code:

ggplot(GFP_long, aes(x=Entrez.Symbol,y=variable,fill=value)) + 
  geom_tile(aes(fill = value))+
  scale_fill_gradient(low="red", high="green")

enter image description here

0 Answers
Related