ggplot每组只包含一个观察

时间:2014-01-24 16:02:18

标签: r plot ggplot2

我试图制作类似于这个答案的情节:https://stackoverflow.com/a/4877936/651779

我的数据框如下所示:

df2 <- read.table(text='measurements samples value
1        4hours   sham1     6
2          1day   sham1   175
3         3days   sham1   417
4         7days   sham1   163
5        14days   sham1    37
6        90days   sham1   134
7        4hours   sham2     8
8          1day   sham2   402
9         3days   sham2   482
10        7days   sham2    67
11       14days   sham2    16
12       90days   sham2    31
13       4hours   sham3   185
14         1day   sham3   402
15        3days   sham3   482
16        7days   sham3    85
17       14days   sham3    29
18       90days   sham3    10',header=T)

绘制
ggplot(df2, aes(measurements, value)) + geom_line(aes(colour = samples))

情节中没有显示任何行,我收​​到消息

geom_path: Each group consist of only one observation. 
Do you need to adjust the group aesthetic?

我不知道我在做什么与我上面提到的答案有所不同。我应该改变什么来使这项工作?

1 个答案:

答案 0 :(得分:27)

group = samples添加到aes的{​​{1}}。这是必要的,因为您需要每行geom_line一行而不是每个数据点。

samples

enter image description here