簡體   English   中英

ggplot每組只包含一個觀察

[英]ggplot each group consists of only one observation

我正在嘗試制作類似於這個答案的情節: 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?

我不知道我在做什么與上面鏈接的答案有所不同。 我應該改變什么來使這項工作?

group = samples添加到geom_lineaes中。 這是必要的,因為您希望每個samples一行而不是每個數據點。

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

在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM