在条形图的条形内绘制边框?
我正在绘制一个带有粗条形边框的简单条形图:
par(lwd=3)
barplot(c(6,7))
arrows(0,0,10,0,lwd=1)
边框在 x 轴上稍微突出,看起来很糟糕。
有没有办法在每个条形内绘制边框,而不是围绕它?
I'm drawing a simple barplot with thick bar borders:
par(lwd=3)
barplot(c(6,7))
arrows(0,0,10,0,lwd=1)
The borders stick out slightly over the x-axis, which looks bad.
Is there any way to draw the border within each bar, rather than around it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能想到的最好的方法是通过在 barplot 中设置 border = NA 来手动将一些东西组合在一起,然后使用lines添加边框:
< img src="https://i.sstatic.net/KrEwm.png" alt="在此处输入图像描述">
这远非理想。
lines
中使用的坐标假设条形之间默认为 0.2 间距,并将底部拉至 0.02 只是基于我的目测。您可能需要根据具体情况进行修改。The best I can think of is to hack something together by hand by setting
border = NA
inbarplot
and then adding the borders usinglines
:This is far from ideal. The coordinates used in
lines
assume the default 0.2 space between bars and pulling the bottom up to 0.02 was just based on me eyeballing it. You might have to tinker with it on a case by case basis.在未能找到clip()-ping或简单的“内边框”答案后,我的建议是:
它的优点是不会夹住较高条形的顶部。打赌你没有注意到这一点。直到我使用lwd=10时我才注意到它。
My suggestion after failing to find a clip()-ping or an easy "inner border" answer is this suggestion:
It has the advantage that it doesn't clip the top of the higher bars. Bet you didn't notice that. I didn't notice it until I used lwd=10.