5

I have this dataframe (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

Using ggplot, I'm trying to get a line for every single day where axis x = time, so in R I wrote:

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. Graph from R

And this is an Excel graph. This is the one I'm looking for. A different line for every single day:

enter image description here

I do not know how to tell R to join dots from same day... What's wrong? What am I missing?

One more thing: As I have data from more than 5 years, I would prefer a one-color plot.

Thanks for your help!

1
  • Add colour=factor(day) instead Commented Jan 5, 2014 at 1:00

2 Answers 2

9

add group aes:

ggplot(df, aes(x=time, y=value, colour=day,group=day)) + geom_line()
Sign up to request clarification or add additional context in comments.

Comments

1

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()

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.