-
Notifications
You must be signed in to change notification settings - Fork 16
/
06-Polishing-plots.Rmd
87 lines (58 loc) · 1.62 KB
/
06-Polishing-plots.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
title: "Visualizing New House Price Index"
output: html_document
---
<!-- This file by Charlotte Wickham is licensed under a Creative Commons Attribution 4.0 International License. -->
```{r setup}
library(tidyverse)
housing <- read_csv("data/housing_bc.csv")
diamonds_plot <- ggplot(data = diamonds) +
geom_bar(mapping = aes(x = cut, fill = clarity))
```
## Your turn 1
**Discuss with your neighbours:**
What would you want to change before publishing this plot?
```{r}
basic_plot <- housing %>%
filter(geography %in% c("Canada", "British Columbia (12)")) %>%
ggplot(mapping = aes(x = date, y = total)) +
geom_line(aes(color = geography))
basic_plot
```
## Your turn 2
I've applied the diamond labels to the housing price plot. Edit the code to add appropriate labelling to the house price plot.
```{r}
basic_plot +
labs(title = "Diamonds data",
subtitle = "Most diamonds are Ideal cut",
caption = "Data from ggplot2::diamonds",
x = "Diamond Cut",
fill = "Clarity"
)
```
## Your turn 3
Add a theme to basic_plot. Try a few and pick one you like.
```{r}
basic_plot
```
## Your turn 4
Add a brewer scale to the basic_plot.
```{r}
basic_plot
```
## Your turn 5
Choose a better color palette for the brewer scale.
```{r}
basic_plot + scale_color_brewer()
```
## Your turn 6
Put the labels, theme and scale changes together for basic_plot.
What is left to change?
```{r}
basic_plot
```
## Takeaways
Every visual element on a ggplot plot can be controlled. The most frequent changes you want to make are to:
* Labels, `+ labs()`
* Themes, `+ theme_bw()`
* Scales `+ scale_*_*()`