class: title-slide, right, top background-image: url(data:image/png;base64,#img/dawn.png) background-position: 90% 75%, 75% 75% background-size:cover .left-column[ # NHS Workshop<br>Introduction to ggplot ] .right-column[ ### colours and facets **Eugene Hickey**<br> January 21st 2021 ] .palegrey[.left[.footnote[Graphic by [Elaine Hickey](https://photos.google.com/photo/AF1QipMjKNoaxyne8nte4HmxA6Th9-4fUfSbl_mx-_1G)]]] ??? Welcome to the workshop on ggplot. Where we'll show you how to create impressive data visualisations. --- layout: true <a class="footer-link" href="http://intro-ggplot-nhs.netlify.app">intro-ggplot-nhs — Eugene Hickey</a> <!-- this adds the link footer to all slides, depends on footer-link class in css--> --- # Choice of Colours in R <br> ### We'll also discuss faceting. - colours are very important - second only to position for perception - can carry information - also important to be visually pleasing - worthwhile to make your figures aesthetically attractive - visualisations that are engaging are more effective --- ### Types of Colour Scales .panelset[ .panel[ .panel-name[Qualitative] .pull-left[ - suite of colours easily distinguished - no heirarchy - caters for visual impairments ] .pull-right[ ![](data:image/png;base64,#04-colours_files/figure-html/qualitative_palette-1.png)<!-- --> ] ]<!-- close first panel --> .panel[ .panel-name[Sequential] .pull-left[ - band of colours, increasingly intense - go from low to high ] .pull-right[ ![](data:image/png;base64,#04-colours_files/figure-html/sequential_palette-1.png)<!-- --> ] ]<!-- close second panel --> .panel[ .panel-name[Diverging] .pull-left[ - suite of colours from minus to plus - contrasting colours at each end - something neutral in the middle ] .pull-right[ ![](data:image/png;base64,#04-colours_files/figure-html/diverging_palette-1.png)<!-- --> ] ]<!-- close third panel --> ]<!-- close panelset --> --- # Getting Colours in R - some really great packages - <span style='color: #B03A2E'>RColorBrewer</span> - excellent, fine control over palette choice - <span style='color: #B03A2E'>viridis</span> - excels at palettes for vision-impaired readers - <span style='color: #B03A2E'>paletteer</span> - collection of palettes from various sources - <span style='color: #B03A2E'>wesanderson</span> - <i>names(wes_palettes)</i> followed by <i>wes_palette("BottleRocket1")</i> - <span style='color: #B03A2E'>rtist</span> - lifts principle colours from paintings --- ```r library(rtist) par(mfrow = c(3, 5)) map(names(rtist_palettes), function(x) print(rtist_palette(x))) ``` ![](data:image/png;base64,#img/rtist.png) --- - more.... - tvthemes() - not just colours, but layouts and fonts - everything from Game of Thrones to Spongebob (yes, really) - ggsci(), palettes for scientific publications (Lancet, AAAS, etc) - colorspace() - resources for picking colours - choose_color() and choose_palette() - can convert colours based on vision deficiencies - will convert from colour descriptions, e.g. hex2RGB() - and a [cheatsheet](https://www.nceas.ucsb.edu/~frazier/RSpatialGuides/colorPaletteCheatsheet.pdf) ---
--- ## Ways of Describing Colours - by name: "red", "cyan", "violetred4", "thistle"..... - get full list of 657 available in R from _colors()_ - by hex code: "#f49340", "#40f9f9", "#ee82ef", "#d8bfd1".... (see [htmlcolors](https://htmlcolorcodes.com/)]) - by rgb values: (249, 67, 64), (64, 249, 249), (57, 14, 30), (216, 191, 209).... - note, rgb() function takes these as a fraction from 0-1 - by hcl values: (53.24, 179.04, 12.17), (91.11, 72.10, 192.17), (32.36, 63.11, 349.86), (80.08, 20.79, 307.73).... --- # Investigating Colours in R - the following code shows the first "N" colours in R where N is set to 10 here: .pull-left[ ```r N <- 10 data.frame(col = colors()[1:N]) %>% ggplot(aes(x = col, fill = col)) + geom_bar(position = "stack", show.legend = F) + coord_flip() + theme_minimal() + theme(axis.text.x = element_blank(), axis.title.x = element_blank(), axis.text.y = element_blank()) ``` ] .pull-right[ ![](data:image/png;base64,#04-colours_files/figure-html/base-colours-out-1.png)<!-- --> ] --- ## Other Usful Functions - _show_col()_ from the _scales_ package is super useful - e.g. show_col("red") or show_col("#84a412") - *rgb()* will give a hex code for a fraction of red, green, blue - e.g. rgb(0.4, 0.2, 0.5) gives "#663380" --- - *colourPicker()* from the colourpicker package - colourPicker(numCols = 4), opens up shiny app, returns colours - *col2rgb()*, also *col2hex()* from the _gplots_ (not _ggplot2_) package, and *col2hcl* from the _jmw86069/jamba_ package - this last is on github, so you must install the package _devtools_ then do _install_github( jmw86069/jamba)_ - _colorfindr_ takes an image and identifies major colours --- .pull-left[ ![](data:image/png;base64,#img/simpsons.jpeg) ] .pull-right[ ``` ## # A tibble: 6 x 3 ## col_hex col_freq col_share ## <chr> <int> <dbl> ## 1 #F9C6CB 1511 0.0300 ## 2 #7183C1 508 0.0101 ## 3 #268EB3 259 0.00515 ## 4 #AFB7DE 244 0.00485 ## 5 #6F81BF 99 0.00197 ## 6 #FAC7CC 99 0.00197 ``` ![](data:image/png;base64,#04-colours_files/figure-html/simpsons-out-1.png)<!-- --> ] --- # Some Websites and Tools - [coolors.co](coolors.co) - will generate appropriate palettes - [colorpicker](http://tristen.ca/hcl-picker/#/hlc/6/1.1/8C4443/845128) - [colorspace](http://colorspace.r-forge.r-project.org/articles/hcl_palettes.html#qualitative-palettes) - Chrome has an _**Eye Dropper**_ tool - click on part of a webpage and it will tell you the colour - Nice description of colurs from [Stowers](https://www.uv.es/conesa/CursoR/material/UsingColorInR.pdf) ---
--- # Colours in _ggplot()_ - use for _fill_ and for _col_ aesthetics - add the _scale_fill_... and _scale_color_... layers to control - explore these by typing _?scale_fill_ and then TAB to see the range of options --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_brewer(type = 'qual') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_01_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_brewer(type = 'div') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_02_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_viridis_d(option = 'magma') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_03_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('rtist::warhol') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_04_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('MapPalettes::irish_flag') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_05_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('yarrr::southpark') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_06_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('dutchmasters::pearl_earring') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_07_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('dutchmasters::view_of_Delft') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_08_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('ghibli::KikiLight') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_09_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('LaCroixColoR::Coconut') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_10_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('LaCroixColoR::PassionFruit') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_11_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('ggsci::lanonc_lancet') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_12_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('ggsci::default_uchicago') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_13_output-1.png)<!-- --> ] --- count: false .panel1-my_rotate-rotate[ ```r dslabs::gapminder %>% group_by(continent, year) %>% summarise(average_fertility = mean(fertility, na.rm = TRUE)) %>% ungroup() %>% ggplot(aes(x = year, y = average_fertility, col = continent)) + geom_line(size = 2) + * scale_color_paletteer_d('ggsci::uniform_startrek') ``` ] .panel2-my_rotate-rotate[ ![](data:image/png;base64,#04-colours_files/figure-html/my_rotate_rotate_14_output-1.png)<!-- --> ] <style> .panel1-my_rotate-rotate { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-my_rotate-rotate { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-my_rotate-rotate { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-histogram-colours-user[ ```r *dslabs::gapminder %>% * ggplot(aes(x = life_expectancy, * fill = ..x..)) + * geom_histogram() + * scale_fill_continuous(type = 'viridis') ``` ] .panel2-histogram-colours-user[ ![](data:image/png;base64,#04-colours_files/figure-html/histogram-colours_user_01_output-1.png)<!-- --> ] --- count: false .panel1-histogram-colours-user[ ```r dslabs::gapminder %>% ggplot(aes(x = life_expectancy, fill = ..x..)) + geom_histogram() + scale_fill_continuous(type = 'viridis') + * scale_fill_gradient2(low = "darkgreen", * mid = "white", * high = "firebrick4", * midpoint = 65) ``` ] .panel2-histogram-colours-user[ ![](data:image/png;base64,#04-colours_files/figure-html/histogram-colours_user_02_output-1.png)<!-- --> ] <style> .panel1-histogram-colours-user { color: black; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-histogram-colours-user { color: black; width: 49%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-histogram-colours-user { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- class: center, inverse # _faceting_ - Faceting means producing multiple panels of a plot - Splits a plot into several versions based on a categorical variable - functions _facet_wrap()_ and _facet_grid()_ - useful when lots of data in different subsets - important to keep axis scales the same --- count: false .panel1-facet-example1-auto[ ```r *sex <- c("Female", "Male") ``` ] .panel2-facet-example1-auto[ ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") *names(sex) <- c("F", "M") ``` ] .panel2-facet-example1-auto[ ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") *cats ### cats dataset from MASS ``` ] .panel2-facet-example1-auto[ ``` ## Sex Bwt Hwt ## 1 F 2.0 7.0 ## 2 F 2.0 7.4 ## 3 F 2.0 9.5 ## 4 F 2.1 7.2 ## 5 F 2.1 7.3 ## 6 F 2.1 7.6 ## 7 F 2.1 8.1 ## 8 F 2.1 8.2 ## 9 F 2.1 8.3 ## 10 F 2.1 8.5 ## 11 F 2.1 8.7 ## 12 F 2.1 9.8 ## 13 F 2.2 7.1 ## 14 F 2.2 8.7 ## 15 F 2.2 9.1 ## 16 F 2.2 9.7 ## 17 F 2.2 10.9 ## 18 F 2.2 11.0 ## 19 F 2.3 7.3 ## 20 F 2.3 7.9 ## 21 F 2.3 8.4 ## 22 F 2.3 9.0 ## 23 F 2.3 9.0 ## 24 F 2.3 9.5 ## 25 F 2.3 9.6 ## 26 F 2.3 9.7 ## 27 F 2.3 10.1 ## 28 F 2.3 10.1 ## 29 F 2.3 10.6 ## 30 F 2.3 11.2 ## 31 F 2.4 6.3 ## 32 F 2.4 8.7 ## 33 F 2.4 8.8 ## 34 F 2.4 10.2 ## 35 F 2.5 9.0 ## 36 F 2.5 10.9 ## 37 F 2.6 8.7 ## 38 F 2.6 10.1 ## 39 F 2.6 10.1 ## 40 F 2.7 8.5 ## 41 F 2.7 10.2 ## 42 F 2.7 10.8 ## 43 F 2.9 9.9 ## 44 F 2.9 10.1 ## 45 F 2.9 10.1 ## 46 F 3.0 10.6 ## 47 F 3.0 13.0 ## 48 M 2.0 6.5 ## 49 M 2.0 6.5 ## 50 M 2.1 10.1 ## 51 M 2.2 7.2 ## 52 M 2.2 7.6 ## 53 M 2.2 7.9 ## 54 M 2.2 8.5 ## 55 M 2.2 9.1 ## 56 M 2.2 9.6 ## 57 M 2.2 9.6 ## 58 M 2.2 10.7 ## 59 M 2.3 9.6 ## 60 M 2.4 7.3 ## 61 M 2.4 7.9 ## 62 M 2.4 7.9 ## 63 M 2.4 9.1 ## 64 M 2.4 9.3 ## 65 M 2.5 7.9 ## 66 M 2.5 8.6 ## 67 M 2.5 8.8 ## 68 M 2.5 8.8 ## 69 M 2.5 9.3 ## 70 M 2.5 11.0 ## 71 M 2.5 12.7 ## 72 M 2.5 12.7 ## 73 M 2.6 7.7 ## 74 M 2.6 8.3 ## 75 M 2.6 9.4 ## 76 M 2.6 9.4 ## 77 M 2.6 10.5 ## 78 M 2.6 11.5 ## 79 M 2.7 8.0 ## 80 M 2.7 9.0 ## 81 M 2.7 9.6 ## 82 M 2.7 9.6 ## 83 M 2.7 9.8 ## 84 M 2.7 10.4 ## 85 M 2.7 11.1 ## 86 M 2.7 12.0 ## 87 M 2.7 12.5 ## 88 M 2.8 9.1 ## 89 M 2.8 10.0 ## 90 M 2.8 10.2 ## 91 M 2.8 11.4 ## 92 M 2.8 12.0 ## 93 M 2.8 13.3 ## 94 M 2.8 13.5 ## 95 M 2.9 9.4 ## 96 M 2.9 10.1 ## 97 M 2.9 10.6 ## 98 M 2.9 11.3 ## 99 M 2.9 11.8 ## 100 M 3.0 10.0 ## 101 M 3.0 10.4 ## 102 M 3.0 10.6 ## 103 M 3.0 11.6 ## 104 M 3.0 12.2 ## 105 M 3.0 12.4 ## 106 M 3.0 12.7 ## 107 M 3.0 13.3 ## 108 M 3.0 13.8 ## 109 M 3.1 9.9 ## 110 M 3.1 11.5 ## 111 M 3.1 12.1 ## 112 M 3.1 12.5 ## 113 M 3.1 13.0 ## 114 M 3.1 14.3 ## 115 M 3.2 11.6 ## 116 M 3.2 11.9 ## 117 M 3.2 12.3 ## 118 M 3.2 13.0 ## 119 M 3.2 13.5 ## 120 M 3.2 13.6 ## 121 M 3.3 11.5 ## 122 M 3.3 12.0 ## 123 M 3.3 14.1 ## 124 M 3.3 14.9 ## 125 M 3.3 15.4 ## 126 M 3.4 11.2 ## 127 M 3.4 12.2 ## 128 M 3.4 12.4 ## 129 M 3.4 12.8 ## 130 M 3.4 14.4 ## 131 M 3.5 11.7 ## 132 M 3.5 12.9 ## 133 M 3.5 15.6 ## 134 M 3.5 15.7 ## 135 M 3.5 17.2 ## 136 M 3.6 11.8 ## 137 M 3.6 13.3 ## 138 M 3.6 14.8 ## 139 M 3.6 15.0 ## 140 M 3.7 11.0 ## 141 M 3.8 14.8 ## 142 M 3.8 16.8 ## 143 M 3.9 14.4 ## 144 M 3.9 20.5 ``` ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") cats %>% ### cats dataset from MASS * ggplot(aes(Bwt, Hwt)) ``` ] .panel2-facet-example1-auto[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example1_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + * geom_point() ``` ] .panel2-facet-example1-auto[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example1_auto_05_output-1.png)<!-- --> ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + geom_point() + * geom_smooth(aes(col = Sex), show.legend = F, se = F) ``` ] .panel2-facet-example1-auto[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example1_auto_06_output-1.png)<!-- --> ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + geom_point() + geom_smooth(aes(col = Sex), show.legend = F, se = F) + * facet_grid(~Sex, labeller = labeller(Sex = sex)) ``` ] .panel2-facet-example1-auto[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example1_auto_07_output-1.png)<!-- --> ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + geom_point() + geom_smooth(aes(col = Sex), show.legend = F, se = F) + facet_grid(~Sex, labeller = labeller(Sex = sex)) + * labs(x = "Bodyweight (kg)", y = "Heart Weight (g)") ``` ] .panel2-facet-example1-auto[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example1_auto_08_output-1.png)<!-- --> ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + geom_point() + geom_smooth(aes(col = Sex), show.legend = F, se = F) + facet_grid(~Sex, labeller = labeller(Sex = sex)) + labs(x = "Bodyweight (kg)", y = "Heart Weight (g)") + * theme_minimal() ``` ] .panel2-facet-example1-auto[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example1_auto_09_output-1.png)<!-- --> ] --- count: false .panel1-facet-example1-auto[ ```r sex <- c("Female", "Male") names(sex) <- c("F", "M") cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + geom_point() + geom_smooth(aes(col = Sex), show.legend = F, se = F) + facet_grid(~Sex, labeller = labeller(Sex = sex)) + labs(x = "Bodyweight (kg)", y = "Heart Weight (g)") + theme_minimal() + * theme(strip.background = element_blank(), * text = element_text(size = 32, * family = "Ink Free")) ``` ] .panel2-facet-example1-auto[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example1_auto_10_output-1.png)<!-- --> ] <style> .panel1-facet-example1-auto { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-facet-example1-auto { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-facet-example1-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-facet-example2-user[ ```r *movielens %>% ### movielens dataset from dslabs * mutate(genres = str_replace(genres, pattern = "\\|.*", "")) %>% * filter(genres != "(no genres listed)") %>% * ggplot(aes(rating)) + * stat_density(position = "identity", geom = "line", adjust = 3) ``` ] .panel2-facet-example2-user[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example2_user_01_output-1.png)<!-- --> ] --- count: false .panel1-facet-example2-user[ ```r movielens %>% ### movielens dataset from dslabs mutate(genres = str_replace(genres, pattern = "\\|.*", "")) %>% filter(genres != "(no genres listed)") %>% ggplot(aes(rating)) + stat_density(position = "identity", geom = "line", adjust = 3) + * facet_wrap(.~genres, strip.position = "bottom", nrow = 3) ``` ] .panel2-facet-example2-user[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example2_user_02_output-1.png)<!-- --> ] --- count: false .panel1-facet-example2-user[ ```r movielens %>% ### movielens dataset from dslabs mutate(genres = str_replace(genres, pattern = "\\|.*", "")) %>% filter(genres != "(no genres listed)") %>% ggplot(aes(rating)) + stat_density(position = "identity", geom = "line", adjust = 3) + facet_wrap(.~genres, strip.position = "bottom", nrow = 3) + * theme(axis.text.y = element_blank(), * axis.title.y = element_blank(), * axis.text.x = element_blank(), * axis.title.x = element_blank()) ``` ] .panel2-facet-example2-user[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example2_user_03_output-1.png)<!-- --> ] <style> .panel1-facet-example2-user { color: black; width: 38.6060606060606%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-facet-example2-user { color: black; width: 59.3939393939394%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-facet-example2-user { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> --- count: false .panel1-facet-example3-user[ ```r ## snails dataset from the MASS library *snails ``` ] .panel2-facet-example3-user[ ``` ## Species Exposure Rel.Hum Temp Deaths N ## 1 A 1 60.0 10 0 20 ## 2 A 1 60.0 15 0 20 ## 3 A 1 60.0 20 0 20 ## 4 A 1 65.8 10 0 20 ## 5 A 1 65.8 15 0 20 ## 6 A 1 65.8 20 0 20 ## 7 A 1 70.5 10 0 20 ## 8 A 1 70.5 15 0 20 ## 9 A 1 70.5 20 0 20 ## 10 A 1 75.8 10 0 20 ## 11 A 1 75.8 15 0 20 ## 12 A 1 75.8 20 0 20 ## 13 A 2 60.0 10 0 20 ## 14 A 2 60.0 15 1 20 ## 15 A 2 60.0 20 1 20 ## 16 A 2 65.8 10 0 20 ## 17 A 2 65.8 15 1 20 ## 18 A 2 65.8 20 0 20 ## 19 A 2 70.5 10 0 20 ## 20 A 2 70.5 15 0 20 ## 21 A 2 70.5 20 0 20 ## 22 A 2 75.8 10 0 20 ## 23 A 2 75.8 15 0 20 ## 24 A 2 75.8 20 0 20 ## 25 A 3 60.0 10 1 20 ## 26 A 3 60.0 15 4 20 ## 27 A 3 60.0 20 5 20 ## 28 A 3 65.8 10 0 20 ## 29 A 3 65.8 15 2 20 ## 30 A 3 65.8 20 4 20 ## 31 A 3 70.5 10 0 20 ## 32 A 3 70.5 15 2 20 ## 33 A 3 70.5 20 3 20 ## 34 A 3 75.8 10 0 20 ## 35 A 3 75.8 15 1 20 ## 36 A 3 75.8 20 2 20 ## 37 A 4 60.0 10 7 20 ## 38 A 4 60.0 15 7 20 ## 39 A 4 60.0 20 7 20 ## 40 A 4 65.8 10 4 20 ## 41 A 4 65.8 15 4 20 ## 42 A 4 65.8 20 7 20 ## 43 A 4 70.5 10 3 20 ## 44 A 4 70.5 15 3 20 ## 45 A 4 70.5 20 5 20 ## 46 A 4 75.8 10 2 20 ## 47 A 4 75.8 15 3 20 ## 48 A 4 75.8 20 3 20 ## 49 B 1 60.0 10 0 20 ## 50 B 1 60.0 15 0 20 ## 51 B 1 60.0 20 0 20 ## 52 B 1 65.8 10 0 20 ## 53 B 1 65.8 15 0 20 ## 54 B 1 65.8 20 0 20 ## 55 B 1 70.5 10 0 20 ## 56 B 1 70.5 15 0 20 ## 57 B 1 70.5 20 0 20 ## 58 B 1 75.8 10 0 20 ## 59 B 1 75.8 15 0 20 ## 60 B 1 75.8 20 0 20 ## 61 B 2 60.0 10 0 20 ## 62 B 2 60.0 15 3 20 ## 63 B 2 60.0 20 2 20 ## 64 B 2 65.8 10 0 20 ## 65 B 2 65.8 15 2 20 ## 66 B 2 65.8 20 1 20 ## 67 B 2 70.5 10 0 20 ## 68 B 2 70.5 15 0 20 ## 69 B 2 70.5 20 1 20 ## 70 B 2 75.8 10 1 20 ## 71 B 2 75.8 15 0 20 ## 72 B 2 75.8 20 1 20 ## 73 B 3 60.0 10 7 20 ## 74 B 3 60.0 15 11 20 ## 75 B 3 60.0 20 11 20 ## 76 B 3 65.8 10 4 20 ## 77 B 3 65.8 15 5 20 ## 78 B 3 65.8 20 9 20 ## 79 B 3 70.5 10 2 20 ## 80 B 3 70.5 15 4 20 ## 81 B 3 70.5 20 6 20 ## 82 B 3 75.8 10 2 20 ## 83 B 3 75.8 15 3 20 ## 84 B 3 75.8 20 5 20 ## 85 B 4 60.0 10 12 20 ## 86 B 4 60.0 15 14 20 ## 87 B 4 60.0 20 16 20 ## 88 B 4 65.8 10 10 20 ## 89 B 4 65.8 15 12 20 ## 90 B 4 65.8 20 12 20 ## 91 B 4 70.5 10 5 20 ## 92 B 4 70.5 15 7 20 ## 93 B 4 70.5 20 9 20 ## 94 B 4 75.8 10 4 20 ## 95 B 4 75.8 15 5 20 ## 96 B 4 75.8 20 7 20 ``` ] --- count: false .panel1-facet-example3-user[ ```r ## snails dataset from the MASS library snails %>% * ggplot(aes(Exposure, Deaths, col = factor(Rel.Hum))) + * geom_line() + * geom_point() + * theme(legend.title = element_blank()) ``` ] .panel2-facet-example3-user[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example3_user_02_output-1.png)<!-- --> ] --- count: false .panel1-facet-example3-user[ ```r ## snails dataset from the MASS library snails %>% ggplot(aes(Exposure, Deaths, col = factor(Rel.Hum))) + geom_line() + geom_point() + theme(legend.title = element_blank()) + * facet_grid(Species ~ Temp, * scales = "free") ``` ] .panel2-facet-example3-user[ ![](data:image/png;base64,#04-colours_files/figure-html/facet-example3_user_03_output-1.png)<!-- --> ] <style> .panel1-facet-example3-user { color: black; width: 58.8%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel2-facet-example3-user { color: black; width: 39.2%; hight: 32%; float: left; padding-left: 1%; font-size: 80% } .panel3-facet-example3-user { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 80% } </style> ---