gpt4 book ai didi

r - 如何在 geom_tile ggplot 中保留图 block 的顺序

转载 作者:行者123 更新时间:2023-12-04 02:16:30 25 4
gpt4 key购买 nike

我正在尝试绘制 geom_tile 图,但在尝试保留图 block 顺序时遇到了困难。这是一个示例数据集

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 = "proline transport"的最大值为 10.692307,但它位于图的中间某处。其他人也一样。理想情况下,我希望它们从高值堆叠到低值。

最佳答案

以上问题的答案如下

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

关于r - 如何在 geom_tile ggplot 中保留图 block 的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33429993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com