[跟着NC学作图]-柱状堆积图
2022-11-28 本文已影响0人
生信筆記
本期内容为[[跟着NC学作图]-柱状堆积图
代码部分:
- 导入相关包和数据
options(stringsAsFactors = FALSE)
library(reshape)
library(plyr)
library(ggplot2)
library(ggsci)
library(cowplot)
library(reshape2)
#'@导入数据
metadata_coinf <- read.table("metadata_coinf.txt", header = T, sep = "\t")
metadata_coinf[1:5,1:12]
01.png
- 绘制基础图形
ggplot(metadata_coinf, aes(x=WEEK, group=CLADE))+
geom_bar(stat="count", aes(fill = CLADE))
geom_bar(stat="count", aes(fill = CLADE))
02.png
- 添加参数
ggplot(metadata_coinf, aes(x=WEEK, group=CLADE))+
geom_bar(stat="count", aes(fill = CLADE)) +
## 添加参数
scale_x_discrete(breaks = factor(metadata$WEEK),limits = levels(factor(metadata$WEEK)) ) +## include all weeks
ylab("n WGS") + xlab("Week") +
## 将Y轴从0开始
scale_y_continuous(breaks=seq(0,10,2))+
theme_bw() + theme( axis.text.x = element_text(vjust=0.5, size=8,angle=45))
03.png
## 更改颜色
p1_npg = p1 + scale_fill_npg(drop=FALSE)
04.png
- 绘制堆积图
ggplot(metadata, aes(x=WEEK, group=factor(CLADE)))+
geom_bar(stat="count", aes(fill = CLADE),position="fill")
05.png
- 添加参数
ggplot(metadata, aes(x=WEEK, group=factor(CLADE)))+
geom_bar(stat="count", aes(fill = CLADE),position="fill") +
#scale_fill_manual(values=cbPalette) +
scale_y_continuous(limits=c(0,1),labels = scales::percent) +
ylab("% WGS") + xlab("Week") +
theme_bw() + theme( axis.text.x = element_text(vjust=0.5, size=8,angle=45))10)
06.png
p2_npg = p2 + scale_fill_npg(drop=FALSE)
07.png
小杜的生信筆記 ,主要发表或收录生物信息学的教程,以及基于R的分析和可视化(包括数据分析,图形绘制等);分享感兴趣的文献和学习资料!