Reputation: 107
I've got a question regarding a graph made from rows.
testdata = structure(c(38, 38, 38, 38, 33, 32, 33, 31, 25, 26, 25, 23, 10,
9, 9, 8, 5, 4, 3, 5, 0, 0, 0, 0), .Dim = c(4L, 6L), .Dimnames = list(NULL, c("V1", "V2", "V3", "V4", "V5", "V6")))
V1 V2 V3 V4 V5 V6
[1,] 38 33 25 10 5 0
[2,] 38 32 26 9 4 0
[3,] 38 33 25 9 3 0
[4,] 38 31 23 8 5 0
This matrix contains 4 samples from 6 different time ticks(V1-V6). I basically want a scatterplot showing 4 different lines with their value on the Y-axis and on the X-axis the 6 "time ticks". For this I just want the dots and the "average line" of the dots and trust bands. I've done this before but I somehow can't manage it with each sample on a different row.
Upvotes: 2
Views: 86
Reputation: 24074
To get something like the excel plot example you gave, you can do:
matplot(t(testdata), t="b", pch=c(18, 15, 17, 4), lty=1, col=c("blue", "red", "green", "purple"), lwd=2)
Following @nico advice, you can also use type="o"
if you want continuous lines:
matplot(t(testdata), t="o", pch=c(18, 15, 17, 4), lty=1, col=c("blue", "red", "green", "purple"), lwd=2)
Upvotes: 5
Reputation: 4921
Another option in the base plotting system:
ndat<-as.data.frame(testdata)
plot(t(ndat[1,]), type="l", col="red", lwd=2, xlab="x-axis", ylab="values")
lines(t(ndat[2,]), type="l", col="yellow", lwd=2)
lines(t(ndat[3,]), type="l", col="green", lwd=2)
lines(t(ndat[4,]), type="l", col="blue", lwd=2)
Upvotes: 4