R: 绘图在时间序列中复制



准备一个愚蠢的问题。。。

我有一大组数据,看起来有点像这样。。

structure(list(V1 = structure(c(4L, 3L, 6L, 5L, 1L, 2L), .Label = c("1012", 
"225", "58", "602", "62", "818"), class = "factor"), V2 = structure(c(4L, 
3L, 6L, 5L, 1L, 2L), .Label = c("1012", "249", "58", "603", "62", 
"824"), class = "factor"), V3 = structure(c(6L, 2L, 5L, 4L, 1L, 
3L), .Label = c("1014", "117", "290", "442", "831", "992"), class = "factor"), 
V4 = structure(c(6L, 3L, 5L, 2L, 1L, 4L), .Label = c("1033", 
"1055", "166", "377", "831", "992"), class = "factor"), V5 = structure(c(3L, 
4L, 6L, 2L, 1L, 5L), .Label = c("1033", "1067", "1575", "190", 
"378", "832"), class = "factor"), V6 = structure(c(3L, 4L, 
6L, 2L, 1L, 5L), .Label = c("1034", "1069", "1575", "221", 
"379", "833"), class = "factor"), V7 = structure(c(3L, 5L, 
6L, 2L, 1L, 4L), .Label = c("1063", "1092", "2351", "379", 
"406", "834"), class = "factor")), .Names = c("V1", "V2", 
"V3", "V4", "V5", "V6", "V7"), class = "data.frame", row.names = c(NA, 
6L))

每一行代表一个受试者,每一个沿着列移动的值代表一个会话中老鼠按下杠杆的时间(以秒为单位)。我想用ggplot做一个类似的数字。然而,我似乎不知道如何绘制时间序列,因为ggplot似乎想要一个离散的、命名为x和y的时间序列。我可以想出劳动密集型的方法来让它发挥作用,但我知道我只是错过了一些简单的东西。

DWin在上面的评论中提供了答案。我想我可以扩展一下,以防有人因为同样缺乏经验而偶然发现这一点。我的解决方案是安装reshapeGUI包,作为学习参数结构的一种快速方法。

加载GUI后,我获取了上面的数据,将行号放入一个名为"主题"的新列中,并运行以下

test.melt <- melt(data = test, id.vars=c('Subjects'),     
measure.vars=c('V1','V2','V3','V4','V5','V6','V7'))

这给了我一个下面描述的结构,它很容易绘制成一个时间序列,显示每个复制品/受试者的值。。。

structure(list(subject = c("1", "2", "3", "4", "5", "6", "1", 
"2", "3", "4", "5", "6", "1", "2", "3", "4", "5", "6", "1", "2", 
"3", "4", "5", "6", "1", "2", "3", "4", "5", "6", "1", "2", "3", 
"4", "5", "6", "1", "2", "3", "4", "5", "6"), response = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 
3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L), .Label = c("V1", "V2", "V3", 
"V4", "V5", "V6", "V7"), class = "factor"), time = c("602", "58", 
"818", "62", "1012", "225", "603", "58", "824", "62", "1012", 
"249", "992", "117", "831", "442", "1014", "290", "992", "166", 
"831", "1055", "1033", "377", "1575", "190", "832", "1067", "1033", 
"378", "1575", "221", "833", "1069", "1034", "379", "2351", "406", 
"834", "1092", "1063", "379")), .Names = c("subject", "response", 
"time"), row.names = c(NA, -42L), class = "data.frame")

谢谢DWin。

最新更新