barplot()条形图

2020-04-13  本文已影响0人  东方不赞

barplot()作为1维图,输入值为单个向量或单个矩阵(分组条形图)

1. 单个向量

1.1

图片.png
x=seq(10,by=2)
y=rep(c("a","b"),times=c(2,3))
barplot(height=x,names.arg = y,col=rainbow(5))

barplot是1维图,

1.2

图片.png
barplot(height=x,names.arg = y,col=rainbow(5),
        horiz = T,
        xlab = "a",
        ylab = "b",
        border = F)

1.3 坐标标签的朝向

在前面的代码加入las

las=1

las=1
barplot(height=x,names.arg = y,col=rainbow(5),
        horiz = T,
        xlab = "a",
        ylab = "b",
        border = F,
        las=1)

las=2

las=2

las=3

las=3

2. 输入值为单个矩阵

2.1堆砌

2.1.1 两行的矩阵

分组条形图-2行的矩阵
z=matrix(1:10,nrow=2)
y=rep(c("a","b"),times=c(2,3))
barplot(height = z,names.arg = y,col=rainbow(9),
        border = F,
        las=1)

2.1.2 三行的矩阵

3行的矩阵
z=matrix(1:15,nrow=3)
y=rep(c("a","b"),times=c(2,3))
barplot(height = z,names.arg = y,col=rainbow(9),
        border = F,
        las=1)

2.2 not堆砌

z=matrix(1:15,nrow=3)
y=rep(c("a","b"),times=c(2,3))
barplot(height = z,names.arg = y,col=rainbow(3),
        border = F,
        las=1,
        beside = T)
图片.png
上一篇 下一篇

猜你喜欢

热点阅读