生信喵 发表于 2022-9-14 10:58:27

条形图以及分组条形图

一、条形图
# 实践:绘制人染色体长度分布图
x <- read.csv(file = "homo_length.csv",header = T)
head(x)
x <- x

barplot(height = x$length)
barplot(height = x$length,names.arg = x$chr)
barplot(height = x$length,names.arg = x$chr,las =3)
barplot(height = x$length,names.arg = x$chr,las =3,col = rainbow(4))
barplot(height = x$length,names.arg = x$chr,las =3,col = 'red')
barplot(height = x$length,names.arg = x$chr,las =3,col = c('red','green'))
library(RColorBrewer)
display.brewer.all()
cols <- brewer.pal(n = 6,name = "RdPu")
barplot(height = x$length,names.arg = x$chr,col = cols)
cols <- brewer.pal(n = 6,name = "Dark2")
barplot(height = x$length,names.arg = x$chr,col = cols)
cols <- brewer.pal(n = 6,name = "Blues")
barplot(height = x$length,names.arg = x$chr,col = cols)
cols <- brewer.pal(n = 6,name = "Set1")
barplot(height = x$length,names.arg = x$chr,col = cols,las=3)
barplot(height = x$length,names.arg = x$chr,col = cols,horiz = T,las=2)
par('mar')
barplot(height = x$length,names.arg = x$chr,col = cols,horiz = T,las=2,
      border = F,width = c(1,2),space = 0.1)
barplot(height = x$length,names.arg = x$chr,las=2,
      border = F,width = c(1,2),space = 1,density = 12,angle = c(45,135))

人染色体长度分布图


二、分组条形图
#绘制分组条形图
x <- read.csv("sv_distrubution.csv",header = T,row.names = 1)
head(x)
#barplot(x)
barplot(as.matrix(x))
barplot(t(as.matrix(x)))
# barplot(t(as.matrix(x)),col = rainbow(4))
barplot(t(as.matrix(x)),col = brewer.pal(4,name = 'Set2'))
barplot(t(as.matrix(x)),col = brewer.pal(4,name = 'Set2'),beside = T)
barplot(t(as.matrix(x)),col = brewer.pal(4,name = 'Set2'),
      horiz = F,density = 30,angle = c(45,135))
barplot(t(as.matrix(x)),col = brewer.pal(4,name = 'Set2'))
barplot(t(as.matrix(x)),col = brewer.pal(4,name = 'Set2'),legend.text = colnames(x),ylim = c(0,800),
      main = "SV Distribution",xlab="Chromosome Number",ylab="SV Numbers")

堆叠条形图
页: [1]
查看完整版本: 条形图以及分组条形图