[英]Plot multiple lines from dataframe in R
I have some data in a single dataframe. 我在单个数据框中有一些数据。 It represents several days' worth of data broken down by age within each day.
它代表每天中按年龄细分的几天的数据价值。 What I'm looking to do is plot the Value (data points) for each age (y axis) by day (x axis).
我要做的是按天(x轴)绘制每个年龄(y轴)的值(数据点)。 The frame is set up like this:
框架设置如下:
Age day Value
1 13 15 139
2 14 15 198
3 15 15 287
4 16 15 404
5 17 15 439
6 18 15 323
7 19 15 255
8 13 16 135
9 14 16 202
10 15 16 309
11 16 16 380
12 17 16 451
13 18 16 366
14 19 16 256
15 13 17 117
16 14 17 208
17 15 17 303
18 16 17 392
19 17 17 410
20 18 17 359
21 19 17 246
Thus, 13 would plot from 139 to 135 to 117 over the three day period. 因此,在三天的时间里,13将从139到135到117绘制。 I'm trying to use ggplot2, and am having trouble with the syntax.
我正在尝试使用ggplot2,但语法有问题。 The end result should plot lines with different color by age.
最终结果应按年龄绘制不同颜色的线。
So far I've tried this: 到目前为止,我已经尝试过了:
ggplot(d, aes(x=day, y=Age, color=Value, group=Age)) + geom_line()
But this yields an empty plot and this error message: geom_path: Each group consist of only one observation. 但是,这将产生一个空图并显示以下错误消息: geom_path:每个组仅包含一个观察值。 Do you need to adjust the group aesthetic?
您是否需要调整小组审美?
What am I missing? 我想念什么?
Not quite sure by your wording what you're after... 用您的措辞不太确定所追求的...
I think it's this... 我想就是这个
ggplot(df, aes(day, Value, group=factor(Age), color=factor(Age))) + geom_line()
plots days vs Value with separate lines being each Age? 绘制天数与价值的关系,每个年龄段都用单独的行?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.