Harold Nelson
2022-09-26
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.7
## ✓ tidyr 1.1.4 ✓ stringr 1.4.0
## ✓ readr 2.1.1 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
Look at the graphics of Age, Sex, Race, and Childs
p <- ggplot(data = gss_sm,
mapping = aes(x = age, y = childs))
p + geom_point(alpha = 0.2) +
geom_smooth() +
facet_grid(sex ~ race)
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
## Warning: Removed 18 rows containing non-finite values (stat_smooth).
## Warning: Removed 18 rows containing missing values (geom_point).
Look at this variable in the gss_sm dataframe.
## Age 18-35 Age 35-45 Age 45-55 Age 55-65 Age 65+ NA's
## 786 452 510 529 573 17
We can use this as a categorical variable to investigate these relationships.
Make use of this variable (or not) to get a different visualization. See what you can do.
p = gss_sm %>%
filter(agegrp == "Age 35-45") %>%
na.omit() %>%
ggplot(aes(x = childs)) +
geom_density(aes(color = race),adjust = .3)
p
## Free the y scale.
## Filter to 35-45
g = gss_sm %>%
filter(age >= 35 & age < 45) %>%
na.omit() %>%
ggplot((aes(x= childs))) + geom_density(adjust = .2)
g
## Facet by Race
## Filter for 65 +
g = gss_sm %>%
filter(age >= 65 ) %>%
na.omit() %>%
ggplot((aes(x= childs))) + geom_density(adjust = .2)
g