-
Notifications
You must be signed in to change notification settings - Fork 11
/
03-individual_geoms.Rmd
112 lines (89 loc) · 3.39 KB
/
03-individual_geoms.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# (PART\*) Layers {-}
# Individual Geoms
```{r 03-individualgeoms, include=FALSE}
library(ggplot2)
library(tidyverse)
```
- Geoms are the fundamental building blocks of ggplot2.
- Most of the geoms are associated with a named plot.
- Some geoms can be added on to low-level geoms to create more complex plots.
- To find out more about individual geoms see their documentation.
## Scatterplot:
```{r 03-scatter}
ggplot(mpg, aes(x = displ, y = hwy)) +
geom_point()
```
## Line plot:
```{r 03-lineplot}
ggplot(economics, aes(date, unemploy / pop)) +
geom_line()
```
## Histogram:
```{r 03-hist}
ggplot(mpg, aes(hwy)) + geom_histogram()
```
## Bar chart
```{r 03-bar}
ggplot(mpg, aes(manufacturer)) +
geom_bar()
```
## geom_path() connects points in order of appearance.
```{r 03-df, include=FALSE}
df <- data.frame(
x = c(3, 1, 5),
y = c(2, 4, 6),
label = c("a","b","c")
)
p <- ggplot(df, aes(x, y, label = label)) +
labs(x = NULL, y = NULL) + # Hide axis label
theme(plot.title = element_text(size = 12))
```
```{r 03-path}
p + geom_path()
```
## geom_polygon() draws polygons which are filled paths.
```{r 03-poly}
p + geom_polygon()
```
## geom_line() connects points from left to right.
```{r 03-line}
p + geom_line()
```
## What low-level geoms are used to draw geom_smooth()?
Geom_smooth() fits a smoother to data, displaying the smooth and its standard error, allowing you to see a dominant pattern within a scatterplot with a lot of "noise". The low level geom for geom_smooth() are geom_path(), geom_area() and geom_point().
```{r 03-smooth}
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth()
```
## What low-level geoms are used to draw geom_boxplot()?
Box plots are used to summarize the distribution of a set of points using summary statistics. The low level geom for geom_boxplot() are geom_rect(), geom_line() and geom_point().
```{r 03-box}
ggplot(mpg, aes(drv, hwy)) + geom_boxplot()
```
## What low-level geoms are used to draw geom_violin()?
Violin plots show a compact representation of the density of the distribution highlighting the areas where most of the points are found. The low level geom for geom_violin() are geom_area() and geom_path().
```{r 03-violin}
ggplot(mpg, aes(drv, hwy)) + geom_violin()
```
## Meeting Videos
### Cohort 1
`r knitr::include_url("https://www.youtube.com/embed/XcTYBH4XbHo")`
<details>
<summary> Meeting chat log </summary>
```
00:13:39 priyanka gagneja: I forgot to mention that since this is relatively smaller chapter Ryan has prepared some material introducing Chapter 4 for today and he will talking about the entire chapter next week.
00:16:38 priyanka gagneja: that's correct
00:16:42 priyanka gagneja: that's my understanding too
00:18:38 priyanka gagneja: what do you mean circles .. can you share a more detailed example
00:21:59 Jiwan Heo: tibble(id = 1:10) %>% mutate(x = cos(2*pi*id/10), y = sin(2*pi*id/10)) %>% ggplot(aes(x, y)) + geom_line() + coord_equal()
00:22:05 Jiwan Heo: vs tibble(id = 1:10) %>% mutate(x = cos(2*pi*id/10), y = sin(2*pi*id/10)) %>% ggplot(aes(x, y)) + geom_path() + coord_equal()
00:35:42 priyanka gagneja: Thank you Ryan !!
00:38:16 priyanka gagneja: need a min
00:52:22 Michael Haugen: “Side rail” no pun intended
00:52:34 Ryan S: lol
00:52:34 Michael Haugen: sounds great
00:54:02 Ryan Metcalf: I was going to use Derail…..no pun intended!
00:54:05 Ryan Metcalf: Thanks you everyone!
```
</details>