Project Part 1

Preparing the marriage rate per 1000 people for plotting.

  1. I downloaded marriage rate data from(https://ourworldindata.org). I selected this data because I am interested in the changing rates of marriage in the America’s over time, after the 1970’s.

  2. This is the link (https://ourworldindata.org/marriages-and-divorces) to the data

  3. The following code chunk loads the package I will use to read and prepare the data

  1. Read the data in
    marriage_rate_by_country <-
      read.csv(here::here("_posts/2022-05-10-project-part-1/marriage-rate-per-1000-inhabitants.csv"))
    
  1. Use Glimpse to see the names and types of the columns
    glimpse(marriage_rate_by_country)
    
Rows: 3,251
Columns: 4
$ Entity                                      <chr> "Albania", "Alba~
$ Code                                        <chr> "ALB", "ALB", "A~
$ Year                                        <int> 1960, 1961, 1962~
$ Crude.marriage.rate..per.1.000.inhabitants. <dbl> 7.8, 11.3, 7.5, ~
view(marriage_rate_by_country)
  1. Use output fromglimpse(and view) to prepare data for analysis

-Create the object ‘countries’ that is a list of regions I want to extract from the data set

-change the name of the first column to “country” and the 4th to “marriage_rate”

-Use filter to extract the rows I want to keep: year >=1970

-select the columns to keep; Country, year, marriage_rate.

-use mutate to convert marriage_rate

–Display 10 rows of regional marriage

countries <- c("United States",
              "Puerto Rico",
              "Costa Rica",
              "Cuba",
              "Brazil",
              "Canada",
              "Guatemala",
              "Mexico",
              "Uruguay",
              "El Salvador",
              "Paraguay",
              "Chile",
              "Colombia")

regional_marriage <- marriage_rate_by_country %>%
  rename(Country = 1, MarriageRate = 4) %>%
  filter(Year >= 1970, Country %in% countries) %>%
  select(Country, Year, MarriageRate)

regional_marriage
          Country Year MarriageRate
1          Brazil 1970          1.2
2          Brazil 1985          7.0
3          Brazil 2004          4.4
4          Brazil 2005          4.5
5          Brazil 2006          4.7
6          Canada 1970          8.8
7          Canada 1971          8.9
8          Canada 1972          9.2
9          Canada 1973          9.0
10         Canada 1974          8.9
11         Canada 1975          8.7
12         Canada 1976          8.4
13         Canada 1977          8.0
14         Canada 1978          7.9
15         Canada 1979          7.8
16         Canada 1980          7.8
17         Canada 1981          7.7
18         Canada 1982          7.5
19         Canada 1983          7.3
20         Canada 1984          7.2
21         Canada 1985          7.1
22         Canada 1986          6.7
23         Canada 1987          6.9
24         Canada 1988          7.0
25         Canada 1989          7.0
26         Canada 1990          6.8
27         Canada 1991          6.1
28         Canada 1992          5.8
29         Canada 1993          5.6
30         Canada 1994          5.5
31         Canada 1995          5.5
32         Canada 1996          5.3
33         Canada 1997          5.1
34         Canada 1998          5.1
35         Canada 1999          5.1
36         Canada 2000          5.1
37         Canada 2001          4.7
38         Canada 2002          4.7
39         Canada 2003          4.7
40         Canada 2004          4.6
41         Canada 2005          4.6
42         Canada 2006          4.6
43         Canada 2007          4.5
44         Canada 2008          4.4
45          Chile 1970          8.1
46          Chile 1985          7.5
47          Chile 1992          6.6
48          Chile 1993          6.7
49          Chile 1994          6.5
50          Chile 1995          6.1
51          Chile 1996          5.8
52          Chile 1997          5.3
53          Chile 1998          5.0
54          Chile 1999          4.6
55          Chile 2000          4.4
56          Chile 2001          4.1
57          Chile 2002          3.9
58          Chile 2003          3.6
59          Chile 2004          3.3
60          Chile 2005          3.3
61          Chile 2006          3.5
62          Chile 2007          3.5
63          Chile 2008          3.3
64          Chile 2009          3.3
65          Chile 2010          3.5
66          Chile 2011          3.8
67          Chile 2012          3.7
68          Chile 2013          3.5
69          Chile 2014          3.6
70          Chile 2015          3.4
71          Chile 2016          3.4
72       Colombia 1970          2.4
73       Colombia 1986          2.2
74     Costa Rica 1970          6.3
75     Costa Rica 1971          6.3
76     Costa Rica 1972          7.0
77     Costa Rica 1973          6.8
78     Costa Rica 1974          7.3
79     Costa Rica 1975          7.3
80     Costa Rica 1976          7.2
81     Costa Rica 1977          7.3
82     Costa Rica 1978          7.6
83     Costa Rica 1979          7.6
84     Costa Rica 1980          7.6
85     Costa Rica 1981          7.0
86     Costa Rica 1982          7.6
87     Costa Rica 1983          7.7
88     Costa Rica 1984          7.9
89     Costa Rica 1985          8.0
90     Costa Rica 1986          7.7
91     Costa Rica 1987          7.8
92     Costa Rica 1988          8.0
93     Costa Rica 1989          7.8
94     Costa Rica 1990          7.5
95     Costa Rica 1991          7.2
96     Costa Rica 1992          6.6
97     Costa Rica 1993          6.3
98     Costa Rica 1994          6.5
99     Costa Rica 1995          7.1
100    Costa Rica 1996          6.7
101    Costa Rica 1997          6.7
102    Costa Rica 1998          6.7
103    Costa Rica 1999          6.8
104    Costa Rica 2000          6.3
105    Costa Rica 2001          6.0
106    Costa Rica 2002          5.9
107    Costa Rica 2003          6.0
108    Costa Rica 2004          6.1
109    Costa Rica 2005          6.1
110    Costa Rica 2006          6.2
111    Costa Rica 2007          6.0
112    Costa Rica 2008          5.7
113    Costa Rica 2009          5.4
114    Costa Rica 2010          5.3
115    Costa Rica 2011          5.4
116    Costa Rica 2012          5.6
117    Costa Rica 2013          5.5
118    Costa Rica 2014          5.4
119    Costa Rica 2015          5.5
120    Costa Rica 2016          5.5
121    Costa Rica 2017          5.2
122          Cuba 1970         13.4
123          Cuba 1985          8.0
124          Cuba 1995          6.4
125          Cuba 2005          4.6
126          Cuba 2006          5.0
127   El Salvador 1970          3.3
128   El Salvador 1985          3.7
129   El Salvador 1995          4.5
130   El Salvador 2005          3.5
131   El Salvador 2006          3.5
132     Guatemala 1970          3.5
133     Guatemala 1985          5.0
134     Guatemala 1995          5.0
135     Guatemala 2005          4.1
136     Guatemala 2006          4.4
137        Mexico 1970          7.0
138        Mexico 1980          7.1
139        Mexico 1985          7.4
140        Mexico 1990          7.4
141        Mexico 1991          7.4
142        Mexico 1992          7.4
143        Mexico 1993          7.2
144        Mexico 1994          7.2
145        Mexico 1995          7.0
146        Mexico 1996          7.0
147        Mexico 1997          7.3
148        Mexico 1998          7.2
149        Mexico 1999          7.5
150        Mexico 2000          7.0
151        Mexico 2001          6.5
152        Mexico 2002          6.0
153        Mexico 2003          5.6
154        Mexico 2004          5.7
155        Mexico 2005          5.6
156        Mexico 2006          5.4
157        Mexico 2007          5.4
158        Mexico 2008          5.3
159        Mexico 2009          5.0
160        Mexico 2010          5.0
161        Mexico 2011          4.9
162        Mexico 2012          5.0
163        Mexico 2013          4.9
164        Mexico 2014          4.8
165        Mexico 2015          4.6
166        Mexico 2016          4.4
167        Mexico 2017          4.3
168      Paraguay 1970          5.3
169      Paraguay 1985          5.0
170      Paraguay 1994          5.0
171      Paraguay 2004          3.1
172      Paraguay 2005          3.4
173   Puerto Rico 1970         10.9
174   Puerto Rico 1985          9.0
175   Puerto Rico 1996          8.8
176   Puerto Rico 2005          6.0
177   Puerto Rico 2006          5.8
178 United States 1970         10.6
179 United States 1971         10.6
180 United States 1972         10.9
181 United States 1973         10.8
182 United States 1974         10.5
183 United States 1975         10.0
184 United States 1976          9.9
185 United States 1977          9.9
186 United States 1978         10.3
187 United States 1979         10.4
188 United States 1980         10.6
189 United States 1981         10.6
190 United States 1982         10.6
191 United States 1983         10.5
192 United States 1984         10.5
193 United States 1985         10.1
194 United States 1986         10.0
195 United States 1987          9.9
196 United States 1988          9.7
197 United States 1989          9.7
198 United States 1990          9.8
199 United States 1991          9.4
200 United States 1992          9.3
201 United States 1993          9.0
202 United States 1994          9.1
203 United States 1995          8.9
204 United States 1996          8.8
205 United States 1997          8.9
206 United States 1998          8.4
207 United States 1999          8.6
208 United States 2000          8.3
209 United States 2001          8.2
210 United States 2002          7.8
211 United States 2003          7.7
212 United States 2004          7.8
213 United States 2005          7.6
214 United States 2006          7.5
215 United States 2007          7.3
216 United States 2008          7.1
217 United States 2009          6.8
218 United States 2010          6.8
219 United States 2011          6.8
220 United States 2012          6.8
221 United States 2013          6.8
222 United States 2014          6.9
223 United States 2015          6.9
224 United States 2016          7.0
225 United States 2017          6.9
226 United States 2018          6.5
227       Uruguay 1970          8.4
228       Uruguay 1985          7.5
229       Uruguay 1995          5.4
230       Uruguay 2005          4.0
231       Uruguay 2006          3.7
Check that the total for given year(1979) equals total in graph
regional_marriage %>% filter(Year == 1979) %>%
  summarise(total_mar = sum(MarriageRate))
  total_mar
1      25.8

North American marriage rates(width=50%)

write_csv(marriage_rate_by_country, file = "American_marriage_rate.csv")