次要Y轴上的mtext超出了R中的图

时间:2016-04-29 13:25:17

标签: r plot

在图中的辅助Y轴上看起来mtext("daily intake"...)。至少在最后的图片上看不出来。所以,我的问题是:

1)如何将此图更简洁地包含在辅助Y轴中? 2)如何将辅助Y轴上的数字(10 ... 100)反转为水平形式?

fcr1 <- c(0.68, 0.88,   1.02,   0.78,   0.75,   0.75,   1.07, 1.00)
fcr2 <- c(0.68, 0.89,   1.00,   0.80,   0.72,   0.75,   1.04, 0.98)
fcr3 <- c(0.71, 0.98,   0.98,   0.80,   0.70,   0.72,   1.08, 1.02)
fcr4 <- c(0.90, 1.00,   1.20,   0.94,   0.72,   0.75,   1.12, 1.20)
fcr5 <- c(0.50, 1.08,   1.12,   0.72,   0.68,   0.67,   1.08, 1.10)
fcr6 <- c(0.50, 1.08,   1.14,   0.81,   0.75,   0.74,   1.09, 1.00)
fi <- c(70,10,7,5,5,4,3,3)

age <- c(30,45,60,75,90,105,120,135)

mydata <- data.frame(fcr1, fcr2, fcr3, fcr4, fcr5, fcr6, age, fi)
plot(age, xlab="Days", ylab="FCR", xlim=c(30,135), ylim=c(0.30,1.30),axes=FALSE)
axis(side=1, at=seq(30,135, by=15), cex.axis=0.8, tck=0.02)
axis(side=2, at=seq(0.3, 1.30, by=0.10), cex.axis=0.8, tck=0.02, las=1)
points(mydata$age, mydata$fcr1, pch = 20, col = "yellow")
points(mydata$age, mydata$fcr2, pch = 20, col=adjustcolor("blue", alpha=0.4))
points(mydata$age, mydata$fcr3, pch = 20, col="indianred")
points(mydata$age, mydata$fcr4, pch = 20, col="red2")
points(mydata$age, mydata$fcr5, pch = 20, col=adjustcolor("green", alpha=0.4))
points(mydata$age, mydata$fcr6, pch = 20, col="purple")

par(new = T)

plot(mydata$age, mydata$fi, pch=21, bg="orange",  xlab="", ylab="", ylim=c(0,100), axes=F, 
     type="s", col="blue", lwd=1, lty=1)
mtext("daily intake",side=4,col="black",line=2) 
axis(4, at=seq(0, 100, by=10), cex.axis=0.8, tck=0.02,  col="black",col.axis="black")

box()

final plot

0 个答案:

没有答案