如何使用数据后面的 abline() 绘制网格线?

编程入门 行业动态 更新时间:2024-10-27 23:19:01
本文介绍了如何使用数据后面的 abline() 绘制网格线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当我使用 abline() 在绘图上绘制网格线时,网格线将绘制在数据上.

When I draw grid lines on a plot using abline() the grid lines are drawn over the data.

有没有办法在数据后面绘制 abline() 行?我觉得这样会更好看.

Is there a way to draw the abline() lines behind the data? I feel this would look better.

示例:

x <- seq(0, 10) y <- x plot(x, y, col = 'red', type = 'o', lwd = 3, pch = 15) abline(h = seq(0, 10, .5), col = 'lightgray', lty = 3) abline(v = seq(0, 10, .5), col = 'lightgray', lty = 3)

生成的图有灰色网格线穿过数据(红线).我希望红线位于灰线之上.

The plot produced has the gray grid lines going over the data (red line). I would like the red line to be on top of the gray lines.

推荐答案

plot() 的 panel.first 参数可以接受一个函数列表或向量,这样你可以把你的 abline() 调用放在那里.

The panel.first argument of plot() can take a list or vector of functions so you can put your abline() calls in there.

plot(1:4, panel.first = c(abline(h = 1:4, lty = 2, col = 'grey') ,abline(v = 1:4, lty = 2, col = 'grey')))

更多推荐

如何使用数据后面的 abline() 绘制网格线?

本文发布于:2023-07-18 00:50:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1139274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网格   如何使用   数据   abline

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!