如何使用数据后面的abline()绘制网格线? [英] How do I draw gridlines using abline() that are behind the data?

查看:170
本文介绍了如何使用数据后面的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()绘制网格线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆