Day 6
in-class
- Color vs fill
tibble(
group = c("a", "b", "c"),
n = 1:3
) |>
ggplot(
aes(
x = group,
y = n
)
)+
geom_col(
aes(
fill = group
),
color = "black"
)+
scale_fill_brewer(palette = "Dark2")
Data operations
filter
babynames |>
filter(
name == "Josef"
)
mutate
combo
Split-Apply-Combine
.by
or group_by()
`filter()`
Be sure to load the tidyverse before using filter()
!
babynames |>
mutate(nchar = nchar(name)) |>
summarise(
.by = c(year, sex),
total = sum(n),
nchar_w = sum(nchar * n)/total
) |>
ggplot(
aes(year, nchar_w)
)+
geom_point()
tibble(
day = c(
"Monday", "Tuesday",
"Monday", "Tuesday", "Wednesday"
),
name = c(
"Oakley", "Oakley",
"Skyler", "Skyler", "Skyler"
),
lines = c(
10, 30,
5, 5, 10
)
)->
collab_df
collab_df
collab_df |>
left_join(yob) ->
collab_df
collab_df |>
left_join(total_babies)
data("pb52", package = "phonTools")
vowel_means |>
ggplot(
aes(-f2, -f1)
)+
geom_text(
aes(label = vowel)
)+
facet_wrap(~type)
tibble(
month=month.name
) |>
mutate(
oysters = case_when(
str_detect(month, "r$") ~ "ok",
.default = "no"
)
)
Reuse
CC-BY 4.0
Citation
BibTeX citation:
@online{fruehwald2024,
author = {Fruehwald, Josef},
title = {Day 6},
date = {2024-09-16},
url = {https://lin611-2024.github.io/notes/in-class/2024-09-16_day6.html},
langid = {en}
}
For attribution, please cite this work as:
Fruehwald, Josef. 2024. “Day 6.” September 16, 2024. https://lin611-2024.github.io/notes/in-class/2024-09-16_day6.html.