条形图中阴影线的宽度

3

我使用以下R脚本创建了一个条形图:

bars <- c(229, 158)
shading.lines <- c(83, 83)
years <- c("1985-89", "2017")
cols1 <- c("indianred4","green4")
cols2 <- c("green4","indianred4")
barplot(bars,names.arg=years,col=cols1)
barplot(shading.lines,names.arg=NA,col=cols2,density=11,add=T)

enter image description here

有没有办法调整阴影线的宽度?我想让它们更粗,以便获得1985-89年和2017年阴影部分相同的外观。


请阅读关于“如何提出好问题”的信息(http://stackoverflow.com/help/how-to-ask)以及如何提供“可重现的示例”(https://dev59.com/eG025IYBdhLWcg3whGSx#5963610)。这将使其他人更容易地帮助您。 - Jaap
@ Jaap:抱歉,我在创建这个问题时不小心关闭了标签页。然后它似乎被发布到stackoverflow上了。这不是我的目的,当我编辑后我会再次发布它。 - yenats
1个回答

2
您可以使用par(lwd=...)来调整阴影的宽度:
bars <- c(229, 158)
shading.lines <- c(83, 83)
years <- c("1985-89", "2017")
cols1 <- c("indianred4","green4")
cols2 <- c("green4","indianred4")
barplot(bars,names.arg=years,col=cols1)
# Set width of shading
par(lwd=5)
barplot(shading.lines,names.arg=NA,col=cols2,density=11,add=T)
# Set width of shading to the default value
par(lwd=1)

enter image description here


这也设置了盒子的宽度,这并不总是理想的。有什么解决办法吗? - Rodrigo
我找到了一个解决方案:分别绘制箱体和阴影线,使用add=Tborder=NA来绘制第二个条形图。在两者之间使用par(lwd=5) - Rodrigo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接