[R] plot level, velocity, acceleration with one x axis

Spencer Graves @pencer@gr@ve@ @end|ng |rom e||ect|vede|en@e@org
Mon May 29 06:57:21 CEST 2023


Hello, All:


	  I want to plot level, velocity, and acceleration in three panels with 
only one x axis.  The code below does this using "layout".  However, I 
want the three plot areas to be of equal size, and this won't do that: 
If I stretch the plot vertically, the relative sizes of the three panels 
changes.  There's probably a way to do this with ggplot2, but I have yet 
to find it.


	  Suggestions?
	  Thanks,
	  Spencer Graves


str(AirTime <- as.numeric(time(AirPassengers)))
str(AP <- as.numeric(AirPassengers))

def.par <- par(no.readonly = TRUE) # save default, for resetting...
(mat3x1 <- matrix(1:3, 3))
plot3x1 <- layout(mat3x1, heights=c(1.4, 1, 1.5))
layout.show(plot3x1)

par(mar=c(0, 4.1, 4.1, 2.1))
plot(AirTime, AP, log='y', type='l', axes=FALSE,
      main='AirPassengers', ylab='AirPassengers')
box(col='grey')
axis(2, las=1)

par(mar=c(0, 4.1, 0, 2.1))
vAP <- diff(log(AP))
plot(tail(AirTime, -1), vAP, type='l',
      ylab='percent increase', axes=FALSE)
box(col='grey')
axis(2, las=1)

par(mar=c(5.1, 4.1, 0, 2.1))
plot(tail(AirTime, -2), diff(vAP), type='l',
      ylab='acceleration', xlab='year',
      las=1)
box(col='grey')

par(def.par)



More information about the R-help mailing list