I am plotting weekly figures that cross over from 2018 into 2019 and the tick marks on my X-axis represent the year then week.
For example:
2018-50, 2018-51, 2018-52, 2018-53, 2019-01, 2019-02, 2019-03
I have two data frames and the dates in either aren't always going to be the same. As such, one solution I have thought of that might work is to find the lowest yearWeek
value in either data frame, and the maximum yearWeek
value in either data frame, and to then create a sequence using those two values. Note that both values could either exist within a single data frame or one data frame could have the lowest/earliest value and the other the highest/latest value.
Both data frames look like this:
week yearWeek month day date
1 31 2018-31 2018-08-01 Wed 2018-08-01
2 31 2018-31 2018-08-01 Thu 2018-08-02
3 31 2018-31 2018-08-01 Fri 2018-08-03
4 31 2018-31 2018-08-01 Sat 2018-08-04
5 32 2018-32 2018-08-01 Sun 2018-08-05
6 32 2018-32 2018-08-01 Mon 2018-08-06
I have looked for a solution and this answer is almost there, but not quite.
The problems with this solution are:
- The single-figure week number don't have a
0
before them; and - Despite specifying
seq(31:53)
, for example, the output starts from1
(I know why this happens); and - There doesn't seem to be a way to stop the count at
53
using this method (2018 had a (short) 53rd week which I would like to include) and resume from2019-01
onwards.
I want to be able to set the X-axis range from 2018-31
(31st week of 2018) to 2019-13
(13th week of 2019).
Something like this:
In short, how can I create a sequence of year-week values ranging from the minimum date value to the maximum date value (in this case 2018-31
-2019-13
)?