如何在背景中放置参考线['abline()']?

发布于 2024-12-05 21:44:09 字数 389 浏览 2 评论 0原文

这也许是非常基本的,但我似乎找不到一个可行的解决方案:

我正在使用 R 中的“boxplot()”函数构建带有自定义轴的箱线图,并且我希望为细灰色线跨 y 刻度间隔的参考,类似于:

boxplot("MyDataTable", ylim=ylim, axes=FALSE, col=312, notch=TRUE)
axis(2, lwd=1.5, at=ytk, las=2, tck=-0.02, cex.axis=0.75, font=2)
abline(h=yln, lty=1.5, lwd=0.5, col=336)

当打印出来(在我的例子中为 pdf)时,细灰色线与箱线图的框和须线重叠。

我怎样才能得到与前景中的图形框和胡须相同的情节......?

This is perhaps very basic, but I just can't seem to find a working solution:

I'm building a boxplot with custom axes using the 'boxplot()' function in R, and I'd like to have thin grey lines for reference across the y-tick intervals, something like:

boxplot("MyDataTable", ylim=ylim, axes=FALSE, col=312, notch=TRUE)
axis(2, lwd=1.5, at=ytk, las=2, tck=-0.02, cex.axis=0.75, font=2)
abline(h=yln, lty=1.5, lwd=0.5, col=336)

When this prints out (to pdf, in my case), the thin grey lines overlap the boxplot's boxes and whiskers.

How can I have the same plot with the graphed boxes and whiskers being in the foreground...?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝海似她心 2024-12-12 21:44:09

一种方法是通过将箱线图添加到现有绘图中来重复调用,以便水平线成为背景。

例如:

boxplot(count ~ spray, data = InsectSprays, col = "lightgray", main = "plot title")
abline(h = 1:25, lty=1.5, lwd=0.5, col=336)
boxplot(count ~ spray, data = InsectSprays, col = "lightgray", add = TRUE)

由于您还需要与轴刻度进行交互,因此您可能会发现类似的东西也可以工作,但您的代码不可重现,因此我们只能猜测您想要看到的实际效果。

简单箱线图,在水平线上过度绘制http://beta1.opencpu.org/R/call/store:tmp/a2884b758f76d5c808e0f9751c35ad74/png?main=%22plot%20title%22

One way is just to repeat the boxplot call by adding it to the existing plot, so the horizontal lines become background.

For example:

boxplot(count ~ spray, data = InsectSprays, col = "lightgray", main = "plot title")
abline(h = 1:25, lty=1.5, lwd=0.5, col=336)
boxplot(count ~ spray, data = InsectSprays, col = "lightgray", add = TRUE)

Since you also need interaction with the axis ticks, you might find something similar works there as well but your code is not reproducible, so we can only guess at the actual effect you want to see.

Simple boxplot, overplotted on horizontal lines http://beta1.opencpu.org/R/call/store:tmp/a2884b758f76d5c808e0f9751c35ad74/png?main=%22plot%20title%22

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文