5

単純な時系列データをプロットし、降水データをオーバープロットするのが好きです。次のコードは、通常のデータの線をプロットし、降水データの棒グラフ (またはヒストグラム バー) を追加します。

D # a simple (zoo) time series
P # a simple (zoo) time series of precipitation
plot(D, type="l")
lines(P, type="h", lwd=5)

しかし、バーは y=0 軸に基づいており、上に向かって伸びています。しかし、水文学では通常、一番上の軸に基づいた降水バーと下向きの「流れ」があります。Dには任意の y 範囲があるため、 のベースラインの値を修正するソリューションをお勧めしますP

私はたくさんグーグルで調べましたが、ggplot やハイドログラフのような追加のパッケージを使わずに R でこれを行う方法を見つけることができませんでした。

4

2 に答える 2

2

BlankUsername の助けを借りて、zoo時系列の次の解決策を見つけました。par(new=T)私は以前のようなものやaxis()コマンドに気づいていませんでした:

# plot the usual data
plot(D)
# add half day to indicate that P is a sum of the whole day
index(P) <- index(P) + 0.5
# define an overlay plot without border
par(bty="n", new=T)
plot(P, type="h", ylim=rev(range(P)), # downward bars by BlankUsername
    yaxt="n", xaxt="n", ann=F, # do not plot x and y axis
    xlim=c(start(D),end(D)), # without xlim the two overlayed plots will not fit
    lwd=10, col=rgb(0,0,0,0.1) ) # suggested cosmetics
# add right axis (4) to describe P
axis(4, pretty(range(P)), col.axis="grey", col="grey", las=1, cex.axis=0.7 )
# reset border and overlay
par(bty="o", new=F)
于 2014-04-09T22:47:18.690 に答える