Hi, I'm a beginner trying to replicate my pen and paper timetracking graph.
Each task should be a line occupying the time in which it occurred. My problem are tasks that occur between two days, I would want them to show on their day and start again in the next one.
library(tidyverse)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
df <- tibble(
id = c(1,2,3,4),
name = c("studying", "gaming", "studying", "gaming"),
start = parse_datetime(c("2020-08-24T0900Z", "2020-08-24T1800Z", "2020-08-25T0900Z", "2020-08-25T1430Z")),
end = parse_datetime(c("2020-08-24T1300Z", "2020-08-25T0100Z", "2020-08-25T1300Z", "2020-08-25T1930Z"))
)
ggplot(df) + geom_segment(
aes(x = hour(start) + minute(start)/60,
y = date(start),
xend = hour(end) + minute(end)/60,
yend = date(end),
colour = name,
size = 1
)
)
I'm thinking duplicate problematic rows then change hour(end) to 23:59 in the first row and hour(start) to 00:00 in the second one, but I don't know how to do that.