R中的7条条形图的纹理? [英] Texture in barplot for 7 bars in R?

查看:76
本文介绍了R中的7条条形图的纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在X中的每个值都有7个不同的类别.我正在使用barplot绘制这些类别.这样的图形在彩色打印机中看起来不错,但是如果我希望它在黑色&彩色打印机中可以呢?白色的.您可以检查以下图表.我想要具有不同的颜色纹理,因此该图在颜色和黑色与黑色方面看起来都不错.白色打印机.

I have 7 different categories per each value in X. I am using barplot to plot these categories. 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.

我在barplot函数中使用了密度= c(10,30,40,50,100,60,80)作为密度参数.还有其他方法可以在barplot中执行不同的纹理处理吗?

I used densities = c(10,30,40,50,100,60,80) for density parameter in barplot function. Are there any other ways to do different texture in barplot?

注意:我尝试在barplot中输入角度值.但是,在这种情况下,这并不是一个好的解决方案,因为并非所有条形图都有很高的值(即条形图的高度).

Note: I tried the angle value in barplot. However, it isn't a good solution in that case, since not all bars have high values (i.e 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)

这篇关于R中的7条条形图的纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆