Based on Gong-Yi's answer, although I need to change the data to fill the bottom polygon. The full answer is:
X <- 1:20 B <- c(1,4,6,3,1, 4, 5,8,8,6,3,2,1, 1,5,7,8,6,4,2) C <- B + 4 A <- rep (0, length(B)) myd <- data.frame (X, B, C, A) plot(X, B, type="l", col="blue", xlim=c(0, 25), ylim=c(0, 15)) # 1 to 6 par(new=TRUE) plot(X, C, type="l", col="red", xlim=c(0, 25), ylim=c(0, 15)) polygon(c(1:6, 6:1), c(B[1:6], C[6:1]), col="green1") par(new=TRUE) plot(X, B, type="l", col="red", xlim=c(0, 25), ylim=c(0, 15)) polygon(c(1:6, 6:1), c(B[1:6], A[6:1]), col="green4") # 6 to 16 par(new=TRUE) plot(X, C, type="l", col="red", xlim=c(0, 25), ylim=c(0, 15)) polygon(c(6:16, 16:6), c(B[6:16], C[16:6]), col="blue1") par(new=TRUE) plot(X, B, type="l", col="red", xlim=c(0, 25), ylim=c(0, 15)) polygon(c(6:16, 16:6), c(B[6:16], A[16:6]), col="blue4") # 16 to 20 par(new=TRUE) plot(X, C, type="l", col="red", xlim=c(0, 25), ylim=c(0, 15)) polygon(c(16:20, 20:16), c(B[16:20], C[20:16]), col="purple1") par(new=TRUE) plot(X, B, type="l", col="red", xlim=c(0, 25), ylim=c(0, 15)) polygon(c(16:20, 20:16), c(B[16:20], A[20:16]), col="purple4")
