如何将网格线放在pdf后面的boxplot中

时间:2016-04-07 14:52:08

标签: r boxplot gridlines

我想将网格线放在我的箱线图后面并保存为pdf。这该怎么做? 我可以用后面的线条生成箱线图,但是当它作为pdf导出时,线条位于图表前面

一些数据

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代码

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()

看起来像这样 boxplot

(虽然注意这是一个屏幕剪辑而不是pdf,因为我不知道该怎么做)

这看起来很简单但是如何让pdf部分工作?

1 个答案:

答案 0 :(得分:4)

为第二个boxplot电话添加填充色:

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()