如何使用数据后面的 abline() 绘制网格线? [英] How do I draw gridlines using abline() that are behind the data?
本文介绍了如何使用数据后面的 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屋!
查看全文