Welcome to the workshop on ggplot.
Where we'll show you how to create impressive data visualisations.
Eugene Hickey
January 21st 2021
Graphic by Elaine Hickey
Welcome to the workshop on ggplot.
Where we'll show you how to create impressive data visualisations.
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
library(rtist)par(mfrow = c(3, 5))map(names(rtist_palettes), function(x) print(rtist_palette(x)))
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
N <- 10data.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())
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
col2rgb(), also col2hex() from the gplots (not ggplot2) package, and col2hcl from the jmw86069/jamba package
colorfindr takes an image and identifies major colours
intro-ggplot-nhs — Eugene Hickey
## # 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
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
dslabs::gapminder %>% ggplot(aes(x = life_expectancy, fill = ..x..)) + geom_histogram() + scale_fill_continuous(type = 'viridis')
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
sex <- c("Female", "Male")names(sex) <- c("F", "M")cats ### cats dataset from MASS
## 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
intro-ggplot-nhs — Eugene Hickey
sex <- c("Female", "Male")names(sex) <- c("F", "M")cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt))
intro-ggplot-nhs — Eugene Hickey
sex <- c("Female", "Male")names(sex) <- c("F", "M")cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + geom_point()
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
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))
intro-ggplot-nhs — Eugene Hickey
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)")
intro-ggplot-nhs — Eugene Hickey
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()
intro-ggplot-nhs — Eugene Hickey
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"))
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
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())
intro-ggplot-nhs — Eugene Hickey
## snails dataset from the MASS librarysnails
## 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
intro-ggplot-nhs — Eugene Hickey
## snails dataset from the MASS librarysnails %>% ggplot(aes(Exposure, Deaths, col = factor(Rel.Hum))) + geom_line() + geom_point() + theme(legend.title = element_blank())
intro-ggplot-nhs — Eugene Hickey
## snails dataset from the MASS librarysnails %>% ggplot(aes(Exposure, Deaths, col = factor(Rel.Hum))) + geom_line() + geom_point() + theme(legend.title = element_blank()) + facet_grid(Species ~ Temp, scales = "free")
intro-ggplot-nhs — Eugene Hickey
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
o | Tile View: Overview of Slides |
Esc | Back to slideshow |
Eugene Hickey
January 21st 2021
Graphic by Elaine Hickey
Welcome to the workshop on ggplot.
Where we'll show you how to create impressive data visualisations.
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
library(rtist)par(mfrow = c(3, 5))map(names(rtist_palettes), function(x) print(rtist_palette(x)))
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
N <- 10data.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())
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
col2rgb(), also col2hex() from the gplots (not ggplot2) package, and col2hcl from the jmw86069/jamba package
colorfindr takes an image and identifies major colours
intro-ggplot-nhs — Eugene Hickey
## # 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
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
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')
intro-ggplot-nhs — Eugene Hickey
dslabs::gapminder %>% ggplot(aes(x = life_expectancy, fill = ..x..)) + geom_histogram() + scale_fill_continuous(type = 'viridis')
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
intro-ggplot-nhs — Eugene Hickey
sex <- c("Female", "Male")names(sex) <- c("F", "M")cats ### cats dataset from MASS
## 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
intro-ggplot-nhs — Eugene Hickey
sex <- c("Female", "Male")names(sex) <- c("F", "M")cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt))
intro-ggplot-nhs — Eugene Hickey
sex <- c("Female", "Male")names(sex) <- c("F", "M")cats %>% ### cats dataset from MASS ggplot(aes(Bwt, Hwt)) + geom_point()
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
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))
intro-ggplot-nhs — Eugene Hickey
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)")
intro-ggplot-nhs — Eugene Hickey
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()
intro-ggplot-nhs — Eugene Hickey
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"))
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
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)
intro-ggplot-nhs — Eugene Hickey
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())
intro-ggplot-nhs — Eugene Hickey
## snails dataset from the MASS librarysnails
## 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
intro-ggplot-nhs — Eugene Hickey
## snails dataset from the MASS librarysnails %>% ggplot(aes(Exposure, Deaths, col = factor(Rel.Hum))) + geom_line() + geom_point() + theme(legend.title = element_blank())
intro-ggplot-nhs — Eugene Hickey
## snails dataset from the MASS librarysnails %>% ggplot(aes(Exposure, Deaths, col = factor(Rel.Hum))) + geom_line() + geom_point() + theme(legend.title = element_blank()) + facet_grid(Species ~ Temp, scales = "free")