简体   繁体   English

在R中7个条形的条形图中的纹理?

[英]Texture in barplot for 7 bars in R?

I have 7 different categories per each value in X. I am using barplot to plot these categories. 我在X中每个值有7个不同的类别。我使用条形图来绘制这些类别。 Such graph looks fine in colors printer, but what if I want it to be fine in black & white. 这样的图形在彩色打印机中看起来很好,但如果我希望它在黑白中很好的话。 You can check the graph below. 您可以查看下面的图表。 I want to have different colors texture, so the graph looks good in color and black & white printer. 我想要有不同的颜色纹理,所以图形看起来很好的颜色和黑白打印机。

在此输入图像描述

I used densities = c(10,30,40,50,100,60,80) for density parameter in barplot function. 我在barplot函数中使用密度= c(10,30,40,50,100,60,80)作为密度参数。 Are there any other ways to do different texture in barplot? 在barplot中还有其他方法可以做不同的纹理吗?

Note: I tried the angle value in barplot. 注意:我在barplot中尝试了角度值。 However, it isn't a good solution in that case, since not all bars have high values (ie height of the bar). 然而,在这种情况下,它不是一个好的解决方案,因为并非所有的条都具有高值(即条的高度)。

Along the lines of my comment, you might find the following helpful: 根据我的评论,您可能会发现以下内容:

# data generation ---------------------------------------------------------
set.seed(1)
mat <- matrix(runif(4*7, min=0, max=10), 7, 4)
rownames(mat) <- 1:7
colnames(mat) <- LETTERS[1:4]


# plotting settings -------------------------------------------------------
ylim <- range(mat)*c(1,1.5)
angle1 <- rep(c(45,45,135), length.out=7)
angle2 <- rep(c(45,135,135), length.out=7)
density1 <- seq(5,35,length.out=7)
density2 <- seq(5,35,length.out=7)
col <- 1 # rainbow(7)


# plot --------------------------------------------------------------------
op <- par(mar=c(3,3,1,1))
barplot(mat, beside=TRUE, ylim=ylim, col=col, angle=angle1, density=density1)
barplot(mat, add=TRUE, beside=TRUE, ylim=ylim, col=col, angle=angle2, density=density2)
legend("top", legend=1:7, ncol=7, fill=TRUE, col=col, angle=angle1, density=density1)
par(bg="transparent")
legend("top", legend=1:7, ncol=7, fill=TRUE, col=col, angle=angle2, density=density2)
par(op)

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM