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 the data? I feel this would look better.
Example:
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.
Click the chart, and then click the Chart Design tab. Click Add Chart Element > Gridlines. Choose the axis that you want to apply the gridlines to or click More Gridline Options to open the Format Major Gridlines pane.
Grid lines are lines that cross the chart plot to show axis divisions. Grid lines help viewers of the chart see what value is represented by an unlabeled data point. Especially for large or complicated charts, grid lines give valuable cues to the viewer.
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')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With