生信人

找回密码
立即注册
搜索
热搜: 活动 交友 discuz
发新帖

0

收听

12

听众

318

主题
发表于 2022-9-27 23:57:56 | 查看: 1543| 回复: 0
一、分组条形图
  1. x <- read.csv("sv_distrubution.csv",header = T)  
  2. x  
  3. # svs <- x %>% tidyr::pivot_longer(cols = 2:5,names_to = 'variation')
  4. svs <- x %>% gather(key = Variation,value =Number,-X)
  5. ggplot(data = svs,aes(x=X,y=Number))+geom_bar(stat = "identity")
  6. ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity")

  7. p <- ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity")
  8. p + scale_x_discrete(limits=x$X)
  9. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 1,type = 'seq')
  10. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 2,type = 'seq')
  11. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 2,type = 'div')
  12. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 3,type = 'div')
  13. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 4,type = 'div')
  14. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set2',type = 'div')
  15. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1',type = 'div')
  16. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1')
  17. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Blues')

  18. ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='dodge')
  19. ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='dodge2')
  20. ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='fill')
  21. ggplot(data = svs,aes(x=X,y=Number,fill=Variation))+geom_bar(stat = "identity",position='stack')

  22. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1')+
  23.   labs(title ="SV Distribution",x="Chromosome Number",y="SV Numbers") +
  24.   theme(legend.position = 'bottom',plot.title = element_text(hjust = 0.5))
复制代码
ggplot2 绘制基因组 SV 突变堆叠条形图
  1. p + scale_x_discrete(limits=x$X) + scale_fill_brewer(palette = 'Set1')+
  2.   labs(title ="SV Distribution",x="Chromosome Number",y="SV Numbers") +
  3.   theme(legend.position = 'bottom',plot.title = element_text(hjust = 0.5)) +
  4.   coord_polar() +guides(fill='none')
复制代码


二、饼图
  1. m <- read.table("Species.txt",sep = '\t',header = FALSE)
  2. head(m)
  3. sum(m$V3)
  4. name <- paste(m[,1],m[,2],'\n',m$V3,'%')
  5. name
  6. ggplot(data = m,aes(x = "",y=V3,fill=name))+geom_bar(stat = 'identity') +
  7.   coord_polar(theta = 'y')+guides(fill = 'none')+scale_fill_brewer(palette = 'Set1')
  8. # y <- paste(m[,1],m[,2])
  9. # x <- data.frame(name=y,values=m$V3/sum(m$V3))
  10. # p <- ggplot(data = x,aes(x = "",y=values,fill=name))+geom_bar(stat = "identity",width = 1)+guides(fill='none')
  11. # p
  12. # p+coord_polar(theta = 'y')+labs(x = '', y = '', title = '')
复制代码

ggplot2 绘制饼图

三、箱线图
  1. head(ToothGrowth)
  2. ToothGrowth$dose <- as.factor(ToothGrowth$dose)
  3. #按提供药物种类分组
  4. ggplot(data = ToothGrowth,aes(x=supp,y=len,fill=supp))+geom_boxplot()
  5. #按剂量分组
  6. ggplot(data = ToothGrowth,aes(x=dose,y=len,group=dose,fill=dose))+geom_boxplot()
  7. #两组
  8. ggplot(data = ToothGrowth,aes(x=dose,y=len,group=supp:dose,fill=supp:dose))+geom_boxplot()
  9. ggplot(data = ToothGrowth,aes(x=dose,y=len,group=supp:dose,fill=supp))+geom_boxplot()
  10. ggplot(data = ToothGrowth,aes(x=dose,y=len,group=supp:dose,fill=dose))+geom_boxplot()
  11. ggplot(data = ToothGrowth,aes(x=supp,y=len,group=supp:dose,fill=dose))+geom_boxplot()

  12. #box图加抖动点
  13. p<- ggplot(data = ToothGrowth,aes(x=dose,y=len,fill=dose))+geom_boxplot()+
  14.   geom_jitter(width = 0.1)
  15. p+labs(title = 'ToothGrowth VC vs OJ',x='DOSE',y='Length')+
  16.   scale_fill_brewer(palette = 'Set1') +
  17.   theme(plot.title = element_text(hjust = 0.5)) +
  18.   theme(legend.position = 'bottom')
复制代码

ggplot2 绘制箱线图加抖动的点
  1. #分面
  2. ggplot(data = ToothGrowth,aes(x=supp,y=len,group=supp:dose,fill=supp))+geom_boxplot()+
  3.   scale_fill_brewer(palette = 'Set1')+
  4.   facet_grid(~ supp,scales = 'free')
复制代码


ggplot2 绘制分面箱线图

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

您需要登录后才可以回帖 登录 | 立即注册

QQ|Archiver|手机版|小黑屋|生信人 ( 萌ICP备20244422号 )

GMT+8, 2024-11-23 17:30 , Processed in 0.094452 second(s), 31 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表