0

I have the following DataSet given:

    intervall_start     intervall_ende      variable        value   time
0   2019-08-01 05:00:00 2019-08-01 05:15:00 Door_1          30.0    5.00
1   2019-08-01 05:15:00 2019-08-01 05:30:00 Door_1          55.0    5.25
2   2019-08-01 05:45:00 2019-08-01 06:00:00 Door_2          114.0   5.75
3   2019-08-01 06:00:00 2019-08-01 06:15:00 Door_1          84.0    6.00
4   2019-08-01 06:15:00 2019-08-01 06:30:00 Door_2          23.0    6.25
... 

When I run pn.ggplot(df, pn.aes(x="time", y="value", colour="variable")) + pn.geom_point(stat="identity") + pn.theme(axis_text_x = pn.element_text(angle=90)) it gives me this plot:

enter image description here

When I run the plotnine line with geom_line instead of geom_point I get this plot: enter image description here

But this is not what I want! My DataFrame contains many values from the 2018-08-01 to the 2018-08-31. The column time is the time for each day independent from the date it happend. My goal is now to print one line for each time. So I would get 96 lines. Why 96? Because I have a 15min interval and the day has 24 hours -> 24 * 4 = 96.

And this plot should be grouped by variable so I know to which variable the line belongs. How can I do this?

This is what I want to have at the end. I want to have one line for each day by time and value. The color should illustrate the variable! Take a look on the x axis, this goes from 0 to 24 because the day has 24 hours. And the column time gives us this the time of the day!

enter image description here

Kind regards

Jan
  • 1,180
  • 3
  • 23
  • 60

1 Answers1

0

Without the actual data it is hard give you in depth help, please refer to this site for a guide for a great reproducible example. I used the data you posted and duplicated it with some changes in value to illustrate the solution. If you define the time variable as group in geom_line it produces something close to what you want. I am not sure if there are further complications with your original data for that you would have to create a reproducible example.

    df = tibble::tribble(
       ~intervall_start, ~intervall_ende, ~variable, ~value, ~time,
  "2019-08-01 05:00:00","2019-08-01 05:15:00", "Door_1", 30.0, 5.00,
  "2019-08-01 05:15:00","2019-08-01 05:30:00", "Door_1", 55.0, 5.25,
  "2019-08-01 05:45:00","2019-08-01 06:00:00", "Door_2", 114.0, 5.75,
  "2019-08-01 06:00:00","2019-08-01 06:15:00", "Door_1", 84.0, 6.00,
  "2019-08-01 06:15:00","2019-08-01 06:30:00", "Door_2", 23.0, 6.25,
  "2019-08-01 05:00:00","2019-08-01 05:15:00", "Door_1", 31.0, 5.00,
  "2019-08-01 05:15:00","2019-08-01 05:30:00", "Door_1", 51.0, 5.25,
  "2019-08-01 05:45:00","2019-08-01 06:00:00", "Door_2", 111.0, 5.75,
  "2019-08-01 06:00:00","2019-08-01 06:15:00", "Door_1", 81.0, 6.00,
  "2019-08-01 06:15:00","2019-08-01 06:30:00", "Door_2", 21.0, 6.25,
  "2019-08-01 05:00:00","2019-08-01 05:15:00", "Door_1", 33.0, 5.00,
  "2019-08-01 05:15:00","2019-08-01 05:30:00", "Door_1", 53.0, 5.25,
  "2019-08-01 05:45:00","2019-08-01 06:00:00", "Door_2", 113.0, 5.75,
  "2019-08-01 06:00:00","2019-08-01 06:15:00", "Door_1", 83.0, 6.00,
  "2019-08-01 06:15:00","2019-08-01 06:30:00", "Door_2", 23.0, 6.25
  )

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

enter image description here

EDIT: Are you after something like this? If not you have to create a reproducible example and explain again what you want.

ggplot(df, aes(x=intervall_start, xend = intervall_ende, y=value, yend=value, colour=variable)) +
  geom_segment()

enter image description here

Mojoesque
  • 1,166
  • 8
  • 15
  • But why get I a range on the x axias? I want to have a line on the y axias for each entry and not a range! – Jan Jul 28 '20 at 12:08
  • I am not sure I understand. In my example you get a line in the y-axis direction. Is this not what you mean? If you post a reproducible example (part of your data and the corresponding plots) I can help you better. See the link I posted. – Mojoesque Jul 28 '20 at 12:13
  • Know, I want to have a line for each entry in the y-axis :) – Jan Jul 28 '20 at 13:38
  • Have a look at the edit if this is what you had in mind. Otherwise you need to explain more / create the reproducible example. – Mojoesque Jul 28 '20 at 13:52
  • no, thats ok. But why aren't those lines connected? – Jan Jul 28 '20 at 14:20
  • Because it is done with 'geom_segment' not 'geom_line" – Mojoesque Jul 28 '20 at 14:48
  • Okay, this now works. But how can I do this with time instead of interval? – Jan Jul 28 '20 at 14:58
  • As I said please create a reproducible example. I don't know what you mean by doing this with time. There is only one timepoint per line. How is that supposed to become a line on the plot? – Mojoesque Jul 28 '20 at 14:59
  • My fault, I have added a picture and a description of what I want! :) – Jan Jul 28 '20 at 15:09
  • If you want one line per day, try to create a column with only the days extracted from the start / end column and use that as the group aesthetic in the call to `geom_line`. – Mojoesque Jul 29 '20 at 07:15