我正在嘗試創建一個循環以從之前創建的數組中提取數據,以便我可以使用提取的數據生成一個線圖。如何在R中創建循環以迭代地繪製數組元素?
到目前爲止,我一直在做手工用:
allweek1<-(data.frame(t_weekmean[,,1])) #which selects the date and generates the data frame I want to later format the date using
week1<-stack(allweek1) #and then plot it using
plot(week1$values,type="n", xlim=c(0,2),xlab="Weight (gr)",ylab="Rate (umol/L*gr)",main="All individuals and Treatments at all times")
lines(week1$values[week1$ind=="X9"]~x,type="o",col="red")
lines(week1$values[week1$ind=="X12"]~x,type="o",col="blue")
lines(week1$values[week1$ind=="X15"]~x,type="o",col="green")
lines(week1$values[week1$ind=="X18"]~x,type="o",col="purple").
我知道必須有使這變成一個循環,在這個例子中,我給短短兩週的一種方式,但我的數據去最多30個,手動操作會很麻煩,容易出錯。
這是起始陣列我有:
, , Week = 1
Temp
variable 9 12 15 18
X0 100.000 100.000 100.000 100.000
X0.5 98.855 98.591 98.357 99.003
X1 98.004 97.804 97.638 98.299
X1.5 95.953 96.999 96.810 97.555
X2 95.235 96.078 95.346 96.665
, , Week = 2
Temp
variable 9 12 15 18
X0 100.000 100.000 100.000 100.000
X0.5 99.137 99.035 97.883 99.055
X1 98.420 98.298 96.459 97.765
X1.5 97.939 97.181 94.406 96.546
X2 96.998 96.237 91.906 95.263
以下的數據幀,然後將其轉換爲一個堆版本:
X9 X12 X15 X18
X0 100.000 100.000 100.000 100.000
X0.5 98.855 98.591 98.357 99.003
X1 98.004 97.804 97.638 98.299
X1.5 95.953 96.999 96.810 97.555
X2 95.235 96.078 95.346 96.665
,然後被用於繪製的代碼。
也許我的編輯更清晰? – 2011-06-09 10:23:37
非常感謝!我將添加一個參數(mfrow = c(2,2)),以便每個圖表具有4周的設置,並瞭解如何保存它們。謝謝!!! – BDM 2011-06-09 10:50:02