我正在创建这个"barplot" ggplot,但我希望能够重新定位每个类别中的条形图,以便最高的条形图位于顶部.简而言之,每个类别都有一个从高到低排序.
以下是我的代码 - 欢迎任何提示 - 谢谢
library("ggplot2")
d <- read.csv('http://db.tt/EOtR3uh', header = F)
d$V4 <- factor(d$V2, levels=d$V2)
base_size <- 11
ggplot(d, aes(d$V4, -log10(d$V3), fill=d$V1)) +
geom_bar(stat="identity") +
coord_flip() +
labs(y = "-log10(Pvalues)",x = "",fill="") +
theme_grey(base_size = base_size) +
scale_x_discrete(expand = c(0, 0))
Run Code Online (Sandbox Code Playgroud)

只需相应地对您的级别进行排序即可
d <- read.csv('http://db.tt/EOtR3uh', header = F, stringsAsFactors=FALSE)
lvls <- d$V2[order(d$V1,-d$V3)]
d$V4 <- factor(d$V2, levels=lvls)
Run Code Online (Sandbox Code Playgroud)
