2015-05-20 34 views
2

我有一个关于由行构成的图形的问题。R创建一个行图

数据
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 

该矩阵包含来自6个不同的时间4个样本蜱(V1-V6)。 我基本上想要一个散点图显示4条不同的线,它们在Y轴上的值和X轴上的6个“时间滴答”。为此,我只想要点和信任带的“点”和“平均线”。我之前已经完成了这个工作,但我不知道如何处理不同行上的每个样本。

+0

请分享你已经到目前为止已经试过。 –

+0

你能举个例子吗?我有点困惑。 –

+0

你的意思是像'matplot(testdata,t =“l”,lty = 1)'吗? – nico

回答

5

要达到这样的你给了Excel情节例如,你可以这样做:

matplot(t(testdata), t="b", pch=c(18, 15, 17, 4), lty=1, col=c("blue", "red", "green", "purple"), lwd=2) 

enter image description here

继@nico建议,你也可以使用type="o",如果你想连续线:

matplot(t(testdata), t="o", pch=c(18, 15, 17, 4), lty=1, col=c("blue", "red", "green", "purple"), lwd=2) 

enter image description here

+0

一个很小的事情:使用'type =“o “'给出更好看的情节,因为它不会破坏行:) – nico

+0

@nico感谢您的提示! :-)我编辑了我的答案以添加选项 – Cath

4

在基本绘图系统的另一种选择:

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) 

enter image description here

+0

'matplot'是基础绘图系统。 –

+0

这就是为什么我说“另一个”...... ;-) –

+1

你也可以将各种'线路'调用包装成'apply'单行 – nico