1

屏幕绘图完美运行,但 pdf 版本丢失'mtext' "incidence (%)"

# data

hgf <- c(394,441,592,559,455,542,583,548,636,709)
incfor <- c(11.2,13.0,13.5,12.0,7.8,8.0,8.4,8.4,8.8,9.5)

par(mar=c(5,4,4,5)+.1)
index <- 1:10
period <- c("9801","9902","0003","0104","0205", "0306",
            "0407","0508","0609","0710")

画面情节

bp <- barplot(hgf, ylim=c(0,800),cex.axis=1.0,yaxt="n")
axis(2, at=seq(0,800,200))
axis(1, at=bp,labels=period,cex.axis=1.0,las=2 )
par(new=TRUE)

plot(bp,incfor,type="l",col="blue",
  cex.axis=1.0,cex.lab=1.0,
  xaxt="n",yaxt="n",xlab="period",ylab="",ylim=c(0,16),lwd=2)
par(cex.axis=1.0)
axis(4, at=seq(0,16,2))
mtext("incidence % (line, rhs)",side=4,line=2,cex=1.0)
mtext("number (bar, lhs)",side=2,line=2,cex=1.0)
grid(nx=NULL,col="black")

pdf版本

par(mar=c(5,4,4,5)+.1)

pdf(file="fig_hgf_for.pdf",
  useDingbats=F)

bp <- barplot(hgf, ylim=c(0,800),cex.axis=1.0,yaxt="n")
axis(2, at=seq(0,800,200))
axis(1, at=bp,labels=period,cex.axis=1.0,las=2 )
par(new=TRUE)

plot(bp,incfor,type="l",col="blue",
  cex.axis=1.0,cex.lab=1.0,
  xaxt="n",yaxt="n",xlab="period",ylab="",ylim=c(0,16),lwd=2)
par(cex.axis=1.0)
axis(4, at=seq(0,16,2))
mtext("incidence % (line, rhs)",
  side=4,line=2,cex=1)
mtext("number (bar, lhs)",side=2,line=2,cex=1)
grid(nx=NULL,col="black")

dev.off()
4

1 回答 1

2

pdf()使用默认设置打开一个新设备par,使您之前的par(mar=...)通话无效。

底线:运行par(mar=...)pdf(...),它看起来不错。

于 2012-08-29T07:39:27.713 回答