Reputation: 1
This is perhaps very basic, but I just can't seem to find a working solution:
I'm building a boxplot with custom axes using the 'boxplot()' function in R, and I'd like to have thin grey lines for reference across the y-tick intervals, something like:
boxplot("MyDataTable", ylim=ylim, axes=FALSE, col=312, notch=TRUE)
axis(2, lwd=1.5, at=ytk, las=2, tck=-0.02, cex.axis=0.75, font=2)
abline(h=yln, lty=1.5, lwd=0.5, col=336)
When this prints out (to pdf, in my case), the thin grey lines overlap the boxplot's boxes and whiskers.
How can I have the same plot with the graphed boxes and whiskers being in the foreground...?
Upvotes: 0
Views: 5034
Reputation: 29515
One way is just to repeat the boxplot call by adding it to the existing plot, so the horizontal lines become background.
For example:
boxplot(count ~ spray, data = InsectSprays, col = "lightgray", main = "plot title")
abline(h = 1:25, lty=1.5, lwd=0.5, col=336)
boxplot(count ~ spray, data = InsectSprays, col = "lightgray", add = TRUE)
Since you also need interaction with the axis ticks, you might find something similar works there as well but your code is not reproducible, so we can only guess at the actual effect you want to see.
Upvotes: 3