r - Two plots with same X and Y axis -


the plot shown produced following r code.

png("test.png") plot(data[,4],data[,3],type='l',col="green") par(new=true) plot(data[,4],data[,2],type='l',col="red") dev.off() 

the range of y-axis differs both plots , overwritten shown in image. set same y-axis range both plots.

enter image description here

if y scales largely overlap, can make initial plot includes full range (without plotting on it) define axes, plot lines.

set.seed(5) data <- data.frame(1:60, rnorm(60, 0.6, 0.1), rnorm(60, 0.65, 0.15),                     seq(2,120,by=2)) 

using type='n' sets axes, doesn't plot anything. using range of data makes sure plot encompasses data.

plot(range(data[,4]), range(c(data[,3],data[,2])), type='n') lines(data[,4], data[,3], type='l', col='green') lines(data[,4], data[,2], type='l', col='red') 

enter image description here


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -