library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.2
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.5
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.3 ✔ forcats 0.5.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(janitor)
## Warning: package 'janitor' was built under R version 4.2.2
##
## Attaching package: 'janitor'
##
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
load("C:/Users/grifw/Downloads/TFR_long.Rdata")
load("C:/Users/grifw/Downloads/IMR_long.Rdata")
miss = anti_join(IMR_long,
TFR_long,
by = c("country_name","year"))
nrow(miss)
## [1] 0
IMR_TFR = IMR_long %>%
left_join(TFR_long,
by = c("country_name",
"country_code",
"year"))
glimpse(IMR_TFR)
## Rows: 16,226
## Columns: 5
## $ country_name <chr> "Aruba", "Aruba", "Aruba", "Aruba", "Aruba", "Aruba", "Ar…
## $ country_code <chr> "ABW", "ABW", "ABW", "ABW", "ABW", "ABW", "ABW", "ABW", "…
## $ year <dbl> 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 196…
## $ IMR <dbl> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, N…
## $ TFR <dbl> 4.820, 4.655, 4.471, 4.271, 4.059, 3.842, 3.625, 3.417, 3…
g = IMR_TFR %>%
ggplot(aes(IMR,TFR,group = country_name)) +
geom_point(size = .1)
ggplotly(g)
g = IMR_TFR %>%
ggplot(aes(IMR,TFR,group = country_name)) +
geom_jitter(size = .1)+
labs(x="Infant Mortality Rate(per 1000 Births", y= "Total Fertility Rate",
title="Infant Mortality Rate vs Total Fertility Rate")
ggplotly(g)
g = IMR_TFR %>%
ggplot(aes(IMR,TFR,group = country_name)) +
geom_jitter(size = .1,aes(color = factor(country_name)))+
labs(x="Infant Mortality Rate(per 1000 Births", y= "Total Fertility Rate",
title="Infant Mortality Rate vs Total Fertility Rate")
ggplotly(g)
g = IMR_TFR %>%
ggplot(aes(IMR,TFR,group = country_name)) +
geom_jitter(size = .15,aes(color = factor(country_name)))+
labs(x="Infant Mortality Rate(per 1000 Births", y= "Total Fertility Rate",
title="Infant Mortality Rate vs Total Fertility Rate")+
theme_bw()+
guides(color = guide_legend(title = "Country Name"))
ggplotly(g)