Concepts of the {ggplot2}
Package Pt. 1:
Data, Aesthetics, and Layers + Misc Stuff
… is an R package to visualize data created by Hadley Wickham in 2005
… is part of the {tidyverse}
Component | Function | Explanation |
---|---|---|
Data |
ggplot(data)
|
The raw data that you want to visualise. |
Aesthetics |
aes()
|
Aesthetic mappings between variables and visual properties. |
Geometries |
geom_*()
|
The geometric shapes representing the data. |
Component | Function | Explanation |
---|---|---|
Data |
ggplot(data)
|
The raw data that you want to visualise. |
Aesthetics |
aes()
|
Aesthetic mappings between variables and visual properties. |
Geometries |
geom_*()
|
The geometric shapes representing the data. |
Statistics |
stat_*()
|
The statistical transformations applied to the data. |
Scales |
scale_*()
|
Maps between the data and the aesthetic dimensions. |
Coordinate System |
coord_*()
|
Maps data into the plane of the data rectangle. |
Facets |
facet_*()
|
The arrangement of the data into a grid of plots. |
Visual Themes |
theme() / theme_*()
|
The overall visual defaults of a plot. |
Bike sharing counts in London, UK, powered by TfL Open Data
Variable | Description | Class |
---|---|---|
date | Date encoded as `YYYY-MM-DD` | date |
day_night | `day` (6:00am–5:59pm) or `night` (6:00pm–5:59am) | character |
year | `2015` or `2016` | factor |
month | `1` (January) to `12` (December) | factor |
season | `winter`, `spring`, `summer`, or `autumn` | factor |
count | Sum of reported bikes rented | integer |
is_workday | `TRUE` being Monday to Friday and no bank holiday | logical |
is_weekend | `TRUE` being Saturday or Sunday | logical |
is_holiday | `TRUE` being a bank holiday in the UK | logical |
temp | Average air temperature (°C) | double |
temp_feel | Average feels like temperature (°C) | double |
humidity | Average air humidity (%) | double |
wind_speed | Average wind speed (km/h) | double |
weather_type | Most common weather type | character |
ggplot2::ggplot()
= link variables to graphical properties
x
, y
)color
, fill
)shape
, linetype
)size
)alpha
)group
)aes()
outside as component
= interpret aesthetics as graphical representations
temp_feel
vs temp
.
# A tibble: 1,454 x 14
date day_night year month season count is_workday is_weekend
<date> <chr> <fct> <fct> <fct> <int> <lgl> <lgl>
1 2015-01-04 day 2015 1 winter 6830 FALSE TRUE
2 2015-01-04 night 2015 1 winter 2404 FALSE TRUE
3 2015-01-05 day 2015 1 winter 14763 TRUE FALSE
4 2015-01-05 night 2015 1 winter 5609 TRUE FALSE
5 2015-01-06 day 2015 1 winter 14501 TRUE FALSE
6 2015-01-06 night 2015 1 winter 6112 TRUE FALSE
7 2015-01-07 day 2015 1 winter 16358 TRUE FALSE
8 2015-01-07 night 2015 1 winter 4706 TRUE FALSE
9 2015-01-08 day 2015 1 winter 9971 TRUE FALSE
10 2015-01-08 night 2015 1 winter 5630 TRUE FALSE
# ... with 1,444 more rows, and 6 more variables: is_holiday <lgl>, temp <dbl>,
# temp_feel <dbl>, humidity <dbl>, wind_speed <dbl>, weather_type <chr>
# install.packages("systemfonts")
library(systemfonts)
system_fonts() %>%
filter(str_detect(family, "Cabinet")) %>%
pull(name) %>%
sort()
[1] "CabinetGrotesk-Black" "CabinetGrotesk-Black"
[3] "CabinetGrotesk-Bold" "CabinetGrotesk-Bold"
[5] "CabinetGrotesk-Extrabold" "CabinetGrotesk-Extrabold"
[7] "CabinetGrotesk-Extralight" "CabinetGrotesk-Extralight"
[9] "CabinetGrotesk-Light" "CabinetGrotesk-Light"
[11] "CabinetGrotesk-Medium" "CabinetGrotesk-Medium"
[13] "CabinetGrotesk-Regular" "CabinetGrotesk-Regular"
[15] "CabinetGrotesk-Thin" "CabinetGrotesk-Thin"
fig.width
and fig.height
per chunk or globallyggplot()
calls and displays it in the viewer pane{ggplot2}
is a powerful library for reproducible graphic designaes()
aes()
theme_set()
theme_update()
exercises/02_concepts_pt1_ex1.qmd
.geom_line()
and geom_path()
?exercises/02_concepts_pt1_ex2.qmd
.Cédric Scherer // rstudio::conf // July 2022