0

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

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

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 制作一个类似于this的图。但是我似乎无法弄清楚如何绘制时间序列,因为 ggplot 似乎想要一个离散的,命名为 x 和 y。我可以想出一些劳动密集型的方法来让它工作,但我知道我只是错过了一些简单的东西。

4

1 回答 1

0

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

加载 GUI 后,我获取了上述数据,将行号放入一个名为“Subjects”的新列中,然后运行以下命令

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")

谢谢迪温。

于 2013-08-30T19:46:33.067 回答