【发布时间】:2022-08-18 00:40:58
【问题描述】:
在我的热图中,我想根据 Haul 1 中的百分比值(减少)来订购 Species。这是我当前的代码:
ggplot(data, aes(Haul, Species)) + geom_tile(aes(fill = Percent)) + scale_fill_gradient(low = \"white\", high = \"red\") + labs(fill = \"% Sites\")+ theme_bw()因此,物种顺序应该是 b、c、d、a,基于减少运输 1 中的百分比。我尝试使用 reorder(),但找不到基于运输 1 指定排序的方法。
ggplot(data, aes(Haul, reorder(Species, Percent))) + geom_tile(aes(fill = Percent)) + scale_fill_gradient(low = \"white\", high = \"red\") + labs(fill = \"% Sites\")+ theme_bw()我的数据框是这样设置的:
Species = rep(c(\"a\",\"b\",\"c\",\"d\"),3) Haul = rep(c(1,2,3),4) Percent = c(25,0,25,50,25,0,75,0,50,100,0,50) data = data.frame(Species, Haul, Percent)谢谢您的帮助!
伊莉丝