Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Second Y axis ylab's location

Tags:

r

axis

I want to draw a double Y axis chart, but when I name the right Y axis name, the name can't be drawed on the right, but lay on the left Y axis's label, what should I do?

plot(1:length(S285$LAI),S285$LAI,axes=F,type="o",pch=1,xlim=c(1,length(S285$LAI)),ylim=c(0,6),xlab="",ylab="LAI",cex.lab=1.5)
axis(side=1,kk1,S285$DAY[kk1])
axis(side=2,seq(0,5,1),seq(0,5,1))
par(new=T)
plot(1:length(S285$LAI),S285$WSO,axes=F,type="o",pch=15,xlim=c(1,length(S285$LAI)),ylim=c(0,10000),xlab="",ylab="WSO")
axis(side=1,kk1,S285$DAY[kk1])
axis(side=4,seq(0,10000,1000),seq(0,10000,1000))
mtext("DOY285播种",side=3,line=-3.5,at=15)
legend(x=1,y=6000,legend=c("LAI","产量"),pch=c(1,15),cex=1.1,lty=c(1,1))

if you run this code, the two label "LAI" and "WSO" will get together, how to draw WSO to the right side? thank you all

like image 606
TOPMAD Avatar asked Jul 31 '26 14:07

TOPMAD


1 Answers

One option is to use mtext:

op <- par(mar = c(5,4,4,4) + 0.1)
plot(1:10, ylab = "ylabel")
axis(side = 4)
mtext("ylabel 2", side = 4, line = 3, cex = par("cex.lab"))
par(op)

which gives:

enter image description here

like image 133
Gavin Simpson Avatar answered Aug 03 '26 04:08

Gavin Simpson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!