Plotnine graphing melted dataframe as 2 separate lines

42 Views Asked by At

I am trying to graph a melted dataframe, as shown here:

    SleepDay                category            value
0   4/12/2016 12:00:00 AM   TotalMinutesAsleep  750
1   4/13/2016 12:00:00 AM   TotalMinutesAsleep  398
2   4/15/2016 12:00:00 AM   TotalMinutesAsleep  475
3   4/26/2016 12:00:00 AM   TotalMinutesAsleep  296
4   4/28/2016 12:00:00 AM   TotalMinutesAsleep  166
5   4/12/2016 12:00:00 AM   TotalTimeInBed      775
6   4/13/2016 12:00:00 AM   TotalTimeInBed      422
7   4/15/2016 12:00:00 AM   TotalTimeInBed      499
8   4/26/2016 12:00:00 AM   TotalTimeInBed      315
9   4/28/2016 12:00:00 AM   TotalTimeInBed      178

This is my code so far:

ggplot(long_data, aes(x='SleepDay', y='value', color = "category")) +\
    geom_line(aes(group = 1)) +\
    theme(axis_text_x=element_text(rotation=75, hjust=1))

Graphing it gives me the following: https://i.stack.imgur.com/bq29T.png

I have no clue how to separate the lines.

1

There are 1 best solutions below

2
On BEST ANSWER

aes(group=1) says all the rows in the data are assigned to group 1. This overrides the global grouping that depends on the category, so all the points fall on the same line!

The solution is to remove group=1.