I am trying the create a loop to extract data from an array created previously, so that I can then use the extracted data to generate a line plot.
So far I have been doing it manually by using:
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").
I know there has to be a way of making this into a loop, for this example I am giving just two weeks but my data goes up to 30, and doing it manually will be messy and easy to have mistakes.
This is the starting array that I have:
, , 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
The following data frame which is then converted to a stack version:
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
and then the code for plotting is used.
