简体   繁体   English

ggplot来自同一数据帧的多线图

[英]ggplot Multi line plot from same dataframe

I have this dataframe (df) : 我有这个数据帧(df):

  day     time      value
20011101    93000 1.00000000
20011102    93000 1.00000000
20011105    93000 1.00000000
20011101   100000 0.81958763
20011102   100000 0.95412844
20011105   100000 0.27610209
20011101   103000 0.27835052
20011102   103000 0.32415902
20011105   103000 0.77958237
20011101   110000 0.23711340

Sample here: https://www.dropbox.com/s/y7mtcay6ke9ydnm/sample.txt 此处示例: https//www.dropbox.com/s/y7mtcay6ke9ydnm/sample.txt

Using ggplot, I'm trying to get a line for every single day where axis x = time, so in RI wrote: 使用ggplot,我试图在轴x =时间的每一天获得一条线,所以在RI中写道:

ggplot(df, aes(x=time, y=value, colour=day)) + geom_line()

Unfortunately, this is what I got. 不幸的是,这就是我得到的。 I did not expect a plot like this. 我没想到会有这样的情节。 来自R的图表

And this is an Excel graph. 这是一个Excel图表。 This is the one I'm looking for. 这是我正在寻找的那个。 A different line for every single day: 每一天都有不同的一行:

在此输入图像描述

I do not know how to tell R to join dots from same day... What's wrong? 我不知道怎么告诉R从同一天加入点......怎么了? What am I missing? 我错过了什么?

One more thing: As I have data from more than 5 years, I would prefer a one-color plot. 还有一件事:由于我有超过5年的数据,我更喜欢单色情节。

Thanks for your help! 谢谢你的帮助!

添加group aes:

ggplot(df, aes(x=time, y=value, colour=day,group=day)) + geom_line()

Convert your day to a factor, it's being treated as continuous right now. 将您的一天转换为一个因素,它现在被视为连续的。

df$day <- as.factor(df$day)
ggplot(df, aes(x=time, y=value, colour=day)) + geom_line()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM