我们知道,在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...
set.seed(5); tibble(x=letters[1:10] %>% as_factor(), y=rnorm(10,30,3), z=LETTERS[1:3] %>% sample(10,replace = T) %>% as_factor() %>% fct_relevel(c("A","B","C"))) %>% mutate(x=x %>% fct_reorder2(y,z)) %>% ggplot(aes(x,y,fill=z)) + geom_col()编辑...
在做物种/功能组成堆叠柱状图时,通常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...
ggplot2 柱状图按数值大小排序 CARTDOG关注赞赏支持ggplot2 柱状图按数值大小排序 CARTDOG关注IP属地: 广东 2020.09.28 09:33:42字数28阅读2,527 https://tding.top/archives/c363755b.html https://zhuanlan.zhihu.com/p/101926524最后编辑于 :2020.09.29 15:34:22 ©著作权归作者所有,转载或内容合作请联系...
下面是墨眉 《共享我们的大脑 》 的投稿全部的代码都是复制粘贴即可运行 在数据展示时为了体现各因素的比重(百分比),有时会用到堆叠柱状图,这里介绍下用 ggplot2 画堆叠柱状图的代码和相应的美化方法...# 因为后面想要做百分比的堆叠柱状图,先查看这个数据适不适合
ggplot()+ geom_bar(data=df01, aes(x=1,y=value,fill=group01), stat="identity",position = "fill")+scale_fill_manual(values = c("#827f88","#3288bd","#f36c44", "#e4e569","#b9b9dd","#000000"), breaks = rev(c("Others","Proteobacteria", ...