### are trunctaed axes impossible to fix?
# let's create two variables0
z1 <- c(5.1, 5.4, 6.1, 5.2)
z2 <- z1 * 10
# a simple plot makes them look almost excatly the same
par(mfrow=c(1,2))
plot(z1, type="l")
plot(z2, type="l")
# on the same plot we lose sight of the pattern in z1, does this matter?
plot(z2, type="l", ylim=c(0,115))
lines(z1, col="hotpink", lwd=2)
# we need to add some context
# colour for the rectangles that increase the context
colr <- c("lightgrey")
# left hand plot for z1
par( fig=c(0, 0.4, 0, 1 ))
par(mar=c(5, 4, 2, 0) + 0.1)
plot(z1, type="l", ylim=c(0, max(z1)), xlab="", ylab="")
# draw a background for the data to be repeates (at scale in the second plot
rect( 1, 0, 5, 6.2 , col=colr, border=F)
lines( z1 , col="hotpink", lwd=2)
#why have I added the box again?
box()
# right hand plot for z2
par( fig=c(0.6, 1, 0, 1 ), new=T)
par(mar=c(5, 0, 2, 4) + 0.1)
plot(z2, type="l", ylim=c(0, max(z2)), xlab="", ylab="", axes=F)
#the box is drawn again (note that it is extended to the left... why?
rect( 0, 0, 4, 6.2 , col=colr, border=F)
lines( z1 , col="hotpink", lwd=2)
# teh axes weren't drawn, as the y-axis needs to be on th e other side.
axis(1)
axis(4)
box()
# now we link teh two grey boxes with a polygon, using a blank plot
par( fig=c(0.4, 0.6, 0, 1 ), new=T)
par(mar=c(5, 0, 2, 0) )
# plot type 'n' is useful here...
plot(z2, type="n", ylim=c(0, max(z2)), xlim=c(0,1),
xlab="", ylab="", axes=F)
# create vectors for the corners of the polygon
# clockwise order from top left
xp <- c(0, 1, 1, 0)
yp <- c( max(z2), max(z1), 0, 0)
# draw the polygon
polygon(xp, yp, col=colr, border=F)
# how can you alter the axes to empahsise the differences, and similiarities?
# think about making similar things similar if they are repeated...
# and making things different in the design if they differ.
# can you add another panel that zooms into z2 ?
# i.e. with a truncated axis?