Reputation: 2143
I would like to put gridlines behind my boxplot and save as a pdf. How to do this? I can generate the boxplot fine with lines behind but when it is exported as a pdf the lines are in front of the plot
Some data
box.data <- data.frame(one = runif(6,-0.2,1),two = runif(6,-0.2,1),three = runif(6,-0.2,1),four = runif(6,-0.2,1),five = runif(6,-0.2,1),six = runif(6,-0.2,1),seven = runif(6,-0.2,1),eight = runif(6,-0.2,1), nine = runif(6,-0.2,1))
Boxplot code
pdf("BiasBoxPlot.pdf")
boxplot(box.data, par(cex.axis=0.5),ylim=c(-0.2,1),yaxt = "n")
axis(2, yaxp=c(-2, 1, 30),cex.axis=0.5)
abline(h=seq(-0.2,1,0.05),col="grey80", lty="dotted",lwd = 0.4)
abline(v=seq(1,9),col="grey80", lty="dotted",lwd = 0.4)
boxplot(box.data,par(cex.axis=0.5),ylim=c(-0.2,1),add = TRUE)
dev.off()
(though note this is a screen clipping not a pdf as I wasn't sure how to do that)
This seems like something straightforward but how to put the get the pdf
part to work?
Upvotes: 1
Views: 2676
Reputation: 1099
Add a fill color to the second boxplot
call:
pdf("BiasBoxPlot.pdf")
boxplot(box.data, par(cex.axis=0.5),ylim=c(-0.2,1),yaxt = "n")
axis(2, yaxp=c(-2, 1, 30),cex.axis=0.5)
abline(h=seq(-0.2,1,0.05),col="grey80", lty="dotted",lwd = 0.4)
abline(v=seq(1,9),col="grey80", lty="dotted",lwd = 0.4)
boxplot(box.data,par(cex.axis=0.5),ylim=c(-0.2,1),add = TRUE,col="white")
dev.off()
Upvotes: 4