How do I draw gridlines using abline() that are behind the data?

前端 未结 4 1607
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 06:57

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

Is there a way to draw the abline() lines behind

4条回答
  •  生来不讨喜
    2020-12-05 07:13

    Plot first with type="n" to establish coordinates. Then put in the grid lines, then plot again with your regular plot type:

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

    I admit that I have always thought the name for that par parameter was "backwards."

提交回复
热议问题