class: center, middle, inverse, title-slide # More that You Can Do With Scales ## Dates, log, labels, breaks, color palettes ### Peter Higgins ### 2021-10-30 --- ### Customizing Plot Scales - Date scales can be tricky - you can use **scale_(x|y)_date()** - then you can set date_breaks to an interval - and format the dates with date_labels. These have specific codes --- count: false Demonstration 1: Select Variables, then Violin Plot .panel1-demo1-auto[ ```r *mdeaths ``` ] .panel2-demo1-auto[ ``` # A tibble: 72 × 5 deaths month year day date <dbl> <int> <dbl> <dbl> <date> 1 2134 1 1974 1 1974-01-01 2 1863 2 1974 1 1974-02-01 3 1877 3 1974 1 1974-03-01 4 1877 4 1974 1 1974-04-01 5 1492 5 1974 1 1974-05-01 6 1249 6 1974 1 1974-06-01 7 1280 7 1974 1 1974-07-01 8 1131 8 1974 1 1974-08-01 9 1209 9 1974 1 1974-09-01 10 1492 10 1974 1 1974-10-01 # … with 62 more rows ``` ] --- count: false Demonstration 1: Select Variables, then Violin Plot .panel1-demo1-auto[ ```r mdeaths %>% * ggplot(aes(x = date, y = deaths)) ``` ] .panel2-demo1-auto[ <img src="demo_microflip_files/figure-html/demo1_auto_02_output-1.png" width="432" /> ] --- count: false Demonstration 1: Select Variables, then Violin Plot .panel1-demo1-auto[ ```r mdeaths %>% ggplot(aes(x = date, y = deaths)) + * geom_line() ``` ] .panel2-demo1-auto[ <img src="demo_microflip_files/figure-html/demo1_auto_03_output-1.png" width="432" /> ] --- count: false Demonstration 1: Select Variables, then Violin Plot .panel1-demo1-auto[ ```r mdeaths %>% ggplot(aes(x = date, y = deaths)) + geom_line() + * theme_linedraw(base_size = 14) ``` ] .panel2-demo1-auto[ <img src="demo_microflip_files/figure-html/demo1_auto_04_output-1.png" width="432" /> ] --- count: false Demonstration 1: Select Variables, then Violin Plot .panel1-demo1-auto[ ```r mdeaths %>% ggplot(aes(x = date, y = deaths)) + geom_line() + theme_linedraw(base_size = 14) + * scale_x_date(date_breaks = "6 months") ``` ] .panel2-demo1-auto[ <img src="demo_microflip_files/figure-html/demo1_auto_05_output-1.png" width="432" /> ] --- count: false Demonstration 1: Select Variables, then Violin Plot .panel1-demo1-auto[ ```r mdeaths %>% ggplot(aes(x = date, y = deaths)) + geom_line() + theme_linedraw(base_size = 14) + scale_x_date(date_breaks = "6 months") + * scale_x_date(date_labels = '%b\n%Y') ``` ] .panel2-demo1-auto[ <img src="demo_microflip_files/figure-html/demo1_auto_06_output-1.png" width="432" /> ] <style> .panel1-demo1-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-demo1-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-demo1-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- ### Date Formatting Codes |Format Example |Unit |Code | |:--------------|:----------------------------------------|:----| |Mon |abbreviated day text |%a | |Monday |full day text |%A | |09 |digit day of month |%d | |3 (0-6) |digit day of week (Sunday = 0) |%w | |24 (0-53) |digit week of year (0-53) - Sunday start |%U | |44 (0-53) |digit week of year (0-53) - Monday start |%W | |Oct |Abbreviated Month |%b | |October |Full Month |%B | |10 |Digit Month |%m | |12 |2-Digit Year |%y | |2012 |4-Digit Year |%Y |