data <- read_excel("../00_data/myData.xlsx")
set.seed(12345)
data_small <- data %>%
select(egg_group_1, attack) %>%
slice(1:20)
data_small %>% count(egg_group_1)
## # A tibble: 4 × 2
## egg_group_1 n
## <chr> <int>
## 1 bug 6
## 2 flying 3
## 3 ground 2
## 4 monster 9
egg_group_1_levels <- c("monster", "bug", "flying", "ground")
data_rev <- data_small %>%
mutate(egg_group_1 = egg_group_1 %>% factor(levels = egg_group_1_levels))
Make two bar charts here - one before ordering another after
data_summary <- data_small %>%
group_by(egg_group_1) %>%
summarise(
attack = mean(attack, na.rm = TRUE))
ggplot(data_summary, aes(attack, egg_group_1)) + geom_point()
ggplot(data_summary, aes(attack, fct_reorder(egg_group_1, attack))) + geom_point()
Show examples of three functions:
data_small %>%
mutate(egg_group_1 = fct_recode(egg_group_1,
"ground_egg" = "ground",
"monster_egg" = "monster",
"flying_egg" = "flying",
"bug_egg" = "bug")) %>%
count(egg_group_1)
## # A tibble: 4 × 2
## egg_group_1 n
## <fct> <int>
## 1 bug_egg 6
## 2 flying_egg 3
## 3 ground_egg 2
## 4 monster_egg 9
data_small %>%
mutate(egg_group_1 = fct_collapse(egg_group_1,
"ground_egg" = "ground",
other = c("monster", "flying", "bug"))) %>%
count(egg_group_1)
## # A tibble: 2 × 2
## egg_group_1 n
## <fct> <int>
## 1 other 18
## 2 ground_egg 2
data_small %>%
mutate(egg_group_1 = fct_lump(egg_group_1)) %>%
count(egg_group_1)
## # A tibble: 3 × 2
## egg_group_1 n
## <fct> <int>
## 1 bug 6
## 2 monster 9
## 3 Other 5
No need to do anything here.