我们知道,在ggplot2里面,如果要对一个简单的柱状图(只包含X和Y)进行排序,只需要在aes()中将原本的x进行排序:reorder(x,y)即可;但是如果一个图中有几个组的柱状图同时存在呢? 我们先来举个例子: library(dplyr) library(ggplot2) df<-read.table(text = ' Care variable value D Equipment 0 D Equipment 1...
跟着Nature microbiology学作图:R语言ggplot2堆积柱形图每个柱子单独配色/多个图例排序 论文 A high-quality genome compendium of the human gut microbiome ofInner Mongolians https://www.nature.com/articles/s41564-022-01270-1 2023Naturemicrobiology--Ahigh-qualitygenomecompendiumofthehumangutmicrobiomeofInnerMong...
在做物种/功能组成堆叠柱状图时,通常ggplot2默认出图的x轴顺序是按字母或者数字大小排序的 默认x轴顺序 ggplot(mtcars,aes(cyl,disp)) + geom_bar(stat = "identity") 默认x轴顺序 随心所欲排x轴 mtcars$cyl <- factor(mtcars$cyl, levels = c("6","4","8")) ggplot(mtcars,aes(cyl,disp)) + geo...
2020.09.28 09:33:42字数 28阅读 2,533 https://tding.top/archives/c363755b.html https://zhuanlan.zhihu.com/p/101926524 最后编辑于:2020.09.29 15:34:22 ©著作权归作者所有,转载或内容合作请联系作者 日记本 更多精彩内容,就在简书APP
如何让柱状图在填充色分组的基础上,再按升序排列柱状图? set.seed(5) tibble(x=letters[1:10], y=rnorm(10,30,3), z=LETTERS[1:3] %>% sample(10,replace = T) %>% as_factor() %>% fct_relevel(c("A","B","C"))) %>% arrange(z,y) %>% mutate(x=factor(x,levels=unique(x)))...