forked from CrumpLab/LabJournalWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPresentation-Final.Rmd
More file actions
169 lines (97 loc) · 2.24 KB
/
Presentation-Final.Rmd
File metadata and controls
169 lines (97 loc) · 2.24 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
---
title: "Presentation in R Markdown"
subtitle: "Forcats package"
author: "Angelina Vasquez"
date: "2019/5/15 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
class: inverse, center, middle
# Forcats Package
-This package is used when you want to do things with categorical data
--
-i.e. different levels or conditions of an experiment
---
class: inverse, center, middle
# Why I chose this Package
```{r echo=FALSE}
knitr::include_graphics("images/CuteCat.jpg")
```
---
class: inverse, center, middle
# Getting Started
Install the **forcats** package from [Github](https://github.com/tidyverse/forcats):
```{r eval=FALSE, tidy=FALSE}
devtools::install_github("tidyverse/forcats")
```
--
-Forcats is part of Tidyverse
--
-You can install the package tidyverse which will also install forcats
--
-or you can use devtools to get straight to forcats
---
class: inverse, center, middle
# You Have it Installed, Now What?
-Do you have categorical data?
--
-Do you want to do something with that categorical data?
--
-Use forcats and it's dependicies to do that thing with categorical data
---
class: inverse, center, middle
# What you Can do With Forcats
-Reordering a factor with a variable
--
-Use fct_reorder()
--
-Reordering a factor by frequency
--
-Use fct_infreq()
--
-Changing the order of the factors by hand
--
-Use fct_relevel()
--
-Collapsing the values of a factor into and "other" category
--
-Use fct_lump()
---
class: inverse, center, middle
# Why do we care?
-Heres some examples
```{r include=FALSE}
library(forcats)
library(dplyr)
library(ggplot2)
```
```{r echo=FALSE}
knitr::include_graphics("images/1200px-Star_wars2.svg.png")
```
---
class: inverse, center, middle
# Using fct_lump()
```{r}
starwars %>%
filter(!is.na(species)) %>%
mutate(species = fct_lump(species, n = 3)) %>%
count(species)
```
---
class: inverse, center, middle
# Using fct_infrequ()
```{r}
starwars %>%
mutate(eye_color = fct_infreq(eye_color)) %>%
ggplot(aes(x = eye_color)) +
geom_bar() +
coord_flip()
```