ggplot每个组只包含一个观察值 [英] ggplot each group consists of only one observation
问题描述
我正在尝试制作类似于此答案的情节: https://stackoverflow.com/a/4877936/651779 我的数据框如下所示: 然后用 剧情中没有行显示,我收到消息 我不知道我在做什么与上面链接的答案不同。我应该改变什么来完成这项工作? 添加 I'm trying to make a plot similar to this answer: https://stackoverflow.com/a/4877936/651779 My data frame looks like this: And plot it with No lines show in the plot, and I get the message I don't see where what I'm doing is different from the answer I linked above. What should I change to make this work? Add 这篇关于ggplot每个组只包含一个观察值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
df2 < - read.table(text ='measurement values value
1 4hours sham1 6
2 1day sham1 175
3 3days sham1 417
4 7days sham1 163
5 14天sham1 37
6 90天sham1 134
7 4小时sham2 8
8 1day sham2 402
9 3days sham2 482
10 7天sham2 67
11 14天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 90天sham3 10',header = T)
ggplot(df2,aes(measurements,value))+ geom_line(aes(color = samples))
geom_path:每个组包含只有一个观察。
您是否需要调整团体美学?
group = samples
添加到 geom_line
的 aes
中。这是必要的,因为您需要每行 samples
而不是每个数据点的一行。
ggplot(df2,aes(测量值))+
geom_line(aes(color = samples,group = samples))
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
to the aes
of geom_line
. This is necessary since you want one line per samples
rather than for each data point.ggplot(df2, aes(measurements, value)) +
geom_line(aes(colour = samples, group = samples))