如何在geom_tile ggplot中保留tile的顺序

时间:2015-10-30 06:29:37

标签: r ggplot2

我试图制作geom_tile图并且难以尝试保留图块的顺序。这是一个示例数据集

head(data2.2)
      wt_mt_up                                         GO ont
1285 10.692307                          proline transport  BP
784  10.319457        salicylic acid biosynthetic process  BP
743   9.550895               systemic acquired resistance  BP
1729  8.563280   response to endoplasmic reticulum stress  BP
841   7.910318 defense response, incompatible interaction  BP
1823  7.765033              defense response to bacterium  BP

p2 <- ggplot(data2.2, aes(x=ont, y=GO, fill = wt_mt_up)) + 
      geom_tile() +
      scale_fill_gradient(legend_title, low="white", high="red") + theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 12)) + theme(axis.text.y = element_text(hjust = 1, size = 12))

p2

GO_plot

正如您在输出图中看到的那样,尽管GO =“脯氨酸运输”的最大值为10.692307,但它位于图中间的某处。其他人也一样。理想情况下,我希望它们从高值到低值叠加。

1 个答案:

答案 0 :(得分:3)

以上是上述问题的答案

p2 <- ggplot(data2.2, aes(x=ont, y=reorder(GO, wt_mt_up), fill = wt_mt_up)) + 
      geom_tile() +
      scale_fill_gradient(legend_title, low="white", high="red") +        
      theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 12)) +  
      theme(axis.text.y = element_text(hjust = 1, size = 12))
p2