我正在尝试以 pivot_long 形式绘制数据,以使用 geom_tile 呈现为热图。但是,我在订购图中的瓷砖时遇到了麻烦。
示例数据https://drive.google.com/file/d/1WIjbN9-xP-1Wgc2Nx3GlterV8XhtnGyu/view?usp=sharing
这是我生成的图:
问题是我想要 y 轴标签,也就是“Drug.dose”,在添加的组合的“无”部分中按数值从高到低排列(因子设置为无、I30、I300 ...... I300_V100)
我的绘图代码如下:通过在我的 y 轴上使用 reorder()(如何保留 geom_tile ggplot 中的图块顺序),它按组合中添加的所有内容从高到低排列,因此您可以看到我在none 是 TN 0.1,但由于 I30、I300 等中的所有零,它进入了图的底部。列表中还有其他不一致之处。
我如何仅通过添加组合的 none 部分来重新排序?
library(ggplot2)
m <- ggplot(data)+
geom_tile(aes(x=Combination, y=reorder(Drug.dose,Avg.percent), fill=Avg.percent))+
geom_text(aes(x=Combination, y=reorder(Drug.dose,Avg.percent), label=Avg.percent), size=3)+
scale_fill_gradientn(colors=pal)+
theme(legend.text = element_text(size=10, face="bold", color = "black"))+
theme(axis.text.x = element_text(size = 15, face="bold", color = "black")) +
theme(axis.text.y = element_text(size = 9, face="bold", color = "black")) +
theme(axis.title.x = element_text(size = 15, face="bold", color = "black", vjust = 3))+
theme(axis.title.y = element_text(size = 15, face="bold", color = "black", hjust = 0.5))+
theme(plot.title = element_text(size = 16))+
theme(strip.text.y = element_text(size = 10, face = "bold", color = "black"))+
scale_x_discrete(position ="top") +
xlab("Combination added")+
ylab("Treatments in the screen")+
ggtitle("Cluster 1 Enriched in TN response")
print(m)