/plot_scripts/plots_miscellaneous-data.R

https://github.com/J535D165/CoronaWatchNL · R · 140 lines · 80 code · 12 blank · 48 comment · 6 complexity · b74ca3adf79b59b2768461e15aa0dff3 MD5 · raw file

  1. library(tidyverse)
  2. library(cowplot)
  3. library(glue)
  4. library(lubridate)
  5. dir.create("plots")
  6. ##############################
  7. ##### MISCELLANEOUS DATA #####
  8. ##############################
  9. ### TEST DATA
  10. # Tests: Toename per kalender week (einde van de week (zondag) als plotdatum)
  11. test <- read_csv("data-misc/data-test/RIVM_NL_test_latest.csv")
  12. test %>%
  13. mutate(
  14. Type = if_else(Type == "Totaal", "Totaal testen", "Positieve testen")
  15. ) %>%
  16. ggplot(aes(x = EindDatum, y = Aantal, colour = Type)) +
  17. geom_line()+
  18. theme_minimal() +
  19. theme(axis.title.x=element_blank(),
  20. axis.title.y=element_blank(),
  21. legend.pos = "bottom",
  22. legend.title = element_blank()) +
  23. scale_color_manual(values=c("#E69F00", "#56B4E9", "#999999")) +
  24. scale_y_continuous(limits=c(0, NA)) +
  25. ggtitle("Toename totaal (positieve) COVID-19 testen per week") +
  26. labs(caption = paste('N.B. Data van week ', as.character(tail(test['Week'], 1)), " wordt nog aangevuld." , sep = "")) +
  27. ggsave("plots/overview_plot_tests_weeks.png", width = 5.5, height=4)
  28. # Tests: Cumulatief per kalender week (einde van de week (zondag) als plotdatum)
  29. test %>%
  30. filter(Type == "Totaal") %>%
  31. mutate(Cumulatief = cumsum(Aantal)) %>%
  32. bind_rows(test %>%
  33. filter(Type == "Positief") %>%
  34. mutate(Cumulatief = cumsum(Aantal))) %>%
  35. mutate(
  36. Type = if_else(Type == "Totaal", "Totaal testen", "Positieve testen")
  37. ) %>%
  38. ggplot(aes(x = EindDatum, y = Cumulatief, colour = Type)) +
  39. geom_line() +
  40. scale_y_continuous(limits=c(0, NA)) +
  41. theme_minimal() +
  42. theme(axis.title.x=element_blank(),
  43. axis.title.y=element_blank(),
  44. legend.pos = "bottom",
  45. legend.title = element_blank()) +
  46. scale_color_manual(values=c("#E69F00", "#56B4E9", "#999999")) +
  47. ggtitle("Totaal (positieve) COVID-19 testen per week") +
  48. ggsave("plots/overview_plot_tests_weeks_cum.png", width = 5.5, height=4)
  49. # Tests: oude data (tm 19 april) totaal (positive) tests
  50. # read_csv("data/rivm_NL_covid19_tests.csv") %>%
  51. # group_by(Datum, Type) %>%
  52. # summarise(Aantal = max(Aantal)) %>%
  53. # mutate(
  54. # Type = if_else(Type == "Totaal", "Totaal testen", "Positieve testen")
  55. # ) %>%
  56. # ggplot(aes(x = Datum, y = Aantal, colour = Type)) +
  57. # geom_line() +
  58. # theme_minimal() +
  59. # theme(axis.title.x=element_blank(),
  60. # axis.title.y=element_blank(),
  61. # legend.pos = "bottom",
  62. # legend.title = element_blank()) +
  63. # scale_color_manual(values=c("#E69F00", "#56B4E9", "#999999")) +
  64. # scale_y_continuous(limits=c(0, NA)) +
  65. # ggtitle("Totaal (positieve) COVID-19 testen") +
  66. # ggsave("plots/overview_plot_tests.png", width = 5.5, height=4)
  67. # Tests: oude data (tm 19 april) toename (positieve) testen
  68. # read_csv("data/rivm_NL_covid19_tests.csv") %>%
  69. # group_by(Datum, Type) %>%
  70. # summarise(Aantal = max(Aantal)) %>%
  71. # ungroup() %>%
  72. # pivot_wider(names_from = Type, values_from = Aantal) %>%
  73. # mutate(
  74. # `Positieve testen` = Positief - lag(Positief),
  75. # `Totaal testen` = Totaal - lag(Totaal),
  76. # ) %>%
  77. # pivot_longer(c("Totaal testen", "Positieve testen"), names_to = "Type", values_to="Aantal", values_drop_na=T) %>%
  78. # ggplot(aes(x = Datum, y = Aantal, colour = Type)) +
  79. # geom_line() +
  80. # scale_y_continuous(limits=c(0, NA)) +
  81. # theme_minimal() +
  82. # theme(axis.title.x=element_blank(),
  83. # axis.title.y=element_blank(),
  84. # legend.pos = "bottom",
  85. # legend.title = element_blank()) +
  86. # scale_color_manual(values=c("#E69F00", "#56B4E9", "#999999")) +
  87. # ggtitle("Toename (positieve) COVID-19 testen") +
  88. # ggsave("plots/overview_plot_tests_diff.png", width = 5.5, height=4)
  89. ### UNDERLYING CONDITIONS
  90. con <- read_csv("data-misc/data-underlying/data-underlying_conditions/RIVM_NL_deceased_under70_conditions.csv")
  91. stat <- read_csv("data-misc/data-underlying/data-underlying_statistics/RIVM_NL_deceased_under70_statistics.csv")
  92. con$Type[which(con$Type == "Chronische neurologische of neuromusculaire aandoeningen")] <- "Chronisch neurologisch/neuromusculair"
  93. con %>%
  94. filter(Type != "Overig") %>%
  95. #mutate(Type = factor(Type, c("Cardio-vasculair en hypertensie", "Diabetes", "Chronische longaandoeningen", "Maligniteit", "Chronisch neurologisch/neuromusculair", "Nieraandoening", "Leveraandoening", "Immuundeficientie", "Zwangerschap", "Postpartum"))) %>%
  96. ggplot(aes(x = Datum, y = AantalCumulatief, colour = Type)) +
  97. geom_line() +
  98. scale_y_continuous(limits=c(0, NA)) +
  99. theme_minimal() +
  100. theme(axis.title.x=element_blank(),
  101. axis.title.y=element_blank(),
  102. legend.pos = "bottom",
  103. legend.title = element_blank(),
  104. plot.title = element_text(hjust = 0.5),
  105. plot.subtitle=element_text(size=11, hjust=0.5),
  106. legend.text = element_text(size = 7)) +
  107. ggtitle("Onderliggende aandoeningen en/of zwangerschap van overledenen (<70 jaar)")+
  108. labs(subtitle = "Cumulatief van gevonden onderliggende aandoeningen en/of zwangerschap bij overleden
  109. COVID-19 patienten onder de 70 jaar") +
  110. ggsave("plots/underlying_conditions.png", width = 8.5, height=4)
  111. stat %>%
  112. mutate(Type = factor(Type, c("Totaal gemeld", "Onderliggende aandoening en/of zwangerschap", "Niet vermeld", "Geen onderliggende aandoening"))) %>%
  113. ggplot(aes(x = Datum, y = AantalCumulatief, colour = Type)) +
  114. geom_line() +
  115. scale_y_continuous(limits=c(0, NA)) +
  116. theme_minimal() +
  117. theme(axis.title.x=element_blank(),
  118. axis.title.y=element_blank(),
  119. legend.pos = "bottom",
  120. legend.title = element_blank(),
  121. plot.title = element_text(hjust = 0.5),
  122. plot.subtitle=element_text(size=11, hjust=0.5),
  123. legend.text = element_text(size = 9)) +
  124. scale_color_manual(values=c("#E69F00", "#56B4E9", "#999999", "gray")) +
  125. ggtitle("Aantal overledenen (<70 jaar) met onderliggende aandoeningen en/of zwangerschap")+
  126. labs(subtitle = "Cumulatief aantal overleden COVID-19 patienten onder de 70 jaar met onderliggende
  127. aandoeningen en/of zwangerschap") +
  128. ggsave("plots/conditions_statistics.png", width = 8.5, height=4)