rggplot2difftime

x axis not showing expected format using difftime and ggplot


I want to plot a time difference (diff) in days by a certain ID across facets with

example <- example %>%
  mutate(diff = difftime(ymd(date), ymd(phase_start), units = "days"))

ggplot(data = example) +
  geom_col(aes(x= as.numeric(diff), y = as.factor(project_id)), width= 0.1) +
  facet_wrap(~ phase_id, nrow = 1) 

However the x axis units do not seem to represent days although specified in difftime. I don't even know what scale it is showing, it should be something between 0 and 400 (days) - it is however 0 to 30000. Also, the difference appears rightly formatted in the data editor. I already tried different ways of calculating difftimes (i.e. convert to date and take the difference).

Graph

Please find a reproducable example below.

# A tibble: 6 x 5
  project_id phase_id date       phase_start diff
       <int>    <int> <chr>      <chr>       <drtn>       
1          0        0 2020-01-20 2020-01-20  0 days       
2          0        0 2020-01-21 2020-01-20  1 days       
3          0        0 2020-01-22 2020-01-20  2 days       
4          0        0 2020-01-23 2020-01-20  3 days       
5          0        0 2020-01-24 2020-01-20  4 days       
6          0        0 2020-01-27 2020-01-20  7 days   

structure(list(project_id = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L,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, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L), phase_id = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 2L, 2L, 2L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, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L), date = c("2020-01-20", "2020-01-21", "2020-01-22", 
"2020-01-23", "2020-01-24", "2020-01-27", "2020-01-28", "2020-01-29", 
"2020-01-30", "2020-01-31", "2020-02-03", "2020-02-04", "2020-02-05", 
"2020-02-06", "2020-02-07", "2020-02-10", "2020-02-11", "2020-02-12", 
"2020-02-13", "2020-02-14", "2020-02-17", "2020-02-18", "2020-02-19", 
"2020-02-20", "2020-02-21", "2020-02-24", "2020-02-25", "2020-02-26", 
"2020-02-27", "2020-02-28", "2020-03-02", "2020-03-03", "2020-03-04", 
"2020-03-05", "2020-03-06", "2020-03-09", "2020-03-10", "2020-03-11", 
"2020-03-12", "2020-03-13", "2020-03-16", "2020-03-17", "2020-03-18", 
"2020-03-19", "2020-03-20", "2020-03-23", "2020-03-24", "2020-03-25", 
"2020-03-26", "2020-03-27", "2020-03-30", "2020-03-31", "2020-04-01", 
"2020-04-02", "2020-04-03", "2020-04-06", "2020-04-07", "2020-04-08", 
"2020-04-09", "2020-04-10", "2020-04-13", "2020-04-14", "2020-04-15", 
"2020-04-16", "2020-04-17", "2020-04-20", "2020-04-21", "2020-04-22", 
"2020-04-23", "2020-04-24", "2020-04-27", "2020-04-28", "2020-04-29", 
"2020-04-30", "2020-05-01", "2020-05-04", "2020-05-05", "2020-05-06", 
"2020-05-07", "2020-05-08", "2020-05-11", "2020-05-12", "2020-05-13", 
"2020-05-14", "2020-05-15", "2020-05-18", "2020-05-19", "2020-05-20", 
"2020-05-21", "2020-05-22", "2020-05-25", "2020-05-26", "2020-05-27", 
"2020-05-28", "2020-05-29", "2020-06-01", "2020-06-02", "2020-06-03", 
"2020-06-04", "2020-06-05", "2020-06-08", "2020-06-09", "2020-06-10", 
"2020-06-11", "2020-06-12", "2020-06-15", "2020-06-16", "2020-06-17", 
"2020-06-18", "2020-06-19", "2020-06-22", "2020-06-23", "2020-06-24", 
"2020-06-25", "2020-06-26", "2020-06-29", "2020-06-30", "2020-07-01", 
"2020-07-02", "2020-07-03", "2020-07-06", "2020-07-07", "2020-07-08", 
"2020-07-09", "2020-07-10", "2020-07-13", "2020-07-14", "2020-07-15", 
"2020-07-16", "2020-07-17", "2020-07-20", "2020-07-21", "2020-07-22", 
"2020-07-23", "2020-07-24", "2020-07-27", "2020-07-28", "2020-07-29", 
"2020-07-30", "2020-07-31", "2020-08-03", "2020-08-04", "2020-08-05", 
"2020-08-06", "2020-08-07", "2020-08-10", "2020-08-11", "2020-08-12", 
"2020-08-13", "2020-08-14", "2020-08-17", "2020-08-18", "2020-08-19", 
"2020-08-20", "2020-08-21", "2020-08-24", "2020-08-25", "2020-08-26", 
"2020-08-27", "2020-08-28", "2020-08-31", "2020-09-01", "2020-09-02", 
"2020-09-03", "2020-09-04", "2020-09-07", "2020-09-08", "2020-09-09", 
"2020-09-10", "2020-09-11", "2020-09-14", "2020-09-15", "2020-09-16", 
"2020-09-17", "2020-09-18", "2020-09-21", "2020-09-22", "2020-09-23", 
"2020-09-24", "2020-09-25", "2020-09-28", "2020-09-29", "2020-09-30", 
"2020-10-01", "2020-10-02", "2020-10-05", "2020-10-06", "2020-10-07", 
"2020-10-08", "2020-10-09", "2020-10-12", "2020-10-13", "2020-10-14", 
"2020-10-15", "2020-10-16", "2020-10-19", "2020-10-20", "2020-10-21", 
"2020-10-22", "2020-10-23", "2020-10-26", "2020-10-27", "2020-10-28", 
"2020-10-29", "2020-10-30", "2020-11-02", "2020-11-03", "2020-11-04", 
"2020-11-05", "2020-11-06", "2020-11-09", "2020-11-10", "2020-11-11", 
"2020-11-12", "2020-11-13", "2020-11-16", "2020-11-17", "2020-11-18", 
"2020-11-19", "2020-11-20", "2020-11-23", "2020-11-24", "2020-11-25", 
"2020-11-26", "2020-11-27", "2020-11-30", "2020-12-01", "2020-12-02", 
"2020-12-03", "2020-12-04", "2020-12-07", "2020-12-08", "2020-12-09", 
"2020-12-10", "2020-12-11", "2020-12-14", "2020-12-15", "2020-12-16", 
"2020-12-17", "2020-12-18", "2020-12-21", "2020-12-22", "2020-12-23", 
"2020-12-24", "2020-12-25", "2020-12-28", "2020-12-29", "2020-12-30", 
"2020-12-31", "2021-01-01", "2021-01-04", "2021-01-05", "2021-01-06", 
"2021-01-07", "2021-01-08", "2021-01-11", "2021-01-12", "2021-01-13", 
"2021-01-14", "2021-01-15", "2021-01-18", "2021-01-19", "2021-01-20", 
"2021-01-21", "2021-01-22", "2021-01-25", "2021-01-26", "2021-01-27", 
"2021-01-28", "2021-01-29", "2021-02-01", "2021-02-02", "2021-02-03", 
"2021-02-04", "2021-02-05", "2021-02-08", "2021-02-09", "2021-02-10", 
"2021-02-11", "2021-02-12", "2021-02-15", "2021-02-16", "2021-02-17", 
"2021-02-18", "2021-02-19", "2021-02-22", "2021-02-23", "2021-02-24", 
"2021-02-25", "2021-02-26", "2021-03-01", "2020-02-03", "2020-02-04", 
"2020-02-05", "2020-02-06", "2020-02-07", "2020-02-10", "2020-02-11", 
"2020-02-12", "2020-02-13", "2020-02-14", "2020-02-17", "2020-02-18", 
"2020-02-19", "2020-02-20", "2020-02-21", "2020-02-24", "2020-02-25", 
"2020-02-26", "2020-02-27", "2020-02-28", "2020-03-02", "2020-03-03", 
"2020-03-04", "2020-03-05", "2020-03-06", "2020-03-09", "2020-03-10", 
"2020-03-11", "2020-03-12", "2020-03-13", "2020-03-16", "2020-03-17", 
"2020-03-18", "2020-03-19", "2020-03-20", "2020-03-23", "2020-03-24", 
"2020-03-25", "2020-03-26", "2020-03-27", "2020-03-30", "2020-03-31", 
"2020-04-01", "2020-04-02", "2020-04-03", "2020-04-06", "2020-04-07", 
"2020-04-08", "2020-04-09", "2020-04-10", "2020-04-13", "2020-04-14", 
"2020-04-15", "2020-04-16", "2020-04-17", "2020-04-20", "2020-04-21", 
"2020-04-22", "2020-04-23", "2020-04-24", "2020-04-27", "2020-04-28", 
"2020-04-29", "2020-04-30", "2020-05-01", "2020-05-04", "2020-05-05", 
"2020-05-06", "2020-05-07", "2020-05-08", "2020-05-11", "2020-05-12", 
"2020-05-13", "2020-05-14", "2020-05-15", "2020-05-18", "2020-05-19", 
"2020-05-20", "2020-05-21", "2020-05-22", "2020-05-25", "2020-05-26", 
"2020-05-27", "2020-05-28", "2020-05-29", "2020-06-01", "2020-06-02", 
"2020-06-03", "2020-06-04", "2020-06-05", "2020-06-08", "2020-06-09", 
"2020-06-10", "2020-06-11", "2020-06-12", "2020-06-15", "2020-06-16", 
"2020-06-17", "2020-06-18", "2020-06-19", "2020-06-22", "2020-06-23", 
"2020-06-24", "2020-06-25", "2020-06-26", "2020-06-29", "2020-06-30", 
"2020-07-01", "2020-07-02", "2020-07-03", "2020-07-06", "2020-07-07", 
"2020-07-08", "2020-07-09", "2020-07-10", "2020-07-13", "2020-07-14", 
"2020-07-15", "2020-07-16", "2020-07-17", "2020-07-20", "2020-07-21", 
"2020-07-22", "2020-07-23", "2020-07-24", "2020-07-27", "2020-07-28", 
"2020-07-29", "2020-07-30", "2020-07-31", "2020-08-03", "2020-08-04", 
"2020-08-05", "2020-08-06", "2020-08-07", "2020-08-10", "2020-08-11", 
"2020-08-12", "2020-08-13", "2020-08-14", "2020-08-17", "2020-08-18", 
"2020-08-19", "2020-08-20", "2020-08-21", "2020-08-24", "2020-08-25", 
"2020-08-26", "2020-08-27", "2020-08-28", "2020-08-31", "2020-09-01", 
"2020-09-02", "2020-09-03", "2020-09-04", "2020-09-07", "2020-09-08", 
"2020-09-09", "2020-09-10", "2020-09-11", "2020-09-14", "2020-09-15", 
"2020-09-16", "2020-09-17", "2020-09-18", "2020-09-21", "2020-09-22", 
"2020-09-23", "2020-09-24", "2020-09-25", "2020-09-28", "2020-09-29", 
"2020-09-30", "2020-10-01", "2020-10-02", "2020-10-05", "2020-10-06", 
"2020-10-07", "2020-10-08", "2020-10-09", "2020-10-12", "2020-10-13", 
"2020-10-14", "2020-10-15", "2020-10-16", "2020-10-19", "2020-10-20", 
"2020-10-21", "2020-10-22", "2020-10-23", "2020-10-26", "2020-10-27", 
"2020-10-28", "2020-10-29", "2020-10-30", "2020-11-02", "2020-11-03", 
"2020-11-04", "2020-11-05", "2020-11-06", "2020-11-09", "2020-11-10", 
"2020-11-11", "2020-11-12", "2020-11-13", "2020-11-16", "2020-11-17", 
"2020-11-18", "2020-11-19", "2020-11-20", "2020-11-23", "2020-11-24", 
"2020-11-25", "2020-11-26", "2020-11-27", "2020-11-30", "2020-12-01", 
"2020-12-02", "2020-12-03", "2020-12-04", "2020-12-07", "2020-12-08", 
"2020-12-09", "2020-12-10", "2020-12-11", "2020-12-14", "2020-12-15", 
"2020-12-16", "2020-12-17", "2020-12-18", "2020-12-21", "2020-12-22", 
"2020-12-23", "2020-12-24", "2020-12-25", "2020-12-28", "2020-12-29", 
"2020-12-30", "2020-12-31", "2021-01-01", "2021-01-04", "2021-01-05", 
"2021-01-06", "2021-01-07", "2021-01-08", "2021-01-11", "2021-01-12", 
"2021-01-13", "2021-01-14", "2021-01-15", "2021-01-18", "2021-01-19", 
"2021-01-20", "2021-01-21", "2021-01-22", "2021-01-25", "2021-01-26", 
"2021-01-27", "2021-01-28", "2021-01-29", "2021-02-01", "2021-02-02", 
"2021-02-03", "2021-02-04", "2021-02-05", "2021-02-08", "2021-02-09", 
"2021-02-10", "2021-02-11", "2021-02-12", "2021-02-15", "2021-02-16", 
"2021-02-17", "2021-02-18", "2021-02-19", "2021-02-22", "2021-02-23", 
"2021-02-24", "2021-02-25", "2021-02-26", "2021-03-01"), phase_start = c("2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", 
"2020-01-20", "2020-01-20", "2020-01-20", "2020-01-20", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", 
"2020-03-30", "2020-03-30", "2020-03-30", "2020-03-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", "2020-11-30", 
"2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", 
"2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", 
"2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", 
"2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", 
"2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", 
"2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", "2020-02-03", 
"2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", 
"2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", 
"2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", 
"2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", 
"2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", 
"2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", 
"2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", "2020-03-16", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", "2020-05-04", 
"2020-05-04"), time_in_phase = structure(c(0, 1, 2, 3, 4, 7, 
8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 23, 24, 25, 28, 29, 
30, 31, 32, 35, 36, 37, 38, 39, 42, 43, 44, 45, 46, 49, 50, 51, 
52, 53, 56, 57, 58, 59, 60, 63, 64, 65, 66, 67, 0, 1, 2, 3, 4, 
7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 23, 24, 25, 28, 
29, 30, 31, 32, 35, 36, 37, 38, 39, 42, 43, 44, 45, 46, 49, 50, 
51, 52, 53, 56, 57, 58, 59, 60, 63, 64, 65, 66, 67, 70, 71, 72, 
73, 74, 77, 78, 79, 80, 81, 84, 85, 86, 87, 88, 91, 92, 93, 94, 
95, 98, 99, 100, 101, 102, 105, 106, 107, 108, 109, 112, 113, 
114, 115, 116, 119, 120, 121, 122, 123, 126, 127, 128, 129, 130, 
133, 134, 135, 136, 137, 140, 141, 142, 143, 144, 147, 148, 149, 
150, 151, 154, 155, 156, 157, 158, 161, 162, 163, 164, 165, 168, 
169, 170, 171, 172, 175, 176, 177, 178, 179, 182, 183, 184, 185, 
186, 189, 190, 191, 192, 193, 196, 197, 198, 199, 200, 203, 204, 
205, 206, 207, 210, 211, 212, 213, 214, 217, 218, 219, 220, 221, 
224, 225, 226, 227, 228, 231, 232, 233, 234, 235, 238, 239, 240, 
241, 242, 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 
21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 35, 36, 37, 38, 39, 42, 
43, 44, 45, 46, 49, 50, 51, 52, 53, 56, 57, 58, 59, 60, 63, 64, 
65, 66, 67, 70, 71, 72, 73, 74, 77, 78, 79, 80, 81, 84, 85, 86, 
87, 88, 91, 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 
21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 35, 36, 37, 38, 39, 0, 
1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 23, 
24, 25, 28, 29, 30, 31, 32, 35, 36, 37, 38, 39, 42, 43, 44, 45, 
46, 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 16, 17, 18, 21, 22, 
23, 24, 25, 28, 29, 30, 31, 32, 35, 36, 37, 38, 39, 42, 43, 44, 
45, 46, 49, 50, 51, 52, 53, 56, 57, 58, 59, 60, 63, 64, 65, 66, 
67, 70, 71, 72, 73, 74, 77, 78, 79, 80, 81, 84, 85, 86, 87, 88, 
91, 92, 93, 94, 95, 98, 99, 100, 101, 102, 105, 106, 107, 108, 
109, 112, 113, 114, 115, 116, 119, 120, 121, 122, 123, 126, 127, 
128, 129, 130, 133, 134, 135, 136, 137, 140, 141, 142, 143, 144, 
147, 148, 149, 150, 151, 154, 155, 156, 157, 158, 161, 162, 163, 
164, 165, 168, 169, 170, 171, 172, 175, 176, 177, 178, 179, 182, 
183, 184, 185, 186, 189, 190, 191, 192, 193, 196, 197, 198, 199, 
200, 203, 204, 205, 206, 207, 210, 211, 212, 213, 214, 217, 218, 
219, 220, 221, 224, 225, 226, 227, 228, 231, 232, 233, 234, 235, 
238, 239, 240, 241, 242, 245, 246, 247, 248, 249, 252, 253, 254, 
255, 256, 259, 260, 261, 262, 263, 266, 267, 268, 269, 270, 273, 
274, 275, 276, 277, 280, 281, 282, 283, 284, 287, 288, 289, 290, 
291, 294, 295, 296, 297, 298, 301), class = "difftime", units = "days")), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -572L))

Solution

  • I am not sure if I understand what you want to plot. But when you do it in the way which you described, ggplot will sum up the diff time per project and phase. To see this, compare your plot with the following output:

    > example %>%
    +     group_by(phase_id, project_id) %>%
    +     summarise(s = sum(as.numeric(diff)))
    
    # A tibble: 6 x 3
    # Groups:   phase_id [3]
      phase_id project_id     s
         <int>      <int> <dbl>
    1        0          0  1675
    2        0         23   585
    3        2          0 21175
    4        2         23   805
    5        3          0  2951
    6        3         23 32336