Explore Nat0718

Harold Nelson

2/24/2020

Libraries and Data

library(tidyverse)
## ── Attaching packages ──────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.2.1     ✓ purrr   0.3.3
## ✓ tibble  2.1.3     ✓ dplyr   0.8.4
## ✓ tidyr   1.0.2     ✓ stringr 1.4.0
## ✓ readr   1.3.1     ✓ forcats 0.4.0
## ── Conflicts ─────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
load("/cloud/project/Nat0718.Rdata")

Ex1

Create birthrates by Race, yr and Age and display them graphically.

Nat0718 %>% 
  group_by(Race,yr,Age) %>% 
  summarize(Births = sum(Births),
            Fpop = sum(Fpop)) %>% 
  ungroup() %>% 
  mutate(Rate = Births/Fpop) -> byRaceYr

byRaceYr %>% 
  ggplot(aes(x=yr,y=Rate,color=Race)) + 
  geom_point(size=.2) +
  facet_wrap(~Age)

Ex2

Create birthrates by Region, yr and Age and display them graphically.

Nat0718 %>% 
  group_by(Region,yr,Age) %>% 
  summarize(Births = sum(Births),
            Fpop = sum(Fpop)) %>% 
  ungroup() %>% 
  mutate(Rate = Births/Fpop) -> byRegionYr

byRegionYr %>% 
  ggplot(aes(x=yr,y=Rate,color=Region)) + 
  geom_point(size=.2) +
  facet_wrap(~Age)