简体   繁体   中英

R - how two have two y-axes with zeroes aligned in the middle of the plot

I am plotting two graphs on the same plot. Each one has a different ylim, and I would like to have the zeroes aligned in the middle of the plot.

This is my code:

# data
 time <- seq(0.1, 10, by = 0.1)
 det_rot <- runif(100, min=-100, max=100)
 vel_mag <- runif(100, min=0, max=5)

# first plot
 smoothingSpline = smooth.spline(time, det_rot, spar=0.20)
 plot(time, det_rot,lwd=2,
           ann=FALSE, las=2, pch="",  ylim=c(-100,250)) # , pch=""
 lines(smoothingSpline, lwd=2, col="red")

 par(new=TRUE)

# second plot
 smoothingSpline2 = smooth.spline(time, vel_mag, spar=0.20)
 plot(time, vel_mag, 
      xaxt="n",yaxt="n",xlab="",ylab="",pch="", ylim=c(0,6))
 lines(smoothingSpline2, lwd=2, col="blue",)
 axis(4)

See the plot:

在此输入图像描述

简单修复:分别将ylims更改为c(-250,250)和c(-6,6)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM