Advertisement
Guest User

Untitled

a guest
Apr 30th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. library(conflicted)
  2. library(tidyverse)
  3. library(scales)
  4. filter <- dplyr::filter
  5.  
  6. # To make import easier, I exported my data using dput() and pasted the results here
  7. obit <-
  8. structure(
  9. list(
  10. Year = 1985:2019,
  11. Total = c(
  12. 141072L,
  13. 190698L,
  14. 257543L,
  15. 282117L,
  16. 347959L,
  17. 471336L,
  18. 566849L,
  19. 619844L,
  20. 733273L,
  21. 826277L,
  22. 929403L,
  23. 1036210L,
  24. 1176373L,
  25. 1271789L,
  26. 1411098L,
  27. 1557809L,
  28. 1744998L,
  29. 2070572L,
  30. 2378939L,
  31. 2640516L,
  32. 2828626L,
  33. 3058626L,
  34. 3193418L,
  35. 3360432L,
  36. 3162040L,
  37. 3417941L,
  38. 3610571L,
  39. 3605410L,
  40. 3539897L,
  41. 3300628L,
  42. 3198552L,
  43. 3106570L,
  44. 2988815L,
  45. 2640684L,
  46. 811030L
  47. ),
  48. Died = c(
  49. 107811L,
  50. 133630L,
  51. 184232L,
  52. 203949L,
  53. 261198L,
  54. 357171L,
  55. 432664L,
  56. 484774L,
  57. 573485L,
  58. 660214L,
  59. 723804L,
  60. 786384L,
  61. 873911L,
  62. 936788L,
  63. 1084051L,
  64. 1187872L,
  65. 1293795L,
  66. 1451134L,
  67. 1548716L,
  68. 1663590L,
  69. 1721344L,
  70. 1773371L,
  71. 1774388L,
  72. 1739529L,
  73. 1529231L,
  74. 1580080L,
  75. 1607773L,
  76. 1560059L,
  77. 1424419L,
  78. 1294834L,
  79. 1237948L,
  80. 1121436L,
  81. 1044591L,
  82. 885010L,
  83. 267344L
  84. ),
  85. Euphemism = c(
  86. 5414L,
  87. 6948L,
  88. 8749L,
  89. 10182L,
  90. 10291L,
  91. 14543L,
  92. 15328L,
  93. 17591L,
  94. 22792L,
  95. 33952L,
  96. 47690L,
  97. 65491L,
  98. 76433L,
  99. 89193L,
  100. 101662L,
  101. 126877L,
  102. 174956L,
  103. 236704L,
  104. 304509L,
  105. 362663L,
  106. 429321L,
  107. 550478L,
  108. 682362L,
  109. 840522L,
  110. 886338L,
  111. 1010024L,
  112. 1150420L,
  113. 1215321L,
  114. 1304262L,
  115. 1254868L,
  116. 1253941L,
  117. 1270894L,
  118. 1249445L,
  119. 1150418L,
  120. 359664L
  121. )
  122. ),
  123. class = c("spec_tbl_df",
  124. "tbl_df", "tbl", "data.frame"),
  125. row.names = c(NA, -35L),
  126. spec = structure(list(
  127. cols = list(
  128. year = structure(list(), class = c("collector_integer",
  129. "collector")),
  130. total = structure(list(), class = c("collector_integer",
  131. "collector")),
  132. died = structure(list(), class = c("collector_integer",
  133. "collector")),
  134. euphemism = structure(list(), class = c("collector_integer",
  135. "collector"))
  136. ),
  137. default = structure(list(), class = c("collector_guess",
  138. "collector")),
  139. skip = 1
  140. ), class = "col_spec")
  141. )
  142.  
  143.  
  144. # Now that the data's loaded, time for analysis
  145. # Gather the wide data into a longer format
  146. obit <- obit %>%
  147. gather("Category", "References",-Year,-Total) %>%
  148. mutate(Percent = References / Total)
  149.  
  150.  
  151.  
  152. # ggplot time!
  153. ggplot(obit, aes(x = Year, y = Percent, color = Category)) +
  154. geom_point(size = 4) +
  155. geom_line(size = 2) +
  156. scale_y_continuous(labels = partial(scales::percent, accuracy = 1)) +
  157. labs(title = "Nobody dies anymore",
  158. caption = "Created by TrueBirch using NewsBank obituary database",
  159. subtitle = "Subtitle goes here. Subtitles are usually much longer than titles.") +
  160. theme(
  161. plot.subtitle = element_text(size = 17,
  162. hjust = 0.5),
  163. panel.grid.major = element_line(colour = "gray95"),
  164. panel.grid.minor = element_line(colour = NA),
  165. plot.title = element_text(size = 25,
  166. hjust = 0.5),
  167. panel.background = element_rect(fill = NA),
  168. axis.title = element_text(size = 12),
  169. legend.key = element_rect(fill = NA),
  170. legend.background = element_rect(fill = NA)
  171. ) + labs(subtitle = "Over the past 20 years, death announcements have mostly replaced the word \"died\" with euphemisms like \"passed\" or \"departed\"") + labs(
  172. y = "Percent of death announcements using the
  173. word \"died\" versus a euphemism",
  174. colour = NULL,
  175. subtitle = "Over the past 20 years, death announcements have mostly\nreplaced the word \"died\" with euphemisms like \"passed\" or \"departed\""
  176. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement