0

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). 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. I'm trying to use ggplot2, and am having trouble with the syntax. 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. Do you need to adjust the group aesthetic?

What am I missing?

1 Answer 1

1

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?

enter image description here

Sign up to request clarification or add additional context in comments.

6 Comments

When I run this it gives me lines going straight across for each age. Instead I'm looking for values to have peaks and valleys based on value amounts.
I added the image for the plot output. It's plotting the values in your dataframe.
Ah, I typed the wrong vector in my y axis. Much better! One more question: how are you getting the color to show? Mine is all monochromatic.
Well, I'm just fumbling around tonight. I got it straight. Thanks so much, jalapic!
I'm going to check up on factor() next, but can you explain why that's necessary?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.