我正在尝试使用以下代码重新排序堆积条形图:
colnames(Device_Chemicals) <- c("Assays", "Active", "Inactive", "Not_Tested", "Total")
library(tidyverse)
Device_Chemicals<-gather(Device_Chemicals, key, Number_of_chemical, -Total, -Assays)
library(ggplot2)
ggplot(Device_Chemicals, aes(y=Number_of_chemical, x=Assays, fill=key)) +
geom_bar(position='stack', stat='identity')+
theme(axis.text.x = element_text(angle = 90))+
theme(plot.title = element_text(hjust=0.5, size=20, face='bold'))+
coord_flip()type here
工作正常。但它看起来并不有序: 我怎样才能根据“活跃”的数量订购它?
尝试关注但没有成功。
aes(y=Number_of_chemical, x=reorder(Assays, +Number_of_chemical), fill=key))