Read in the Dataset

I have spent HW3 and HW4 cleaning up the 2017 Australian Marriage Law dataset and better understanding it. I returned to HW4 and attempted to save a cleaner version of the dataset as a .csv file using the readr function write_csv. I will try to read in the data below:

ausmar <- read_csv("/Users/Megan Georges/Documents/DACSS601_R/Data/ausmar.csv")
## Rows: 150 Columns: 6
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (2): Divisions, Cities
## dbl (4): Response_Clear_Yes, Response_Clear_No, Response_Not_Clear, Non_Resp...
## 
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(ausmar)
## # A tibble: 6 x 6
##   Divisions                 Cities    Response_Clear_~ Response_Clear_~ Response_Not_Cl~
##   <chr>                     <chr>                <dbl>            <dbl>            <dbl>
## 1 New South Wales Divisions Banks                37736            46343              247
## 2 New South Wales Divisions Barton               37153            47984              226
## 3 New South Wales Divisions Bennelong            42943            43215              244
## 4 New South Wales Divisions Berowra              48471            40369              212
## 5 New South Wales Divisions Blaxland             20406            57926              220
## 6 New South Wales Divisions Bradfield            53681            34927              202
## # ... with 1 more variable: Non_Response <dbl>

Fix Division Names… Again

I don’t like that each division name ends with “Divisions” instead of “Division”, so I used the mutate() function to change the names… Then I decided that having “Division” in each value of the Division column was repetitive, so I removed it altogether.

ausmar <- ausmar %>%
  mutate(Divisions = case_when(
    Divisions == "New South Wales Divisions" ~ "New South Wales",
    Divisions == "Victoria Divisions" ~ "Victoria",
    Divisions == "Queensland Divisions" ~ "Queensland",
    Divisions == "South Australia Divisions" ~ "South Australia",
    Divisions == "Western Australia Divisions" ~ "Western Australia",
    Divisions == "Tasmania Divisions" ~ "Tasmania",
    Divisions == "Northern Territory Divisions" ~ "Northern Territory",
    Divisions == "Australian Capital Territory Divisions" ~ "Australian Capital Territory"
  ))

Practice Generating and Designing a Table

I have really only been displaying data in tibbles. I wanted to play around with creating a more appealing and clear table for the dataset when the file is knitted. I decided to use the function kable() from the knitr package and download kableExtra because it is simple and works with a rectangular dataset like the cleaned-up Australian Marraige Law dataset.

kable(ausmar, col.names = c("Division", "City", "Response Yes (Clear)", "Response No (Clear)", "Response Not Clear", "No Response"), 
      align = c('c', 'c', 'c', 'c', 'c', 'c')) %>%
  add_header_above(c("Location"=2, "Type of Response"=4))%>%
    kable_styling(fixed_thead = TRUE)%>%
  scroll_box(width = "100%", height = "500px")
Location
Type of Response
Division City Response Yes (Clear) Response No (Clear) Response Not Clear No Response
New South Wales Banks 37736 46343 247 20928
New South Wales Barton 37153 47984 226 24008
New South Wales Bennelong 42943 43215 244 19973
New South Wales Berowra 48471 40369 212 16038
New South Wales Blaxland 20406 57926 220 25883
New South Wales Bradfield 53681 34927 202 17261
New South Wales Calare 54091 35779 285 25342
New South Wales Chifley 32871 46702 263 28180
New South Wales Cook 47505 38804 229 18713
New South Wales Cowper 57493 38317 315 25197
New South Wales Cunningham 60906 31840 268 20607
New South Wales Dobell 59475 30987 255 24275
New South Wales Eden-Monaro 57223 30926 249 22139
New South Wales Farrer 48432 39297 277 25669
New South Wales Fowler 27847 48782 228 29251
New South Wales Gilmore 59322 36386 303 23109
New South Wales Grayndler 73208 18429 136 16074
New South Wales Greenway 38016 43980 217 25253
New South Wales Hughes 51337 36558 185 17038
New South Wales Hume 51284 36271 213 23457
New South Wales Hunter 59137 32723 251 25253
New South Wales Kingsford Smith 56297 31510 225 22399
New South Wales Lindsay 49071 38295 234 26955
New South Wales Lyne 51416 41539 316 21426
New South Wales Macarthur 43323 39907 228 27271
New South Wales Mackellar 62350 29330 208 17500
New South Wales Macquarie 56180 31778 235 18490
New South Wales McMahon 29146 53967 242 23721
New South Wales Mitchell 42112 43652 176 19436
New South Wales Newcastle 71158 23999 232 19970
New South Wales New England 44608 40324 256 25581
New South Wales North Sydney 64813 25473 193 17538
New South Wales Page 55943 37727 291 25645
New South Wales Parkes 41408 37108 241 29777
New South Wales Parramatta 29299 47038 197 25757
New South Wales Paterson 60915 32059 279 24264
New South Wales Reid 43567 39061 203 23786
New South Wales Richmond 62591 29625 274 22719
New South Wales Riverina 47333 39308 265 25632
New South Wales Robertson 58689 30614 231 20431
New South Wales Shortland 62455 29836 255 19675
New South Wales Sydney 76144 14860 146 22093
New South Wales Warringah 64999 21660 172 16630
New South Wales Watson 24915 57160 205 24634
New South Wales Wentworth 69279 16410 162 18121
New South Wales Werriwa 30252 53174 269 29282
New South Wales Whitlam 57562 34879 276 23064
Victoria Aston 48455 29730 234 17664
Victoria Ballarat 65613 27405 333 20923
Victoria Batman 66383 26906 287 17901
Victoria Bendigo 63412 28852 333 19360
Victoria Bruce 34644 39203 257 21261
Victoria Calwell 37839 49823 331 23588
Victoria Casey 59959 28144 316 16807
Victoria Chisholm 49448 30844 271 17188
Victoria Corangamite 69723 27708 326 17123
Victoria Corio 62658 29865 359 18255
Victoria Deakin 55464 28973 276 15389
Victoria Dunkley 62840 24471 285 19322
Victoria Flinders 68291 29275 336 21407
Victoria Gellibrand 62045 29065 278 19771
Victoria Gippsland 51196 33910 338 20370
Victoria Goldstein 69726 21663 238 14857
Victoria Gorton 49834 43587 347 27479
Victoria Higgins 70059 19375 180 16615
Victoria Holt 47147 45875 289 28260
Victoria Hotham 47986 32524 303 19732
Victoria Indi 54563 31925 324 18934
Victoria Isaacs 56645 30063 275 20692
Victoria Jagajaga 65098 23453 255 15363
Victoria Kooyong 63592 22729 231 14147
Victoria Lalor 57062 43429 345 30127
Victoria La Trobe 61807 29826 268 19002
Victoria Mallee 42495 35795 359 21207
Victoria Maribyrnong 53208 35658 360 23762
Victoria McEwen 73705 39007 377 26966
Victoria McMillan 61479 36500 372 22403
Victoria Melbourne 81287 15839 182 20154
Victoria Melbourne Ports 70589 15523 198 18745
Victoria Menzies 47137 35626 258 15745
Victoria Murray 48205 35452 357 21560
Victoria Scullin 48245 42147 357 22817
Victoria Wannon 49340 31529 343 18569
Victoria Wills 68450 29399 250 20169
Queensland Blair 47194 31433 256 23975
Queensland Bonner 52139 31891 209 17981
Queensland Bowman 53529 32627 220 19691
Queensland Brisbane 72812 18762 159 20656
Queensland Capricornia 39917 33917 230 24896
Queensland Dawson 42539 34599 205 26943
Queensland Dickson 54206 28988 190 18527
Queensland Fadden 52154 32218 215 26234
Queensland Fairfax 58510 32451 277 21335
Queensland Fisher 52023 30783 258 19625
Queensland Flynn 39020 36783 262 24529
Queensland Forde 46937 30585 231 24423
Queensland Griffith 69171 21132 184 20133
Queensland Groom 40536 41915 262 20717
Queensland Herbert 48110 28441 207 29665
Queensland Hinkler 40649 39548 308 22425
Queensland Kennedy 33160 37784 263 29794
Queensland Leichhardt 47750 27606 239 35841
Queensland Lilley 59991 28671 218 20249
Queensland Longman 51268 33576 258 24250
Queensland Maranoa 35475 45308 352 22553
Queensland McPherson 54034 28486 229 23214
Queensland Moncrieff 50566 28717 214 25232
Queensland Moreton 47418 30413 220 20020
Queensland Oxley 44655 29365 224 23348
Queensland Petrie 53144 33067 200 23323
Queensland Rankin 41570 34621 237 26119
Queensland Ryan 64967 24451 162 16223
Queensland Wide Bay 46507 37065 319 21645
Queensland Wright 47109 35812 280 22144
South Australia Adelaide 62769 26771 217 20477
South Australia Barker 42498 38827 243 24297
South Australia Boothby 62139 28556 234 16919
South Australia Grey 40811 35750 260 25327
South Australia Hindmarsh 57947 33613 273 20548
South Australia Kingston 58863 27567 252 20764
South Australia Makin 51547 33743 242 21991
South Australia Mayo 57361 31247 261 17239
South Australia Port Adelaide 53649 33869 276 27253
South Australia Sturt 52308 32655 252 19410
South Australia Wakefield 52636 33649 268 27802
Western Australia Brand 51953 25481 194 24466
Western Australia Burt 44058 33275 169 24197
Western Australia Canning 48486 32019 214 22157
Western Australia Cowan 44388 31075 184 21330
Western Australia Curtin 59638 22943 178 15706
Western Australia Durack 39304 27128 194 31428
Western Australia Forrest 51612 29285 225 21752
Western Australia Fremantle 57541 24559 236 19878
Western Australia Hasluck 47880 28836 230 19570
Western Australia Moore 56690 26690 195 16916
Western Australia O’Connor 43554 33987 234 24925
Western Australia Pearce 54305 30699 209 26401
Western Australia Perth 57510 22967 177 19479
Western Australia Stirling 47225 30060 190 21345
Western Australia Swan 49093 26830 185 21857
Western Australia Tangney 48338 30090 174 14926
Tasmania Bass 36249 22510 145 15487
Tasmania Braddon 30054 25573 154 17632
Tasmania Denison 45005 15992 167 13092
Tasmania Franklin 44746 20322 163 13605
Tasmania Lyons 35894 25258 176 17204
Northern Territory Lingiari(c) 19026 15898 106 34854
Northern Territory Solomon 29660 15792 123 22642
Australian Capital Territory Canberra(d) 89590 31361 281 24399
Australian Capital Territory Fenner(e) 85869 30159 253 26196

Proportion of Voters that Did Not Respond

I think that a very useful piece of information for researchers and organizers to pay mind to is the proportion of voters that did not respond to the marriage law survey. I’d be curious to learn more about what produced high or low rates of response in different areas.

ausmartotals <- ausmar %>%
  mutate(Total = (Response_Clear_Yes + Response_Clear_No + Response_Not_Clear + Non_Response))

ausmarnon <- ausmartotals %>%
  select(Divisions, Cities, Non_Response, Total) %>%
  mutate(Prop_Non_Response = (Non_Response/Total *100))

ausmarnon %>%
  select(Divisions, Cities, Prop_Non_Response) %>%
  arrange(desc(Prop_Non_Response)) %>%
  kable(col.names = c("Division", "City", "Non Response Proportion"), 
        align = c('c', 'c', 'c'), 
        caption = "Proportion of Voters that Did Not Respond in Each City") %>%
  kable_styling(fixed_thead = TRUE)%>%
  scroll_box(width = "100%", height = "500px") 
Proportion of Voters that Did Not Respond in Each City
Division City Non Response Proportion
Northern Territory Lingiari(c) 49.87408
Northern Territory Solomon 33.19114
Queensland Leichhardt 32.16286
Western Australia Durack 32.05173
Queensland Kennedy 29.49872
Queensland Herbert 27.87461
New South Wales Fowler 27.56720
New South Wales Parkes 27.43564
New South Wales Chifley 26.08873
New South Wales Werriwa 25.91855
Queensland Dawson 25.83568
Queensland Rankin 25.47027
New South Wales Parramatta 25.18012
Queensland Capricornia 25.15764
South Australia Grey 24.79442
New South Wales Blaxland 24.78384
New South Wales Macarthur 24.62860
Queensland Flynn 24.38416
South Australia Wakefield 24.31201
Western Australia O’Connor 24.26972
Queensland Moncrieff 24.09266
Tasmania Braddon 24.01754
Western Australia Brand 23.96419
Queensland Oxley 23.92409
Queensland Forde 23.90287
Western Australia Burt 23.79276
South Australia Port Adelaide 23.68858
Queensland Fadden 23.67241
Western Australia Pearce 23.65384
New South Wales Lindsay 23.53018
New South Wales Greenway 23.49859
Queensland Blair 23.30883
Victoria Holt 23.24568
New South Wales New England 23.09401
New South Wales Watson 23.04095
Victoria Lalor 23.00421
South Australia Barker 22.95093
New South Wales Riverina 22.77631
Victoria Gorton 22.66365
New South Wales Farrer 22.58104
Western Australia Swan 22.31103
New South Wales Reid 22.30976
Victoria Bruce 22.29434
Queensland Longman 22.17609
New South Wales McMahon 22.15342
Western Australia Cowan 21.99491
New South Wales Barton 21.95097
New South Wales Calare 21.94170
Queensland McPherson 21.90765
Tasmania Lyons 21.90699
Queensland Hinkler 21.78665
Queensland Maranoa 21.75083
Western Australia Stirling 21.59988
Western Australia Canning 21.53758
New South Wales Hunter 21.51682
New South Wales Page 21.44123
Queensland Petrie 21.25412
Victoria Mallee 21.23758
Western Australia Forrest 21.14431
Victoria Calwell 21.13980
New South Wales Dobell 21.11016
New South Wales Hume 21.08968
Victoria Maribyrnong 21.03055
Queensland Wright 21.02046
Tasmania Bass 20.81838
New South Wales Cowper 20.76870
New South Wales Paterson 20.64723
Queensland Wide Bay 20.50959
South Australia Makin 20.45237
Victoria Murray 20.42169
Queensland Moreton 20.41378
New South Wales Kingsford Smith 20.28325
Western Australia Hasluck 20.27643
Victoria Scullin 20.09140
Queensland Groom 20.02997
New South Wales Eden-Monaro 20.02859
New South Wales Whitlam 19.92037
New South Wales Banks 19.88333
New South Wales Richmond 19.71981
Victoria Hotham 19.62504
New South Wales Sydney 19.50937
Western Australia Perth 19.45313
Western Australia Fremantle 19.44743
New South Wales Gilmore 19.39976
South Australia Kingston 19.32506
Victoria McEwen 19.25386
Victoria Gippsland 19.25076
Victoria Isaacs 19.21709
Queensland Fisher 19.11110
Queensland Fairfax 18.95215
New South Wales Bennelong 18.77603
New South Wales Lyne 18.68052
Victoria Wannon 18.60976
New South Wales Robertson 18.57955
South Australia Adelaide 18.57594
Queensland Bowman 18.56468
Queensland Lilley 18.55510
Victoria McMillan 18.55259
South Australia Sturt 18.55197
New South Wales Mitchell 18.44443
Australian Capital Territory Fenner(e) 18.38613
Victoria Aston 18.38411
Queensland Brisbane 18.37902
Victoria Ballarat 18.30950
South Australia Hindmarsh 18.28423
Queensland Griffith 18.20014
Queensland Dickson 18.17959
New South Wales Cunningham 18.13661
Victoria Dunkley 18.07179
Victoria Flinders 17.94249
Victoria Indi 17.90517
Victoria Melbourne Ports 17.84303
Victoria Gellibrand 17.78623
New South Wales Cook 17.77940
Tasmania Denison 17.63090
Queensland Bonner 17.59049
Victoria Chisholm 17.58345
New South Wales Shortland 17.53237
New South Wales Wentworth 17.42873
New South Wales Macquarie 17.33172
New South Wales Newcastle 17.31118
Victoria Bendigo 17.29235
Tasmania Franklin 17.25734
Victoria Melbourne 17.15789
Victoria La Trobe 17.13389
Victoria Wills 17.05364
Western Australia Moore 16.83335
Australian Capital Territory Canberra(d) 16.75399
Victoria Corio 16.42567
New South Wales Bradfield 16.27306
South Australia Mayo 16.24665
New South Wales North Sydney 16.23633
New South Wales Hughes 16.20845
New South Wales Warringah 16.07369
Victoria Batman 16.05802
New South Wales Mackellar 15.99810
Victoria Casey 15.97229
Western Australia Tangney 15.95886
Western Australia Curtin 15.95085
Victoria Menzies 15.94172
South Australia Boothby 15.68782
Victoria Higgins 15.64074
Victoria Deakin 15.37332
Queensland Ryan 15.33321
New South Wales Berowra 15.26120
Victoria Corangamite 14.90512
New South Wales Grayndler 14.90445
Victoria Jagajaga 14.74815
Victoria Kooyong 14.04880
Victoria Goldstein 13.95233

A Basic Bar Graph of Total Votes

A very basic bar graph can be useful to display the total number of votes from the survey, including clear Yes and No responses, as well as Unclear responses and Non-Responses. The graph clearly displays that more respondents support a change in law than those who do not support a change in law.

ausmarvotes <- ausmar %>%
  select(Response_Clear_Yes, Response_Clear_No, Response_Not_Clear, Non_Response)%>%
  summarise(Yes=sum(Response_Clear_Yes), No=sum(Response_Clear_No), NotClear=sum(Response_Not_Clear), NonResponse=sum(Non_Response))

rownames(ausmarvotes) <- c("Total")
## Warning: Setting row names on a tibble is deprecated.
ausmarvotes <- pivot_longer(ausmarvotes, Yes:NonResponse, names_to = "Response", values_to = "Total") %>%
  arrange(desc(Total)) 
kable(ausmarvotes)
Response Total
Yes 7817247
No 4873987
NonResponse 3278260
NotClear 36686
ggplot(data = ausmarvotes) +
  geom_bar(mapping = aes(x = Response, y = Total), stat = "identity") +
  labs(title = "Should Australian Law Change to Allow Same-Sex Marraige?", 
       subtitle = "2017 postal survey of Australians", x = "Type of Response", y = "Total # of Responses")

Removing Response Not Clear from the Graph

Removing the NotClear responses, which is a small amount in proportion to the other responses, allows for the bar graph to scale larger and display a more obvious difference in the 3 primary types of responses. As I mentioned above, it is important for organizers and legislatures to pay attention to those who did not respond. They did not respond to the survey, but they may still vote on the matter and influence different results to this survey.

ausmarvotes %>%
  filter(Response == "Yes" | Response == "No" | Response == "NonResponse") %>%
  ggplot() +
  geom_bar(mapping = aes(x = Response, y = Total), stat = "identity") +
  labs(title = "Should Australian Law Change to Allow Same-Sex Marraige?", 
       subtitle = "2017 postal survey of Australians, excluding unclear answers", x = "Type of Response", y = "Number of Responses")

Concluding Thoughts

Something that I wish I was able to do was add labels on the boxplots in each bin to show the total count of responses. I was not able to figure out how to get this to work or how to adjust the way the y-axis number labels displayed… Another (more complex) bar graph that I think would be interesting is one that is shows the proportion of each type of response by City or by Division. You could use fill=Response to color code the type of response in each bar (City or Division) or you could use facet_wrap to display each Division as a subplot.