I am trying to expand my own answer to the drawing of the Gantt chart in a more general case. I will illustrate a partial result here:
This diagram shows several trips with red dots representing deviations, and the green dots return. Now here is my task:
- I would like to mark all the days between departure and return with a gray dot and leave everyone else untouched.
- I would like the dots to correctly wrap the different months (for example, leaving June 28 would mean days until June 30, and then wrap around July 1).
- The script should not fail in the case of a one-day trip (for example, a trip in early September, where check-out and return take place on the same day, and a smaller green dot is displayed on a large red marker).
It is trivial to create this graph using the code below, and it would be easy to connect the dots with a line from red to green, where both will happen in the same month. Can someone help in case of a wrapping in the form of a general enough to take on also jumps and non-leap years, etc.?
library("ggplot2") # ---------------- # LOAD DATA df <- read.table(text='id,dep_month,dep_day,ret_month,ret_day c,1,5,1,16 v,2,1,2,6 a,3,28,3,31 z,4,9,4,11 y,4,25,5,3 f,6,28,7,7 w,8,19,8,29 b,9,9,9,9 k,9,29,10,6 n,11,20,12,3', header = TRUE, sep = ',') # ---------------- # DRAW YEAR CHART p <- ggplot(data = df, aes(x = dep_day, y = dep_month ) ) p <- p + theme_bw() p <- p + geom_point(colour = 'red', size = 6) p <- p + geom_point(aes(x = ret_day, y = ret_month ), colour = 'green', size = 4 ) p <- p + scale_x_continuous( breaks = c(1:31) ) p <- p + scale_y_reverse( breaks = c(1:12) ) p <- p + ylab("Month") + xlab("Day") print(p)