修改X轴的名称

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
以如下数据为例
Chr count
Chr01 129848
Chr02 71797
Chr03 94549
Chr04 57979
Chr05 111190
Chr06 206997
Chr07 98584
Chr08 215548
Chr09 101744
Chr10 121403
Chr11 106254
Chr12 85558
Chr13 126346
scaffolds 49821
1
2
3
4
5
6
7
8
9
#数据读取
df<-read.table('file.txt',header=1,row.names=1)
#绘制boxplot,但不显示坐标轴,通过asex控制
p<-barplot(df[,1],axes = F,horiz = 1,border = 'white')
#逐步添加坐标轴
axis(2,labels = rownames(df),at = p[,1],tick = 0,pos = 4)
axis(1)
#添加标签
text(df[,1]+7000,p[,1],labels = df[,1])

也可以写成包的形式

1
2
3
4
5
6
7
8
SnpCountPlot<-function(data,col='gray60',border='white',xlim=c(0,max(data[,1])+max(data[,1])/10)){
#绘制boxplot,但不显示坐标轴,通过asex控制
p<-barplot(data[,1],axes = F,horiz = 1,border = 'white',col=col,xlim=xlim)
#逐步添加坐标轴
axis(2,labels = rownames(data),at = p[,1],tick = 0,pos = 4)
axis(1)
#添加标签
text(data[,1]+7000,p[,1],labels = data[,1])}

运行结果