-
Notifications
You must be signed in to change notification settings - Fork 0
/
planner.Rmd
505 lines (390 loc) · 17.8 KB
/
planner.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
---
title: "Get started"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Get started}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r include=FALSE}
knitr::opts_chunk$set(collapse = TRUE,
echo = TRUE,
eval = FALSE,
comment = "#>",
out.width = "100%",
dpi = 96,
fig.align = "center")
```
The R package `planner` is dedicated to create ready to print calendars. Calendars are saved as PDF files in the A4 paper format. User can add various information: holidays (several countries available), moon phases, custom events (single-day, multi-day and multi-week events), and special days (like birthdays, etc.).
This vignette shows how to customize calendars.
First, let's import the package.
```{r setup, eval=TRUE}
library("planner")
```
## Monthly calendar
The function `monthly_calendar()` creates a monthly calendar. Two arguments are mandatory and must be set by the user: `year` and `month`.
```{r 'default-settings'}
monthly_calendar(year = 2024,
month = 4)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Default settings", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-01.png")
```
By default, the calendar is exported as `calendar-2024-04.pdf` in the current working directory. Use the argument `path` to change the destination and the argument `filename` to rename the PDF file.
### Working week
If you want to remove Saturdays and Sundays, add `weekend = FALSE`. This will produce a calendar with working weeks.
```{r 'working-week'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Working weeks", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-02.png")
```
### Moon phases
You can add moon phases by setting the argument `moon` to `TRUE`. Only full moons (empty circles), new moons (black circles), first and third quarters are available. You need an Internet connection when using `moon = TRUE` to scrap the website <https://www.timeanddate.com/moon/phases/>.
```{r 'moon-phases'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Moon phases", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-03.png")
```
### Holidays
The function `get_holidays()` can be used to retrieve holidays for a specific country and for given year and month. This function also requires an Internet connection to scrap the website <https://www.timeanddate.com/holidays/>.
```{r 'get-holidays'}
holidays <- get_holidays(year = 2024,
month = 4,
country = "UK")
holidays
#> date name type
#> 1 2024-04-01 Easter Monday Common Local Holiday
#> 2 2024-04-05 Laylatul Qadr (Night of Power) Muslim
#> 3 2024-04-10 Eid ul Fitr (Tentative Date) Muslim
#> 4 2024-04-22 Stephen Lawrence Day Observance
#> 5 2024-04-23 First day of Passover Jewish Holiday
#> 6 2024-04-30 Last day of Passover Jewish Holiday
```
The output contains different types of holidays (field `type`) which may vary by country. To add this information to the monthly calendar, use the argument `holidays`.
```{r 'holidays-1'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - UK Holidays", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-04.png")
```
Note the position of holidays on the calendar and the background of cells: data pass to the argument `holidays` will always be added at the top of cells.
<br />
You can filter holidays by types with the function `filter_holidays()`.
```{r 'filter-holidays'}
holidays <- filter_holidays(data = holidays,
types = "Common Local Holiday")
holidays
#> date name type
#> 1 2024-04-01 Easter Monday Common Local Holiday
```
**Tip:** to get available types for the selected country, have a look at the function `get_holiday_types()`.
```{r 'holidays-2'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - UK Holidays (filtered)", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-05.png")
```
Note that you can create your own holidays (days off) and pass the `data.frame` to the `holidays` argument of the function `monthly_calendar()`. Only two columns are required: `date` and `name`.
### Special events
You can also use the argument `specials` of the function `monthly_calendar()` to add _special days_, like birthdays. There will be added at the bottom of the cell (with a glyph).
Let's create two special dates:
```{r 'get-birthdays'}
birthdays <- data.frame("date" = c("2024-04-11", "2024-04-17"),
"name" = c("John's birthday", "Jane's birthday"))
birthdays
#> date name
#> 1 2024-04-11 John's birthday
#> 2 2024-04-17 Jane's birthday
```
```{r 'birthdays'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays,
specials = birthdays)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Special dates", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-06.png")
```
### Adding events
The package `planner` can deal with different calendar events:
- single-day events
- multi-day events
- multi-week events
To add these events to a monthly calendar you can use the argument `events` of the function `monthly_calendar()` that requires a `data.frame` with the following columns:
- `name`: the name of the event,
- `from`: the starting date of the event,
- `to`: the ending date of the event.
#### Single-day events
Let's add single-day events. First, we will create four events for the April 2, 2024.
```{r 'get-single-day-events'}
events <- data.frame()
events <- rbind(events,
data.frame("name" = "Single-day event 1",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events <- rbind(events,
data.frame("name" = "Single-day event 2",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events <- rbind(events,
data.frame("name" = "Single-day event 3",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events <- rbind(events,
data.frame("name" = "Single-day event 4",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events
#> name from to
#> 1 Single-day event 1 2024-04-02 2024-04-02
#> 2 Single-day event 2 2024-04-02 2024-04-02
#> 3 Single-day event 3 2024-04-02 2024-04-02
#> 4 Single-day event 4 2024-04-02 2024-04-02
```
Of course, you can store your events in a file (CSV, Excel, etc.) and read it from R. You just need to name the columns according to the structure of the `events` object (as shown above).
Let's add these events to the calendar with the argument `events`.
```{r 'single-day-events'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays,
specials = birthdays,
events = events)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Single-day events", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-07.png")
```
You can omit the ending date for single-day events. In that case, the event will be displayed as a bullet point.
```{r 'get-single-day-events-2'}
## Add a bullet point event ----
events <- rbind(events,
data.frame("name" = "Single-day event 5",
"from" = "2024-04-03",
"to" = NA))
events
#> name from to
#> 1 Single-day event 1 2024-04-02 2024-04-02
#> 2 Single-day event 2 2024-04-02 2024-04-02
#> 3 Single-day event 3 2024-04-02 2024-04-02
#> 4 Single-day event 4 2024-04-02 2024-04-02
#> 5 Single-day event 5 2024-04-03 <NA>
```
```{r 'single-day-event-2'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays,
specials = birthdays,
events = events)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Single-day events (bis)", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-08.png")
```
#### Multi-day events
The logic is the same for multi-day events. Let's create new calendar events.
```{r 'get-multi-day-events'}
events <- data.frame()
events <- rbind(events,
data.frame("name" = "Multi-day event 1",
"from" = "2024-04-02",
"to" = "2024-04-03"))
events <- rbind(events,
data.frame("name" = "Multi-day event 2",
"from" = "2024-04-02",
"to" = "2024-04-05"))
events <- rbind(events,
data.frame("name" = "Single-day event 1",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events <- rbind(events,
data.frame("name" = "Single-day event 2",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events <- rbind(events,
data.frame("name" = "Single-day event 3",
"from" = "2024-04-03",
"to" = NA))
events
#> name from to
#> 1 Multi-day event 1 2024-04-02 2024-04-03
#> 2 Multi-day event 2 2024-04-02 2024-04-05
#> 3 Single-day event 1 2024-04-02 2024-04-02
#> 4 Single-day event 2 2024-04-02 2024-04-02
#> 5 Single-day event 3 2024-04-03 <NA>
```
```{r 'multi-day-event'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays,
specials = birthdays,
events = events)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Multi-day events", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-09.png")
```
#### Multi-week events
Multi-week events are also supported.
```{r 'get-multi-week-events'}
events <- data.frame()
events <- rbind(events,
data.frame("name" = "Multi-day event 1",
"from" = "2024-04-02",
"to" = "2024-04-03"))
events <- rbind(events,
data.frame("name" = "Multi-day event 2",
"from" = "2024-04-02",
"to" = "2024-04-05"))
events <- rbind(events,
data.frame("name" = "Single-day event 1",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events <- rbind(events,
data.frame("name" = "Single-day event 2",
"from" = "2024-04-02",
"to" = "2024-04-02"))
events <- rbind(events,
data.frame("name" = "Single-day event 3",
"from" = "2024-04-03",
"to" = NA))
events <- rbind(events,
data.frame("name" = "Multi-week event 1",
"from" = "2024-04-09",
"to" = "2024-04-23"))
events
#> name from to
#> 1 Multi-day event 1 2024-04-02 2024-04-03
#> 2 Multi-day event 2 2024-04-02 2024-04-05
#> 3 Single-day event 1 2024-04-02 2024-04-02
#> 4 Single-day event 2 2024-04-02 2024-04-02
#> 5 Single-day event 3 2024-04-03 <NA>
#> 6 Multi-week event 1 2024-04-09 2024-04-23
```
```{r 'multi-week-event'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays,
specials = birthdays,
events = events)
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Multi-week events", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-10.png")
```
The **vertical order of events by day** follow these rules: events are ordered by duration (number of days by week), then by ending date (bullet-point events are added after boxed-events), and finally by event names.
For readability purposes, **the number of events by day is limited to four** (special days included).
### Colors
The argument `palette` of the `monthly_calendar()` allows you to change the color of events (box background and bullet point). By providing only **one color** all events will be colored the same way.
```{r 'change-color'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays,
specials = birthdays,
events = events,
palette = "#990000")
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Customize colors", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-11.png")
```
In `planner` it's possible to categorize events and to attribute a specific color to each category. First you need to add a new column, named `category`, in the `events` `data.frame`.
```{r 'category-argument'}
## Events with category ----
events <- data.frame()
events <- rbind(events,
data.frame("name" = "Multi-day event 1",
"from" = "2024-04-02",
"to" = "2024-04-03",
"category" = "A"))
events <- rbind(events,
data.frame("name" = "Multi-day event 2",
"from" = "2024-04-02",
"to" = "2024-04-05",
"category" = "B"))
events <- rbind(events,
data.frame("name" = "Single-day event 1",
"from" = "2024-04-02",
"to" = "2024-04-02",
"category" = "A"))
events <- rbind(events,
data.frame("name" = "Single-day event 2",
"from" = "2024-04-02",
"to" = "2024-04-02",
"category" = "A"))
events <- rbind(events,
data.frame("name" = "Single-day event 3",
"from" = "2024-04-03",
"to" = NA,
"category" = "B"))
events <- rbind(events,
data.frame("name" = "Multi-week event 1",
"from" = "2024-04-09",
"to" = "2024-04-23",
"category" = "C"))
events
#> name from to category
#> 1 Multi-day event 1 2024-04-02 2024-04-03 A
#> 2 Multi-day event 2 2024-04-02 2024-04-05 B
#> 3 Single-day event 1 2024-04-02 2024-04-02 A
#> 4 Single-day event 2 2024-04-02 2024-04-02 A
#> 5 Single-day event 3 2024-04-03 <NA> B
#> 6 Multi-week event 1 2024-04-09 2024-04-23 C
```
To associate a specific color to each event category, the argument `palette` must contain as many colors as there are event categories. Moreover, the `palette` argument must be a **named vector**, where names match event categories.
```{r 'change-color-2'}
monthly_calendar(year = 2024,
month = 4,
weekend = FALSE,
moon = TRUE,
holidays = holidays,
specials = birthdays,
events = events,
palette = c("A" = "#00356a",
"B" = "#990000",
"C" = "#a17900"))
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Customize colors (bis)", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-12.png")
```
### Calendar language
Finally, it's possible to change the language of the calendar (only day and month names are supported) with the argument `lang`. Not all languages are supported, and the rendering depends on your system encoding and OS.
```{r 'finnish'}
monthly_calendar(year = 2024,
month = 4,
lang = "Finnish")
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Customize language (Finnish)", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-13.png")
```
```{r 'greek'}
monthly_calendar(year = 2024,
month = 4,
lang = "Greek")
```
```{r echo=FALSE, eval=TRUE, out.width="100%", fig.cap = "Monthly calendar - Customize language (Greek)", fig.align='center'}
knitr::include_graphics("figures/calendar-demo-14.png")
```
## Annual calendar
Not implemented yet...