【问题标题】:Width of shading lines in barplot条形图中阴影线的宽度
【发布时间】:2018-03-06 04:38:19
【问题描述】:

我在 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)

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

【问题讨论】:

  • 请阅读有关how to ask a good question 的信息以及如何提供reproducible example。这将使其他人更容易帮助您。
  • @Jaap:对不起,我在创建这个问题时不小心关闭了选项卡。显然,它随后被发布到stackoverflow。这不是我的目标,我会在编辑后再次发布。

标签: r colors bar-chart


【解决方案1】:

您可以使用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)

【讨论】:

  • 这也设置了盒子的宽度,这并不总是需要的。有什么解决办法吗?
  • 我找到了一个解决方案:分别绘制方框和阴影线,第二个条形图使用 add=Tborder=NA。在两者之间使用par(lwd=5)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-22
相关资源
最近更新 更多