Data Analysis & Visualisation According to FAIR Principles
Abstract
The slides, R script, and Jupyter notebook for the workshop lesson "Data Analysis & Visualisation According to FAIR Principles" as part of the "NFDI4Biodiversity Seasonal School 2024" and the subsequent edition as part of the follow-up course "NFDI4Biodiversity & HeFDI & iDiv Seasonal School 2025". The lesson covers the principles of the data science workflow, using R and the tidyverse, with a focus on data visualization principles and the grammar of graphics with the ggplot2 package.
Full text
Data Analysis & Visualisation According to FAIR Principles NFDI4Biodiversity & HeFDI & iDiv Seasona l Schoo l 2 0 25 October 9, 2 0 25 Dr Cédric Scherer Data Visua l ization & Information Design Cédric Scherer
Welcome! Data Visua l ization & Information Design Cédric Scherer
Hi, I am Cédric. I am an independent specia l ist for infographics and data visua l izations . I craft charts and maps, deve l op workf l ows for efficient data communication, and teach data visua l ization and dashboard design. he ll [email protected] Data Visua l ization & Information Design Cédric Scherer
Data Visua l ization & Information Design Cédric Scherer
Data Visua l ization & Information Design Cédric Scherer
Data Visua l ization & Information Design Cédric Scherer
cedricscherer.com Data Visua l ization & Information Design Cédric Scherer
cedricscherer.com/2 0 19/ 0 8/ 0 5/a-ggp l ot2-tutoria l -for-beautifu l -p l otting-in-r Data Visua l ization & Information Design Cédric Scherer
cedricscherer.com Data Visua l ization & Information Design Cédric Scherer
… make both ca l cu l ations and graphs . Both sorts of output shou l d be studied; each wi ll contribute to understanding . F. J. Anscombe (1973) Data Visua l ization & Information Design Cédric Scherer
Anscombe’s Quartet Data Visua l ization & Information Design Cédric Scherer
Anscombe’s Quartet Data Visua l ization & Information Design Cédric Scherer
Anscombe’s Quartet Source: Matejka & Fitzmaurice (2 0 17) Data Visua l ization & Information Design Cédric Scherer
Visualize Your Data! When Dmitry Kobak and Sergey Shpi l kin […] ana l ysed the resu l ts, they found that an unusua ll y high number of turnout and vote-share resu l ts were mu l tip l es of five (eg, 5 0 %, 55%, 6 0 %), a te ll -ta l e sign of manipu l ation . by The Economist <Russian e l ections once again had a suspicious l y neat resu l t= Data Visua l ization & Information Design Cédric Scherer
Visualize Your Data! When Dmitry Kobak and Sergey Shpi l kin […] ana l ysed the resu l ts, they found that an unusua ll y high number of turnout and vote-share resu l ts were mu l tip l es of five (eg, 5 0 %, 55%, 6 0 %), a te ll -ta l e sign of manipu l ation . by The Economist <Russian e l ections once again had a suspicious l y neat resu l t= Data Visua l ization & Information Design Cédric Scherer
What Makes a Good Data Visualization? → Integrity (information) → Story (interestingness) → Goal (usefulness) → Visual Form (beauty) Data Visua l ization & Information Design Cédric Scherer
The Data Science Work昀氀ow Data Visua l ization & Information Design Cédric Scherer
FAIR Principles → F indability → A ccessibility → I nteroperability → R euse of digital assets Data Visua l ization & Information Design Cédric Scherer
Data Visua l ization & Information Design Cédric Scherer
Inspect the Data dplyr::glimpse(trydb) 1 Rows: 52,323 Columns: 5 $ ...1 <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,… $ SpeciesName <chr> "Castanea sativa", "Fagus sylvatica", "Larix decidua", "Pi… $ TraitName <chr> "Seed dry mass", "Seed dry mass", "Seed dry mass", "Seed d… $ StdValue <dbl> 1433.000000, 158.000000, 6.244000, 2.940000, 6.190000, 190… $ UnitName <chr> "mg", "mg", "mg", "mg", "mg", "mg", "mg", "mg", "mg", "g/c… trydb <- janitor::clean_names(trydb) 1 dplyr::glimpse(trydb) 1 Rows: 52,323 Columns: 5 $ x1 <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17… $ species_name <chr> "Castanea sativa", "Fagus sylvatica", "Larix decidua", "P… $ trait_name <chr> "Seed dry mass", "Seed dry mass", "Seed dry mass", "Seed … $ std_value <dbl> 1433.000000, 158.000000, 6.244000, 2.940000, 6.190000, 19… $ unit_name <chr> "mg", "mg", "mg", "mg", "mg", "mg", "mg", "mg", "mg", "g/… Data Visua l ization & Information Design Cédric Scherer
Inspect the Data unique(trydb$unit_name) 1 [1] "mg" "g/cm3" "mg/g" "g/g" "per mill" "m" [7] "mm2" "number" "mm2 mg-1" "g m-2" "mm" "mm-2" [13] "g" length(unique(trydb$species_name)) 1 [1] 41 median(trydb$std_value) 1 [1] NA median(trydb$std_value, na.rm = TRUE) 1 [1] 4.18 quantile(trydb$std_value, na.rm = TRUE) 1 0% 25% 50% 75% 100% -9.670 0.621 4.180 15.750 138600.000 Data Visua l ization & Information Design Cédric Scherer
Inspect the Data summary(trydb) 1 x1 species_name trait_name std_value Min. : 1 Length:52323 Length:52323 Min. : -9.670 1st Qu.:13082 Class :character Class :character 1st Qu.: 0.621 Median :26162 Mode :character Mode :character Median : 4.180 Mean :26162 Mean : 88.316 3rd Qu.:39242 3rd Qu.: 15.750 Max. :52323 Max. :138600.000 NA's :10 unit_name Length:52323 Class :character Mode :character Data Visua l ization & Information Design Cédric Scherer
Inspect the Data dplyr::count(trydb) 1 # A tibble: 1 × 1 n <int> 1 52323 Data Visua l ization & Information Design Cédric Scherer
Inspect the Data dplyr::count(trydb, species_name) 1 # A tibble: 41 × 2 species_name n <chr> <int> 1 Abies alba 795 2 Abies concolor 311 3 Abies grandis 154 4 Abies koreana 10 5 Abies nordmanniana 32 6 Abies procera 45 7 Castanea sativa 701 8 Cedrus atlantica 126 9 Fagus sylvatica 7166 10 Larix decidua 653 # ℹ 31 more rows Data Visua l ization & Information Design Cédric Scherer
Inspect the Data dplyr::count(trydb, trait_name) 1 # A tibble: 17 × 2 trait_name n <chr> <int> 1 Dispersal unit length 96 2 Leaf area (in case of compound leaves: leaflet, undefined if petiole i… 190 3 Leaf area per leaf dry mass (specific leaf area, SLA or 1/LMA): undefi… 6742 4 Leaf carbon (C) content per leaf dry mass 3999 5 Leaf dry mass per leaf fresh mass (leaf dry matter content, LDMC) 4447 6 Leaf fresh mass 2442 7 Leaf nitrogen (N) content per leaf area 2579 8 Leaf nitrogen (N) content per leaf dry mass 9771 9 Leaf nitrogen (N) isotope signature (delta 15N) 200 10 Leaf nitrogen/phosphorus (N/P) ratio 2612 11 Leaf phosphorus (P) content per leaf dry mass 4923 12 Plant height vegetative 10201 13 Seed dry mass 700 14 Seed length 112 15 Seed number per reproducton unit 67 Data Visua l ization & Information Design Cédric Scherer
Inspect the Data dplyr::count(trydb, species_name, trait_name) 1 # A tibble: 405 × 3 species_name trait_name n <chr> <chr> <int> 1 Abies alba Dispersal unit length 6 2 Abies alba Leaf area (in case of compound leaves: leaflet, undefined… 2 3 Abies alba Leaf area per leaf dry mass (specific leaf area, SLA or 1… 128 4 Abies alba Leaf carbon (C) content per leaf dry mass 43 5 Abies alba Leaf dry mass per leaf fresh mass (leaf dry matter conten… 98 6 Abies alba Leaf fresh mass 144 7 Abies alba Leaf nitrogen (N) content per leaf area 36 8 Abies alba Leaf nitrogen (N) content per leaf dry mass 91 9 Abies alba Leaf nitrogen/phosphorus (N/P) ratio 35 10 Abies alba Leaf phosphorus (P) content per leaf dry mass 50 # ℹ 395 more rows Data Visua l ization & Information Design Cédric Scherer
Data Wrangling Data Visua l ization & Information Design Cédric Scherer
Data Visua l ization & Information Design Cédric Scherer
The Main Verbs of {dplyr} Verb (Function) Explanation filter() Pick rows with matching criteria select() Pick columns with matching criteria arrange() Reorder rows mutate() Create new variables summarize() or summarise() Sum up variables group_by() Create subsets library(dplyr) 1 Data Visua l ization & Information Design Cédric Scherer
Wrangle the Data trydb |> 1 filter(trait_name == "Leaf nitrogen (N) content per leaf area") |> 2 select(species_name, std_value) |> 3 arrange(-std_value) 4 # A tibble: 2,579 × 2 species_name std_value <chr> <dbl> 1 Pinus sylvestris 8.47 2 Pinus sylvestris 8.47 3 Pinus strobus 8.21 4 Pinus strobus 8.21 5 Pinus strobus 8.21 6 Picea abies 8.05 7 Picea abies 8.05 8 Picea abies 6.83 9 Picea abies 6.83 10 Pinus sylvestris 6.72 # ℹ 2,569 more rows Data Visua l ization & Information Design Cédric Scherer
Wrangle the Data trydb |> 1 filter(trait_name == "Leaf nitrogen (N) content per leaf area") |> 2 select(species_name, std_value) |> 3 arrange(-std_value) |> 4 mutate(genus_name = stringr::word(species_name, 1)) 5 # A tibble: 2,579 × 3 species_name std_value genus_name <chr> <dbl> <chr> 1 Pinus sylvestris 8.47 Pinus 2 Pinus sylvestris 8.47 Pinus 3 Pinus strobus 8.21 Pinus 4 Pinus strobus 8.21 Pinus 5 Pinus strobus 8.21 Pinus 6 Picea abies 8.05 Picea 7 Picea abies 8.05 Picea 8 Picea abies 6.83 Picea 9 Picea abies 6.83 Picea 10 Pinus sylvestris 6.72 Pinus # ℹ 2,569 more rows Data Visua l ization & Information Design Cédric Scherer
Wrangle the Data trydb |> 1 filter(trait_name == "Leaf nitrogen (N) content per leaf area") |> 2 select(species_name, std_value) |> 3 arrange(-std_value) |> 4 mutate(genus_name = stringr::word(species_name, 1)) |> 5 filter(genus_name == "Larix") 6 # A tibble: 23 × 3 species_name std_value genus_name <chr> <dbl> <chr> 1 Larix decidua 3.13 Larix 2 Larix decidua 2.7 Larix 3 Larix decidua 2.66 Larix 4 Larix decidua 2.46 Larix 5 Larix decidua 2.46 Larix 6 Larix decidua 2.46 Larix 7 Larix decidua 2.46 Larix 8 Larix decidua 2.46 Larix 9 Larix decidua 2.46 Larix 10 Larix decidua 2.46 Larix # ℹ 13 more rows Data Visua l ization & Information Design Cédric Scherer
Wrangle the Data trydb |> 1 filter(trait_name == "Leaf nitrogen (N) content per leaf area") |> 2 select(species_name, std_value) |> 3 arrange(-std_value) |> 4 filter(stringr::str_detect(species_name, "Larix")) 5 # A tibble: 23 × 2 species_name std_value <chr> <dbl> 1 Larix decidua 3.13 2 Larix decidua 2.7 3 Larix decidua 2.66 4 Larix decidua 2.46 5 Larix decidua 2.46 6 Larix decidua 2.46 7 Larix decidua 2.46 8 Larix decidua 2.46 9 Larix decidua 2.46 10 Larix decidua 2.46 # ℹ 13 more rows Data Visua l ization & Information Design Cédric Scherer
Wrangle the Data trydb |> 1 filter(trait_name == "Leaf nitrogen (N) content per leaf area") |> 2 group_by(species_name) |> 3 summarize(std_value_avg = mean(std_value, na.rm = TRUE)) |> 4 arrange(-std_value_avg) 5 # A tibble: 27 × 2 species_name std_value_avg <chr> <dbl> 1 Abies concolor 3.87 2 Picea engelmannii 3.15 3 Picea abies 3.11 4 Pinus uncinata 3.10 5 Pinus sylvestris 2.75 6 Pinus contorta 2.69 7 Pinus rigida 2.46 8 Pinus nigra 2.27 9 Abies alba 2.25 10 Pinus strobus 2.23 # ℹ 17 more rows Data Visua l ization & Information Design Cédric Scherer
Data Visualization with {ggplot2} Data Visua l ization & Information Design Cédric Scherer
Data Visua l ization & Information Design Cédric Scherer
{ggplot2} is a system for dec l arative l y creating graphics, based on <The Grammar of Graphics= (Wi l kinson, 2 00 5). You provide the data, te ll {ggplot2} how to , what graphica l primitives to use, and it takes care of the detai l s. map variab l es to aesthetics Data Visua l ization & Information Design Cédric Scherer
Advantages of {ggplot2} code-first approach → reproducib l e and transparent workf l ow consistent under l ying <grammar of graphics= very f l exib l e, l ayered p l ot specification theme system for po l ishing p l ot appearance l ots of additiona l functiona l ity thanks to extensions active and he l pfu l community Data Visua l ization & Information Design Cédric Scherer
ggp l ot2 Examp l es featured on ggp l ot2.tidyverse.org Data Visua l ization & Information Design Cédric Scherer
The ggplot2 Package An R package to visua l ize data created by Had l ey Wickham in 2 00 5 library(ggplot2) 1 Data Visua l ization & Information Design Cédric Scherer
ggplot2::ggplot() Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(data = trydb) + 1 aes(x = std_value, 2 y = trait_name) + 3 geom_boxplot() 4 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(data = trydb) + 1 aes(x = std_value, y = trait_name) + 2 geom_boxplot() 3 ggplot(data = trydb) + 1 aes( 2 x = std_value, 3 y = trait_name 4 ) + 5 geom_boxplot() 6 ggplot(data = trydb, 1 mapping = aes(x = std_value, y = trait_name)) + 2 geom_boxplot() 3 ggplot(trydb, 1 aes(std_value, trait_name)) + 2 geom_boxplot() 3 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb) + 1 aes( 2 x = std_value, 3 y = stringr::str_trunc(trait_name, 30) 4 ) + 5 geom_boxplot() 6 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb) + 1 aes( 2 x = std_value, 3 y = stringr::str_trunc(trait_name, 30) 4 ) + 5 geom_jitter() 6 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb) + 1 aes( 2 x = std_value, 3 y = stringr::str_trunc(trait_name, 30) 4 ) + 5 geom_jitter( 6 height = .3, 7 alpha = .05 8 ) 9 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb) + 1 aes( 2 x = std_value, 3 y = stringr::str_trunc(trait_name, 30) 4 ) + 5 geom_jitter( 6 height = .3, 7 alpha = .05 8 ) + 9 scale_x_log10() 1 0 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(data = trydb) + 1 aes( 2 x = std_value + 1, 3 y = stringr::str_trunc(trait_name, 30) 4 ) + 5 geom_jitter( 6 height = .3, 7 alpha = .05 8 ) + 9 scale_x_log10() 1 0 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb_nitro) + 1 aes(x = std_value) + 2 geom_histogram() 3 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb_nitro) + 1 aes(x = std_value) + 2 geom_histogram() + 3 facet_wrap( 4 ~ stringr::word(species_name, 1), 5 ncol = 2 6 ) 7 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb_nitro) + 1 aes( 2 x = std_value, 3 y = species_name 4 ) + 5 geom_boxplot() 6 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb_nitro) + 1 aes( 2 x = std_value, 3 y = species_name 4 ) + 5 stat_summary() 6 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(trydb_nitro) + 1 aes( 2 x = std_value, 3 y = species_name 4 ) + 5 stat_summary( 6 fun = "mean", 7 fun.min = function(x) mean(x, na.rm = TR 8 fun.max = function(x) mean(x, na.rm = TR 9 ) 1 0 Data Visua l ization & Information Design Cédric Scherer
Polish the Data Visualization ggplot(trydb_nitro) + 1 aes( 2 x = std_value, 3 y = species_name 4 ) + 5 stat_summary( 6 fun = "mean", 7 fun.min = function(x) mean(x, na.rm = TR 8 fun.max = function(x) mean(x, na.rm = TR 9 ) + 1 0 scale_x_continuous( 11 expand = expansion(add = c(0, .5)), 12 limits = c(0, NA), 13 labels = scales::number_format(suffix = 14 ) + 15 scale_y_discrete(limits = rev) + 16 labs( 17 x = "Leaf nitrogen (N) content per leaf 18 y = NULL 19 ) + 2 0 theme_minimal( 21 Data Visua l ization & Information Design Cédric Scherer
Polish the Data Visualization Data Visua l ization & Information Design Cédric Scherer
Data Visua l ization & Information Design Cédric Scherer
Polish the Data Visualization ggplot(trydb_nitro) + 1 aes( 2 x = std_value, 3 y = forcats::fct_reorder(species_name, s 4 ) + 5 stat_summary( 6 fun = "mean", 7 fun.min = function(x) mean(x, na.rm = TR 8 fun.max = function(x) mean(x, na.rm = TR 9 ) + 1 0 coord_cartesian(clip = "off") + 11 scale_x_continuous( 12 expand = expansion(add = c(0, .5)), 13 limits = c(0, NA), 14 labels = scales::number_format(suffix = 15 ) + 16 labs( 17 x = "Leaf nitrogen (N) content per leaf 18 y = NULL 19 ) + 2 0 theme_minimal( 21 Data Visua l ization & Information Design Cédric Scherer
Polish the Data Visualization ggplot(trydb_nitro) + 1 aes( 2 x = std_value, 3 y = forcats::fct_reorder(species_name, s 4 ) + 5 geom_jitter( 6 height = .25, 7 alpha = .3, 8 size = .6, 9 color = "grey60" 1 0 ) + 11 stat_summary( 12 fun = "mean", 13 fun.min = function(x) mean(x, na.rm = TR 14 fun.max = function(x) mean(x, na.rm = TR 15 ) + 16 coord_cartesian(clip = "off") + 17 scale_x_continuous( 18 expand = expansion(add = c(0, .5)), 19 limits = c(0, NA), 2 0 labels = scales::number_format(suffix = 21 Data Visua l ization & Information Design Cédric Scherer
Adjust the Data Detail trydb_nitro |> 1 mutate(genus_name = stringr::word(species_ 2 ggplot() + 3 aes( 4 x = std_value, 5 y = forcats::fct_reorder(genus_name, std_ 6 ) + 7 geom_jitter( 8 height = .25, 9 alpha = .2, 1 0 size = .6, 11 color = "grey60" 12 ) + 13 stat_summary( 14 fun = "mean", 15 fun.min = function(x) mean(x, na.rm = TR 16 fun.max = function(x) mean(x, na.rm = TR 17 ) + 18 coord_cartesian(clip = "off") + 19 scale_x_continuous( 2 0 expand = expansion(add = c(0, .5)), 21 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data ggplot(gbif_common) + 1 aes(y = forcats::fct_infreq(species)) + 2 geom_bar(width = .7) + 3 scale_y_discrete(limits = rev) 4 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data g <- 1 ggplot(gbif_common) + 2 aes(y = forcats::fct_infreq(species)) + 3 geom_bar( 4 aes(fill = species == "Quercus robur"), 5 width = .7 6 ) + 7 scale_y_discrete(limits = rev) + 8 scale_fill_manual( 9 values = c("grey50", "#28A87D"), guide = 1 0 ) + 11 labs( 12 x = "Number of observations in Germany", 13 y = NULL, 14 caption = "Data: Global Biodiversity Inf 15 ) + 16 theme_minimal( 17 base_family = "Roboto Condensed", 18 base_size = 14 19 ) 2 0 21 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data g + 1 coord_cartesian(clip = "off") + 2 scale_x_continuous( 3 expand = expansion(add = c(0, .5)), 4 limits = c(0, NA), 5 labels = scales::comma 6 ) + 7 theme( 8 panel.grid.minor = element_blank(), 9 panel.grid.major.y = element_blank(), 1 0 axis.title.x = element_text(hjust = 0), 11 axis.text.y = element_text(face = "itali 12 plot.caption = element_text(color = "gre 13 plot.caption.position = "plot" 14 ) 15 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data g + 1 stat_count( 2 geom = "text", 3 aes(label = after_stat(count)), 4 hjust = 1.1, 5 family = "Roboto Condensed", 6 color = "white", 7 fontface = "bold" 8 ) + 9 scale_x_continuous( 1 0 expand = expansion(add = c(0, .5)), 11 limits = c(0, NA), 12 guide = "none", 13 name = NULL 14 ) + 15 labs(title = "The English oak (Quercus rob 16 theme( 17 panel.grid.minor = element_blank(), 18 panel.grid.major = element_blank(), 19 axis.text.y = element_text(face = "itali 2 0 plot.caption = element_text(color = "gre 21 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data g + 1 stat_count( 2 geom = "text", 3 aes(label = after_stat(format(count, big 4 hjust = 1.2, 5 family = "Roboto Condensed", 6 color = "white", 7 fontface = "bold" 8 ) + 9 scale_x_continuous( 1 0 expand = expansion(add = c(0, .5)), 11 limits = c(0, NA), 12 guide = "none", 13 name = NULL 14 ) + 15 labs(title = "The English oak (Quercus rob 16 theme( 17 panel.grid.minor = element_blank(), 18 panel.grid.major = element_blank(), 19 axis.text.y = element_text(face = "itali 2 0 plot.caption = element_text(color = "gre 21 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data g + 1 stat_count( 2 geom = "text", 3 aes(label = after_stat(format(count, big 4 hjust = 1.2, 5 family = "Roboto Condensed", 6 color = "white", 7 fontface = "bold" 8 ) + 9 scale_x_continuous( 1 0 expand = expansion(add = c(0, .5)), 11 limits = c(0, NA), 12 guide = "none", 13 name = NULL 14 ) + 15 labs(title = "The English oak (*Quercus ro 16 theme( 17 panel.grid.minor = element_blank(), 18 panel.grid.major = element_blank(), 19 axis.text.y = element_text(face = "itali 2 0 plot.caption = element_text(color = "gre 21 Data Visua l ization & Information Design Cédric Scherer
Visualize the Data g + 1 stat_count( 2 geom = "text", 3 aes(label = after_stat(format(count, big 4 hjust = 1.1, 5 family = "Roboto Condensed", 6 color = "white", 7 fontface = "bold" 8 ) + 9 scale_x_continuous( 1 0 expand = expansion(add = c(0, .5)), 11 limits = c(0, NA), 12 guide = "none", 13 name = NULL 14 ) + 15 labs(title = "The <span style='color:#28A8 16 theme( 17 panel.grid.minor = element_blank(), 18 panel.grid.major = element_blank(), 19 axis.text.y = element_text(face = "itali 2 0 plot.caption = element_text(color = "gre 21 Data Visua l ization & Information Design Cédric Scherer
Save the Graphic ## save stored plot 1 ggsave(filename = "my_plot.png", plot = g) 2 ## save last plot (with implicit matching of `filename`) 1 ggsave("my_plot.png") 2 ## save last plot with custom settings 1 ggsave("my_plot.png", width = 6.7, height = 5, dpi = 600) 2 ## save last plot with custom unit 1 ggsave("my_plot.png", width = 17.02, height = 12.7, unit = "cm", dpi = 600) 2 ## save last plot as PDF file 1 ggsave("my_plot.pdf", width = 6.7, height = 5, device = cairo_pdf) 2 ## save last plot as SVG file 1 ggsave("my_plot.svg", width = 6.7, height = 5) 2 Data Visua l ization & Information Design Cédric Scherer
Wrap-Up Data Visua l ization & Information Design Cédric Scherer
The Components of a ggplot Component Function Explanation Data ggplot(data) The raw data that you want to visualize (initializing a plot). Aesthetics aes() The mapping between variables and visual properties. Geometries geom_*() The geometric shape of a layer representing the data. Statistics stat_*() The statistical transformation of a layer applied to the data. Scales scale_*() The representation of mapped aesthetic attributes. Coordinate System coord_*() The transformation to map data coordinates into the plot plane. Facets facet_*() The arrangement of the data into a set of small multiples. Visual Themes theme() | theme_*() The overall visual defaults of nondata elements of the graphic. Data Visua l ization & Information Design Cédric Scherer
Thank You! // www.cedricscherer.com www. l inktr.ee/CedScherer Data Visua l ization & Information Design Cédric Scherer