R语言base实现中文常见不同线条填充柱形图

写在前面

目前已经是6月中旬了,毕业生已经开始收拾东西,开始走了,我们的路还是要继续,博士最后的几年可能是人生中最后的上学的时间,珍惜也好,坚持也好,希望我们可以把握丰硕的成果。

中文文章中,我们常见的柱状图并不是五颜六色的,大多数情况下是黑白,通过透明度区分,或者填充不同方向的线条,在R语言里面基础包给我们类似的解决方案,但是遗憾的是只能用于柱状图。这才有了我们介绍的patternplot包。

# create dummy data
data <- data.frame(
name=letters[1:5],
value=sample(seq(4,15),5)
)

# barplot
barplot( height=data$value, names=data$name , density=c(5,10,20,30,7) , angle=c(0,45,90,11,36) , col="brown" )

density可以通过调控线的密度,angle通过调控线的方向来做出不同样式的填充线。这两种参数一起调控,可实现相当多的类型。

barplot( height=data$value, names=data$name , density=c(5,10,20,30,4) , angle=c(0,45,90,11,36) , col="brown" )

遗憾的是在箱线图中并没有这种类型的实现方式,所以我们才需要patternplot包

## boxplot on a formula:
boxplot(count ~ spray, data = InsectSprays, col = "lightgray")
# *add* notches (somewhat funny here <--> warning "notches .. outside hinges"):
boxplot(count ~ spray, data = InsectSprays,
notch = TRUE, add = TRUE, col = "blue")

boxplot(decrease ~ treatment, data = OrchardSprays, col = "bisque",
log = "y")

(0)

相关推荐