ggsci::scale_fill_npg() 为了方便后续绘制不同分类级别的物种丰度堆叠柱状图,我们定义一个通用绘图函数pic()。 Step 7: 定义绘图函数 pic <- function(name){ ggplot(dat, aes(sample, value, fill = dat[,name])) + geom_bar(stat="identity", position = 'fill')+ xlab("") + ylab("") + them...
data$sum <- rowSums(data) data <- data[order(data$sum, decreasing = TRUE),] #计算相对丰度 dataabun <- data[1:24]/colSums(data[1:24]) #这里要排除掉sum列,不然最后一列的值是按sum算的 #筛选丰度较高的类群,并合并其余为Others phylum_top15 <- dataabun[1:15, -ncol(dataabun)] phylum...
(2)比例堆叠柱状图 q<-ggplot(data_m,aes(x=species,y=Number,group=NLR))+geom_bar(stat="identity",position="fill",width=0.5,aes(fill=NLR))+labs(x="species",y="Proportion")+scale_y_continuous(expand=c(0,0))+#图延伸到0theme_classic()+theme(legend.text=element_text(size=11),legend....
最后是画图 # 使用ggplot2绘图 p <- ggplot(data4,aes(x=sample,y=100*value, fill = Class))+ #数据输入:样本、物种、丰度 geom_col(position="stack",width = 0.5)+ # stack:堆叠图 scale_y_continuous(expand=c(0,0))+ # 调整y轴属性,使柱子与x轴坐标接触 scale_fill_manual (values = rev(...
R ggplot2绘制堆叠柱状图 超级可爱的懂事长鸭IP属地: 江苏 0.5442021.12.31 23:01:28字数 169阅读 17,665 STEP1:了解数据特征 rm(list=ls())data_test=datasets::attitude# 因为后面想要做百分比的堆叠柱状图,先查看这个数据适不适合statistics=apply(data_test,1,sum)# 得到每个样本的观测值总和plot(statistics)...
绘图部分将geom_bar(position="stack")设置成堆叠类型可以生成堆叠的柱状图,默认fill的顺序是”Sample“因子的顺序,如果不是有序因子一般是字母排序的顺序。 p = ggplot(dat, aes(x= type,y= Num,fill = Sample))+ geom_bar(stat="identity",width =0.6,position ="stack")+ ...
ggplot(data, aes(fill=condition, y=value, x=specie)) + geom_bar(position="fill", stat="identity")##这两句代码可以分开两句输入,也可以一句输入## 这里就是百分比堆叠柱状图了,可以比较下图于上图的纵坐标,差别也仅是 position="fill" 4. 自己造一个堆叠柱状图(个性化设计) ...
这个图换成堆叠图就很简单了 q1<-ggplot(data=df1, mapping=aes(x = Group, y = Value,fill=Sample))+ geom_bar(stat="identity",position=position_stack(0.75))+theme_bw()+ggtitle(expression(underline(bold('Goruped Bar ')))+theme(plot.title = element_text(hjust = 0.5))##只有这里dodge换成...
###读取并挑选 top10 丰度种(RPM),并绘制物种丰度堆叠柱状图#读取数据:特征表species<-read.delim('species_RPM_table-NC.txt',row.names=1,sep='\t',stringsAsFactors=FALSE,check.names=FALSE)#求各类群的丰度总和,并排序species$sum<-rowSums(species)species<-species[order(species$sum,decreasing=TRUE),]...
3. 制作堆叠柱状图 (1) p<-ggplot(data_m,aes(x=species,y=Number,group=NLR))+geom_bar(stat="identity",position="stack",width=0.5,aes(fill=NLR))+labs(x="species",y="NLR Number")+#设置横纵坐标的题目,可以和前面的不一样scale_y_continuous(expand=c(0,0))+#使每根柱子延伸到0,也可以...