2011-10-28 12 views
2

私はRには比較的新しく、日付に対してグループ化されたデータをプロットするのに問題があります。私は4年以上の月ごとに集計データを持っています。私は2008年の5月を2009年5月に分類するのではなく、むしろ毎年の標準誤差が毎月を指していることを望んでいます。ここまでは私のコードですが、ポイントのない空白のグラフが表示されます。私は軸を取り除くことができます。POSIXct行と私はポイントとエラーバーを持つグラフを取得します。この問題は、プロットのスケーリングやデータ形式と軸の関係にあるようです。誰も私をここで助けることができますか?日付を伴うトラブルプロットR

> r <- as.POSIXct(range(refmCount$mo.yr), "month") 
> 
> ############# can get plot and points to line up on the x-axis########################## 
> plot(refmCount$mo.yr, refmCount$count, type = "n", xaxt = "n", 
+  xlab = "Date", 
+  ylab = "Mean number of salamanders per night", 
+  xlim = c(r[1], r[2])) 
> axis.POSIXct(1, at = seq(r[1], r[2], by = "month"), format = "%b") 
> points(refmCount$mo.yr, refmCount$count, type = "p", pch = 19) 
points(depmCount$mo.yr, depmCount$count, type = "p", pch = 24) 
> arrows(refmCount$mo.yr, refmCount$count+mCount$se, refmCount$mo.yr, refmCount$count- refmCount$se, angle=90, code=3, length=0) 
> 
> str(refmCount) 
'data.frame': 19 obs. of 7 variables: 
$ mo.yr:Class 'Date' num [1:19] 14000 14031 14061 14092 14123 ... 
$ trt : Factor w/ 2 levels "Depletion","Reference": 2 2 2 2 2 2 2 2 2 2 ... 
$ N : num 75 110 15 10 34 20 20 10 40 15 ... 
$ count: num 3.6 5.95 3.47 6.7 11.12 ... 
$ sd : num 8.58 8.4 4.42 3.47 11.88 ... 
$ se : num 0.99 0.801 1.142 1.096 2.037 ... 
$ ci : num 1.97 1.59 2.45 2.48 4.14 ... 
> r 
[1] "2008-04-30 20:00:00 EDT" "2011-05-31 20:00:00 EDT" 
> 

答えて

1

2つの選択肢があります。パッケージ "zoo"をインストールし、年令クラスを使用するか、2005年5月が2005.4167になるように月を計算します。あなたはpaste(month.abb[month], year)でよりきれいなラベルを作成できます。

+0

私はそれを理解しました。以前のコードでは、変数mo.yrを作成したときにas.POSIXctの代わりにas.Dateを使用していたので、私の軸は1つの形式になり、変数は別のものになりました。それはコードの150行前だったので、私はそれを逃したと思います。助けてくれてありがとう。 – djhocking

関連する問題