一、分组条形图
x <- read.csv("sv_distrubution.csv",header = T)
x
# svs <- x %>% tidyr::pivot_longer(cols = 2:5,names_to = 'variation')
svs <- x %>% gather(key = Variation,value =Number,-X)
ggplot(data = svs,aes(x=X,y=Number))+geom_bar(stat = "identity")
ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity")
p <- ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity")
p + scale_x_discrete(limits=x$X)
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 1,type = 'seq')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 2,type = 'seq')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 2,type = 'div')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 3,type = 'div')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 4,type = 'div')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set2',type = 'div')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1',type = 'div')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Blues')
ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='dodge')
ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='dodge2')
ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='fill')
ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='stack')
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1')+
labs(title ="SV Distribution",x="Chromosome Number",y="SV Numbers") +
theme(legend.position = 'bottom',plot.title = element_text(hjust = 0.5))
ggplot2 绘制基因组 SV 突变堆叠条形图
p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1')+
labs(title ="SV Distribution",x="Chromosome Number",y="SV Numbers") +
theme(legend.position = 'bottom',plot.title = element_text(hjust = 0.5)) +
coord_polar() +guides(fill='none')
二、饼图
m <- read.table("Species.txt",sep = '\t',header = FALSE)
head(m)
sum(m$V3)
name <- paste(m[,1],m[,2],'\n',m$V3,'%')
name
ggplot(data = m,aes(x = "",y=V3,fill=name))+geom_bar(stat = 'identity') +
coord_polar(theta = 'y')+guides(fill = 'none')+scale_fill_brewer(palette = 'Set1')
# y <- paste(m[,1],m[,2])
# x <- data.frame(name=y,values=m$V3/sum(m$V3))
# p <- ggplot(data = x,aes(x = "",y=values,fill=name))+geom_bar(stat = "identity",width = 1)+guides(fill='none')
# p
# p+coord_polar(theta = 'y')+labs(x = '', y = '', title = '')
ggplot2 绘制饼图
三、箱线图
head(ToothGrowth)
ToothGrowth$dose <- as.factor(ToothGrowth$dose)
#按提供药物种类分组
ggplot(data = ToothGrowth,aes(x=supp,y=len,fill=supp))+geom_boxplot()
#按剂量分组
ggplot(data = ToothGrowth,aes(x=dose,y=len,group=dose,fill=dose))+geom_boxplot()
#两组
ggplot(data = ToothGrowth,aes(x=dose,y=len,group=supp:dose,fill=supp:dose))+geom_boxplot()
ggplot(data = ToothGrowth,aes(x=dose,y=len,group=supp:dose,fill=supp))+geom_boxplot()
ggplot(data = ToothGrowth,aes(x=dose,y=len,group=supp:dose,fill=dose))+geom_boxplot()
ggplot(data = ToothGrowth,aes(x=supp,y=len,group=supp:dose,fill=dose))+geom_boxplot()
#box图加抖动点
p<- ggplot(data = ToothGrowth,aes(x=dose,y=len,fill=dose))+geom_boxplot()+
geom_jitter(width = 0.1)
p+labs(title = 'ToothGrowth VC vs OJ',x='DOSE',y='Length')+
scale_fill_brewer(palette = 'Set1') +
theme(plot.title = element_text(hjust = 0.5)) +
theme(legend.position = 'bottom')
ggplot2 绘制箱线图加抖动的点
#分面
ggplot(data = ToothGrowth,aes(x=supp,y=len,group=supp:dose,fill=supp))+geom_boxplot()+
scale_fill_brewer(palette = 'Set1')+
facet_grid(~ supp,scales = 'free')
ggplot2 绘制分面箱线图
写在最后:有时间我们会努力更新的。大家互动交流可以前去论坛,地址在下面,复制去浏览器即可访问,弥补下公众号没有留言功能的缺憾。
bioinfoer.com
有些板块也可以预设为大家日常趣事的分享等,欢迎大家来提建议。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有