#创建数据集
data <- data.frame(
name=letters[1:5],
value=sample(seq(4,15),5)
)
#查看数据集
data
#绘制
barplot(height=data$value, names=data$name)
#改为一个统一颜色
barplot(height=data$value, names=data$name, col=rgb(0.2,0.4,0.6,0.6) )
#不同颜色主题
library(RColorBrewer)
coul <- brewer.pal(5, "Set2")
coul
barplot(height=data$value, names=data$name, col=coul )
#框子颜色
barplot(height=data$value, names=data$name, border="#69b3a2", col="white" )
#坐标轴范围更改,以及坐标名字更改
barplot(height=data$value, names=data$name,
col=rgb(0.8,0.1,0.1,0.6),
xlab="categories",
ylab="values",
main="My title",
ylim=c(0,40)
)
#图形要横着
barplot(height=data$value, names=data$name,
col="#69b3a2",
horiz=T, las=1
)
#要纹理,不要颜色
barplot( height=data$value,
names=data$name ,
density=c(5,10,20,30,7) ,
angle=c(0,45,90,11,36) ,
col="brown")