class: center, middle, inverse, title-slide .title[ # Data visualization basics ] .subtitle[ ## – examples in {ggplot2} ] .author[ ###
Julia Romanowska
] .date[ ### April 20, 2023 ] --- class: inverse, left, middle ##
{ggplot2} basics --- ### A plot in {ggplot2} consists of several layers: -- 1. data 2. aesthetics (`aes`) ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-aesthetics)) 3. `geom`s ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-geoms)) 4. `scale`s ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-scales)) 5. `theme` ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-themes)) ??? 1. data - strict format: tidy data! - one row per datapoint - all grouping must be included in the data 2. aesthetics (`aes`) ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-aesthetics)) - how to map the data to the graph? - which column is *x*, *y*, ... - which column provides grouping (based on the grouping, one can either connect points into lines, split a graph into several facets, or color differently each group) 3. `geom`s ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-geoms)) - how to visualize the data? - points (`geom_point`), lines (`geom_line`), bars (`geom_bar`), etc. - `geom`s are connected to `stat`s that conduct any necessary pre-processing of data (e.g., `geom_histogram` would first calculate the number of observations in each bin through `stat_bin`) 4. `scale`s ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-scales)) - any type of data representation on the plot - coordinates: `scale_x_continuous`, `scale_x_discrete`, `scale_x_date`, etc. - colors: `scale_color_manual`, `scale_colour_brewer`, `scale_fill_continuous`, etc. 5. `theme` ([original documentation](https://ggplot2.tidyverse.org/reference/index.html#section-themes)) - visual aspects - size and types of fonts - positioning of axes, legends, etc. Each layer is added to the previous one with a `+` sign. The result can be saved to an object and added upon later. --- class: inverse, left, middle ## Example plot with {ggplot2} --- ## Data <div style="float: right; position: fixed; right: 10px; top: 10px;"> <img style="float: right; position: relative; width: 120px" src="libs/figs/palmer_penguins_logo.png" alt="palmer penguins R package logo"/><br> </div> [palmerpenguins](https://allisonhorst.github.io/palmerpenguins/) <br> ``` # A tibble: 344 × 8 species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g <fct> <fct> <dbl> <dbl> <int> <int> 1 Adelie Torgersen 39.1 18.7 181 3750 2 Adelie Torgersen 39.5 17.4 186 3800 3 Adelie Torgersen 40.3 18 195 3250 4 Adelie Torgersen NA NA NA NA 5 Adelie Torgersen 36.7 19.3 193 3450 6 Adelie Torgersen 39.3 20.6 190 3650 7 Adelie Torgersen 38.9 17.8 181 3625 8 Adelie Torgersen 39.2 19.6 195 4675 9 Adelie Torgersen 34.1 18.1 193 3475 10 Adelie Torgersen 42 20.2 190 4250 # ℹ 334 more rows # ℹ 2 more variables: sex <fct>, year <int> ``` ??? I will be using this simple dataset with morphological data of penguins living on a certain island. -- > **IMPORTANT** start with tidy data! **each row is an observation, each column is a variable** --- count: false .panel1-penguins_species_simple-auto[ ```r *ggplot(data = penguins) ``` ] .panel2-penguins_species_simple-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_simple_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species_simple-auto[ ```r ggplot(data = penguins) + * aes( * x = bill_length_mm, * y = bill_depth_mm * ) ``` ] .panel2-penguins_species_simple-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_simple_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species_simple-auto[ ```r ggplot(data = penguins) + aes( x = bill_length_mm, y = bill_depth_mm ) + * geom_point() ``` ] .panel2-penguins_species_simple-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_simple_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species_simple-auto[ ```r ggplot(data = penguins) + aes( x = bill_length_mm, y = bill_depth_mm ) + geom_point() + * geom_smooth(method = "lm") ``` ] .panel2-penguins_species_simple-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_simple_auto_04_output-1.png)<!-- --> ] <style> .panel1-penguins_species_simple-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_species_simple-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_species_simple-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> --- count: false .panel1-penguins_species-auto[ ```r *ggplot(data = penguins) ``` ] .panel2-penguins_species-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species-auto[ ```r ggplot(data = penguins) + * aes( * x = bill_length_mm, * y = bill_depth_mm * ) ``` ] .panel2-penguins_species-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species-auto[ ```r ggplot(data = penguins) + aes( x = bill_length_mm, y = bill_depth_mm ) + * geom_point( * aes(color = species, * shape = species), * size = 2 * ) ``` ] .panel2-penguins_species-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species-auto[ ```r ggplot(data = penguins) + aes( x = bill_length_mm, y = bill_depth_mm ) + geom_point( aes(color = species, shape = species), size = 2 ) + * geom_smooth( * method = "lm", * se = FALSE, * aes(color = species) * ) ``` ] .panel2-penguins_species-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species-auto[ ```r ggplot(data = penguins) + aes( x = bill_length_mm, y = bill_depth_mm ) + geom_point( aes(color = species, shape = species), size = 2 ) + geom_smooth( method = "lm", se = FALSE, aes(color = species) ) *penguins_default <- last_plot() ``` ] .panel2-penguins_species-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species_auto_05_output-1.png)<!-- --> ] <style> .panel1-penguins_species-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_species-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_species-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> ??? Basics of ggplot2: - layers - 'aesthetics' + data + geom --- class: inverse, left, middle ## _...back to theory..._ --- ## Bar chart --- count: false .panel1-penguins_barchart-auto[ ```r *ggplot(penguins) ``` ] .panel2-penguins_barchart-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_barchart_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-penguins_barchart-auto[ ```r ggplot(penguins) + * geom_bar(aes(island)) ``` ] .panel2-penguins_barchart-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_barchart_auto_02_output-1.png)<!-- --> ] <style> .panel1-penguins_barchart-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_barchart-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_barchart-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> --- ## Line chart --- count: false .panel1-penguins_linechart-auto[ ```r *penguins ``` ] .panel2-penguins_linechart-auto[ ``` # A tibble: 344 × 8 species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g <fct> <fct> <dbl> <dbl> <int> <int> 1 Adelie Torgersen 39.1 18.7 181 3750 2 Adelie Torgersen 39.5 17.4 186 3800 3 Adelie Torgersen 40.3 18 195 3250 4 Adelie Torgersen NA NA NA NA 5 Adelie Torgersen 36.7 19.3 193 3450 6 Adelie Torgersen 39.3 20.6 190 3650 7 Adelie Torgersen 38.9 17.8 181 3625 8 Adelie Torgersen 39.2 19.6 195 4675 9 Adelie Torgersen 34.1 18.1 193 3475 10 Adelie Torgersen 42 20.2 190 4250 # ℹ 334 more rows # ℹ 2 more variables: sex <fct>, year <int> ``` ] --- count: false .panel1-penguins_linechart-auto[ ```r penguins %>% * count(year, sex) ``` ] .panel2-penguins_linechart-auto[ ``` # A tibble: 9 × 3 year sex n <int> <fct> <int> 1 2007 female 51 2 2007 male 52 3 2007 <NA> 7 4 2008 female 56 5 2008 male 57 6 2008 <NA> 1 7 2009 female 58 8 2009 male 59 9 2009 <NA> 3 ``` ] --- count: false .panel1-penguins_linechart-auto[ ```r penguins %>% count(year, sex) %>% * ggplot(aes(x = year, y = n)) ``` ] .panel2-penguins_linechart-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_linechart_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-penguins_linechart-auto[ ```r penguins %>% count(year, sex) %>% ggplot(aes(x = year, y = n)) + * geom_line(aes(color = sex)) ``` ] .panel2-penguins_linechart-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_linechart_auto_04_output-1.png)<!-- --> ] <style> .panel1-penguins_linechart-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_linechart-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_linechart-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> --- ## Heatmap --- count: false .panel1-penguins_heatmap-auto[ ```r *penguins ``` ] .panel2-penguins_heatmap-auto[ ``` # A tibble: 344 × 8 species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g <fct> <fct> <dbl> <dbl> <int> <int> 1 Adelie Torgersen 39.1 18.7 181 3750 2 Adelie Torgersen 39.5 17.4 186 3800 3 Adelie Torgersen 40.3 18 195 3250 4 Adelie Torgersen NA NA NA NA 5 Adelie Torgersen 36.7 19.3 193 3450 6 Adelie Torgersen 39.3 20.6 190 3650 7 Adelie Torgersen 38.9 17.8 181 3625 8 Adelie Torgersen 39.2 19.6 195 4675 9 Adelie Torgersen 34.1 18.1 193 3475 10 Adelie Torgersen 42 20.2 190 4250 # ℹ 334 more rows # ℹ 2 more variables: sex <fct>, year <int> ``` ] --- count: false .panel1-penguins_heatmap-auto[ ```r penguins %>% * count(species, island) ``` ] .panel2-penguins_heatmap-auto[ ``` # A tibble: 5 × 3 species island n <fct> <fct> <int> 1 Adelie Biscoe 44 2 Adelie Dream 56 3 Adelie Torgersen 52 4 Chinstrap Dream 68 5 Gentoo Biscoe 124 ``` ] --- count: false .panel1-penguins_heatmap-auto[ ```r penguins %>% count(species, island) %>% *ggplot(aes(x = species, y = island)) ``` ] .panel2-penguins_heatmap-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_heatmap_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-penguins_heatmap-auto[ ```r penguins %>% count(species, island) %>% ggplot(aes(x = species, y = island)) + * geom_tile(aes(fill = n)) ``` ] .panel2-penguins_heatmap-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_heatmap_auto_04_output-1.png)<!-- --> ] <style> .panel1-penguins_heatmap-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_heatmap-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_heatmap-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> --- ## Parallel coordinates ### [{ggbump} package](https://github.com/davidsjoberg/ggbump) --- count: false .panel1-penguins_parallel-auto[ ```r *penguins ``` ] .panel2-penguins_parallel-auto[ ``` # A tibble: 344 × 8 species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g <fct> <fct> <dbl> <dbl> <int> <int> 1 Adelie Torgersen 39.1 18.7 181 3750 2 Adelie Torgersen 39.5 17.4 186 3800 3 Adelie Torgersen 40.3 18 195 3250 4 Adelie Torgersen NA NA NA NA 5 Adelie Torgersen 36.7 19.3 193 3450 6 Adelie Torgersen 39.3 20.6 190 3650 7 Adelie Torgersen 38.9 17.8 181 3625 8 Adelie Torgersen 39.2 19.6 195 4675 9 Adelie Torgersen 34.1 18.1 193 3475 10 Adelie Torgersen 42 20.2 190 4250 # ℹ 334 more rows # ℹ 2 more variables: sex <fct>, year <int> ``` ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% * group_by(species) ``` ] .panel2-penguins_parallel-auto[ ``` # A tibble: 344 × 8 # Groups: species [3] species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g <fct> <fct> <dbl> <dbl> <int> <int> 1 Adelie Torgersen 39.1 18.7 181 3750 2 Adelie Torgersen 39.5 17.4 186 3800 3 Adelie Torgersen 40.3 18 195 3250 4 Adelie Torgersen NA NA NA NA 5 Adelie Torgersen 36.7 19.3 193 3450 6 Adelie Torgersen 39.3 20.6 190 3650 7 Adelie Torgersen 38.9 17.8 181 3625 8 Adelie Torgersen 39.2 19.6 195 4675 9 Adelie Torgersen 34.1 18.1 193 3475 10 Adelie Torgersen 42 20.2 190 4250 # ℹ 334 more rows # ℹ 2 more variables: sex <fct>, year <int> ``` ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% group_by(species) %>% * summarise( * across(bill_length_mm:body_mass_g, ~ mean(.x, na.rm = TRUE)) * ) ``` ] .panel2-penguins_parallel-auto[ ``` # A tibble: 3 × 5 species bill_length_mm bill_depth_mm flipper_length_mm body_mass_g <fct> <dbl> <dbl> <dbl> <dbl> 1 Adelie 38.8 18.3 190. 3701. 2 Chinstrap 48.8 18.4 196. 3733. 3 Gentoo 47.5 15.0 217. 5076. ``` ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% group_by(species) %>% summarise( across(bill_length_mm:body_mass_g, ~ mean(.x, na.rm = TRUE)) ) %>% * pivot_longer( * bill_length_mm:body_mass_g, * names_to = "measurement", * values_to = "value" * ) ``` ] .panel2-penguins_parallel-auto[ ``` # A tibble: 12 × 3 species measurement value <fct> <chr> <dbl> 1 Adelie bill_length_mm 38.8 2 Adelie bill_depth_mm 18.3 3 Adelie flipper_length_mm 190. 4 Adelie body_mass_g 3701. 5 Chinstrap bill_length_mm 48.8 6 Chinstrap bill_depth_mm 18.4 7 Chinstrap flipper_length_mm 196. 8 Chinstrap body_mass_g 3733. 9 Gentoo bill_length_mm 47.5 10 Gentoo bill_depth_mm 15.0 11 Gentoo flipper_length_mm 217. 12 Gentoo body_mass_g 5076. ``` ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% group_by(species) %>% summarise( across(bill_length_mm:body_mass_g, ~ mean(.x, na.rm = TRUE)) ) %>% pivot_longer( bill_length_mm:body_mass_g, names_to = "measurement", values_to = "value" ) %>% * group_by(measurement) ``` ] .panel2-penguins_parallel-auto[ ``` # A tibble: 12 × 3 # Groups: measurement [4] species measurement value <fct> <chr> <dbl> 1 Adelie bill_length_mm 38.8 2 Adelie bill_depth_mm 18.3 3 Adelie flipper_length_mm 190. 4 Adelie body_mass_g 3701. 5 Chinstrap bill_length_mm 48.8 6 Chinstrap bill_depth_mm 18.4 7 Chinstrap flipper_length_mm 196. 8 Chinstrap body_mass_g 3733. 9 Gentoo bill_length_mm 47.5 10 Gentoo bill_depth_mm 15.0 11 Gentoo flipper_length_mm 217. 12 Gentoo body_mass_g 5076. ``` ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% group_by(species) %>% summarise( across(bill_length_mm:body_mass_g, ~ mean(.x, na.rm = TRUE)) ) %>% pivot_longer( bill_length_mm:body_mass_g, names_to = "measurement", values_to = "value" ) %>% group_by(measurement) %>% * mutate( * rank = rank(value) * ) ``` ] .panel2-penguins_parallel-auto[ ``` # A tibble: 12 × 4 # Groups: measurement [4] species measurement value rank <fct> <chr> <dbl> <dbl> 1 Adelie bill_length_mm 38.8 1 2 Adelie bill_depth_mm 18.3 2 3 Adelie flipper_length_mm 190. 1 4 Adelie body_mass_g 3701. 1 5 Chinstrap bill_length_mm 48.8 3 6 Chinstrap bill_depth_mm 18.4 3 7 Chinstrap flipper_length_mm 196. 2 8 Chinstrap body_mass_g 3733. 2 9 Gentoo bill_length_mm 47.5 2 10 Gentoo bill_depth_mm 15.0 1 11 Gentoo flipper_length_mm 217. 3 12 Gentoo body_mass_g 5076. 3 ``` ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% group_by(species) %>% summarise( across(bill_length_mm:body_mass_g, ~ mean(.x, na.rm = TRUE)) ) %>% pivot_longer( bill_length_mm:body_mass_g, names_to = "measurement", values_to = "value" ) %>% group_by(measurement) %>% mutate( rank = rank(value) ) %>% * ungroup() ``` ] .panel2-penguins_parallel-auto[ ``` # A tibble: 12 × 4 species measurement value rank <fct> <chr> <dbl> <dbl> 1 Adelie bill_length_mm 38.8 1 2 Adelie bill_depth_mm 18.3 2 3 Adelie flipper_length_mm 190. 1 4 Adelie body_mass_g 3701. 1 5 Chinstrap bill_length_mm 48.8 3 6 Chinstrap bill_depth_mm 18.4 3 7 Chinstrap flipper_length_mm 196. 2 8 Chinstrap body_mass_g 3733. 2 9 Gentoo bill_length_mm 47.5 2 10 Gentoo bill_depth_mm 15.0 1 11 Gentoo flipper_length_mm 217. 3 12 Gentoo body_mass_g 5076. 3 ``` ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% group_by(species) %>% summarise( across(bill_length_mm:body_mass_g, ~ mean(.x, na.rm = TRUE)) ) %>% pivot_longer( bill_length_mm:body_mass_g, names_to = "measurement", values_to = "value" ) %>% group_by(measurement) %>% mutate( rank = rank(value) ) %>% ungroup() %>% * ggplot( * aes(x = measurement, y = rank) * ) ``` ] .panel2-penguins_parallel-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_parallel_auto_08_output-1.png)<!-- --> ] --- count: false .panel1-penguins_parallel-auto[ ```r penguins %>% group_by(species) %>% summarise( across(bill_length_mm:body_mass_g, ~ mean(.x, na.rm = TRUE)) ) %>% pivot_longer( bill_length_mm:body_mass_g, names_to = "measurement", values_to = "value" ) %>% group_by(measurement) %>% mutate( rank = rank(value) ) %>% ungroup() %>% ggplot( aes(x = measurement, y = rank) ) + * geom_bump(aes(color = species, group = species)) ``` ] .panel2-penguins_parallel-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_parallel_auto_09_output-1.png)<!-- --> ] <style> .panel1-penguins_parallel-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_parallel-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_parallel-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> --- class: left, middle ## ...many other geoms and extensions: https://exts.ggplot2.tidyverse.org/gallery/ --- class: inverse, left, middle ## _...back to theory..._ --- count: false .panel1-penguins_species2-auto[ ```r *penguins_default ``` ] .panel2-penguins_species2-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species2_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species2-auto[ ```r penguins_default + * facet_grid(rows = vars(species)) ``` ] .panel2-penguins_species2-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species2_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species2-auto[ ```r penguins_default + facet_grid(rows = vars(species)) *penguins_facet <- last_plot() ``` ] .panel2-penguins_species2-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species2_auto_03_output-1.png)<!-- --> ] <style> .panel1-penguins_species2-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_species2-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_species2-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> --- [{ggiraph} package](https://davidgohel.github.io/ggiraph/) .pull-left[ ```r penguins_facet_interactive <- penguins_facet + geom_point_interactive( aes( color = species, shape = species, tooltip = paste0(sex, ", living on ", island) ) ) girafe(ggobj = penguins_facet_interactive) ``` ] .pull-right[
] --- class: inverse, left, middle ## _...back to theory..._ --- count: false .panel1-penguins_species3-auto[ ```r *penguins_facet ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_01_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + * scale_color_manual( * values = c("darkorange", * "darkorchid", * "cyan4") * ) ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_02_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + scale_color_manual( values = c("darkorange", "darkorchid", "cyan4") ) + * labs(title = * "Penguin species differentation") ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_03_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + scale_color_manual( values = c("darkorange", "darkorchid", "cyan4") ) + labs(title = "Penguin species differentation") + * labs(subtitle = * "based on bill depth and bill length") ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_04_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + scale_color_manual( values = c("darkorange", "darkorchid", "cyan4") ) + labs(title = "Penguin species differentation") + labs(subtitle = "based on bill depth and bill length") + * xlab("bill length (mm)") ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_05_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + scale_color_manual( values = c("darkorange", "darkorchid", "cyan4") ) + labs(title = "Penguin species differentation") + labs(subtitle = "based on bill depth and bill length") + xlab("bill length (mm)") + * ylab("bill depth (mm)") ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_06_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + scale_color_manual( values = c("darkorange", "darkorchid", "cyan4") ) + labs(title = "Penguin species differentation") + labs(subtitle = "based on bill depth and bill length") + xlab("bill length (mm)") + ylab("bill depth (mm)") + * theme_minimal() ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_07_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + scale_color_manual( values = c("darkorange", "darkorchid", "cyan4") ) + labs(title = "Penguin species differentation") + labs(subtitle = "based on bill depth and bill length") + xlab("bill length (mm)") + ylab("bill depth (mm)") + theme_minimal() + * theme( * plot.title = * element_text(face = "bold"), * plot.subtitle = * element_text(face = "italic")) ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_08_output-1.png)<!-- --> ] --- count: false .panel1-penguins_species3-auto[ ```r penguins_facet + scale_color_manual( values = c("darkorange", "darkorchid", "cyan4") ) + labs(title = "Penguin species differentation") + labs(subtitle = "based on bill depth and bill length") + xlab("bill length (mm)") + ylab("bill depth (mm)") + theme_minimal() + theme( plot.title = element_text(face = "bold"), plot.subtitle = element_text(face = "italic")) + * theme(legend.position = "none") ``` ] .panel2-penguins_species3-auto[ ![](JRom_intro_ggplot2_examples_files/figure-html/penguins_species3_auto_09_output-1.png)<!-- --> ] <style> .panel1-penguins_species3-auto { color: black; width: 51.5789473684211%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel2-penguins_species3-auto { color: black; width: 46.421052631579%; hight: 32%; float: left; padding-left: 1%; font-size: 50% } .panel3-penguins_species3-auto { color: black; width: NA%; hight: 33%; float: left; padding-left: 1%; font-size: 50% } </style> ??? OK, that was the basic graph, but we can modify everything: - change of color, - split into sub-graphs, - adding graph title (and subtitle, caption) - adding axes titles - styling --- class: inverse, center, middle #
Hands-on