面グラフを描く

面グラフを描きたい。
まあggplot2を使えばgeom_lineでfillを指定したりすれば一発なのだが、以下のサイトにあるような図を描きたいのでggplot2だと色々過剰。
http://www.informationisbeautiful.net/visualizations/mountains-out-of-molehills/
したがって基本のplotで描くことにする。
この場合、polygonを使う。
polygonは多角形の中を塗りつぶす関数。
今回のように面グラフを描く場合は、基準線(たとえばy座標が0)と折れ線グラフで囲んだ多角形を作って、その中を塗りつぶす。

# サンプルデータ

smp <- c(0, 0, 2, 3, 1, 0, 0, 4, 5, 3, 0)
smp2 <- c(0, 1, 0, 1, 2, 0, 0, 1, 2, 0, 0)
smp3 <- c(1, 0, 0, 0, 2, 0, 0, 0, 0, 2, 3, 0)

# 範囲を指定した空のプロットで枠を決める

plot(x = c(0, length(smp)+1), y = c(min(smp-2), max(smp+1)), type = "n", axes = FALSE, xlab = "time-series", ylab = "value")
polygon(x = c(1:length(smp), length(smp):1), y = c(rep(0, length(smp)), smp[length(smp):1]), col = "coral", border = NA)

# y座標を下に1ずつずらしながらプロットする
par(new=T)
polygon(x = c(1:(length(smp2)), length(smp2):1), y = c(rep(-1, length(smp2)), smp2[length(smp2):0]-1), col = "rosybrown", border = NA)
par(new=T)
polygon(x = c(1:(length(smp3)), (length(smp3)):1), y = c(rep(-2, length(smp3)), smp3[length(smp3):0]-2), col = "slategray", border = NA)