0

I have data with id, start time, and end time.

ID start_time end_time 1 2017-12-29 03:52:06 2017-12-29 04:56:00 2 2017-12-29 04:12:34 2017-12-29 04:44:00 3 2017-12-29 04:24:36 2017-12-29 05:26:00 4 2017-12-29 04:30:00 2017-12-29 06:24:00 5 2017-12-29 04:33:28 2017-12-29 06:00:00 6 2017-12-29 04:52:08 2017-12-29 06:07:00 7 2017-12-29 05:13:48 2017-12-29 06:33:00 8 2017-12-29 05:33:53 2017-12-29 06:39:00 9 2017-12-29 05:40:00 2017-12-29 07:15:00 10 2017-12-29 05:30:40 2017-12-29 07:00:00 11 2017-12-29 06:08:15 2017-12-29 07:31:00 12 2017-12-29 06:12:33 2017-12-29 07:25:00 

If I plot these time intervals, it looks like as follows:

library(ggplot2) ggplot(time_day1) + aes(x = start_time, xend = end_time, y = id, yend=id, colour = id) + geom_segment() + geom_point() + geom_point(aes(x = end_time )) + xlab("Time") + theme_bw() 

enter image description here

what I would like to plot is the series of the number of observations(ids) with the same x-axis (time) as a time-series plot. I'd appreciate if you provide the appropriate approach for this.

1
  • Please consider accepting my answer if it was the solution to your problem or give further information if it wasn't. Commented May 30, 2021 at 14:50

1 Answer 1

1

I edited your post, so that the variables in the data and function match.

To change the appearance of the x-axes, you can use scale_x_datetime(date_labels = "%d.%m.%Y"). In this case the colums start_time/first_time and end_time/last_time have to be of class POSIXct.

To read more about it see the R Graph Gallery or the official reference of the tidyverse/ggplot2 packages.

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

1 Comment

Thank you for the answer! It was slightly different from what I asked, but it was helpful and I solved the issue! Thank you !!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.