Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigación reproducible sobre positividad y letalidad #2

Open
kenarab opened this issue Jun 4, 2020 · 0 comments
Open

Investigación reproducible sobre positividad y letalidad #2

kenarab opened this issue Jun 4, 2020 · 0 comments

Comments

@kenarab
Copy link
Collaborator

kenarab commented Jun 4, 2020

library(COVID19AR)
#> Loading required package: dplyr
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
#> Loading required package: knitr
#> Loading required package: magrittr
#> Loading required package: lgr
#> Warning: replacing previous import 'ggplot2::Layout' by 'lgr::Layout' when
#> loading 'COVID19AR'
#> Warning: replacing previous import 'readr::col_factor' by 'scales::col_factor'
#> when loading 'COVID19AR'
#> Warning: replacing previous import 'magrittr::equals' by 'testthat::equals' when
#> loading 'COVID19AR'
#> Warning: replacing previous import 'magrittr::not' by 'testthat::not' when
#> loading 'COVID19AR'
#> Warning: replacing previous import 'magrittr::is_less_than' by
#> 'testthat::is_less_than' when loading 'COVID19AR'
#> Warning: replacing previous import 'dplyr::matches' by 'testthat::matches' when
#> loading 'COVID19AR'
library(ggplot2)
#> 
#> Attaching package: 'ggplot2'
#> The following object is masked from 'package:lgr':
#> 
#>     Layout
#library(dplyr)
#library(RColorBrewer)
knitr::opts_chunk$set(fig.width = 4, fig.height = 6, dpi = 300, warning = FALSE)

covid19.curator <- COVID19ARCurator$new()
self <- covid19.curator
dummy <- covid19.curator$loadData()
#> INFO  [11:20:20.164] Exists dest path? {dest.path: ~/.R/COVID19AR/Covid19Casos.csv, exists.dest.path: TRUE}
dummy <- covid19.curator$curateData()
#> INFO  [11:20:20.931] Normalize 
#> INFO  [11:20:21.146] checkSoundness 
#> INFO  [11:20:21.263] Mutating data

covid19.ar.provincia.summary <- covid19.curator$makeSummary(group.vars = c("residencia_provincia_nombre"))
covid19.ar.provincia.summary.selected <- covid19.ar.provincia.summary %>% filter(confirmados >= 100)

covid19.ar.summary <- covid19.curator$makeSummary(group.vars = c("residencia_provincia_nombre", "sepi_apertura"))
#> INFO  [11:20:42.203] Processing {current.group: residencia_provincia_nombre = Buenos Aires}
#> INFO  [11:20:44.308] Processing {current.group: residencia_provincia_nombre = CABA}
#> INFO  [11:20:46.407] Processing {current.group: residencia_provincia_nombre = Catamarca}
#> INFO  [11:20:47.608] Processing {current.group: residencia_provincia_nombre = Chaco}
#> INFO  [11:20:48.966] Processing {current.group: residencia_provincia_nombre = Chubut}
#> INFO  [11:20:50.203] Processing {current.group: residencia_provincia_nombre = Córdoba}
#> INFO  [11:20:51.692] Processing {current.group: residencia_provincia_nombre = Corrientes}
#> INFO  [11:20:52.982] Processing {current.group: residencia_provincia_nombre = Entre Ríos}
#> INFO  [11:20:54.319] Processing {current.group: residencia_provincia_nombre = Formosa}
#> INFO  [11:20:55.798] Processing {current.group: residencia_provincia_nombre = Jujuy}
#> INFO  [11:20:56.984] Processing {current.group: residencia_provincia_nombre = La Pampa}
#> INFO  [11:20:58.204] Processing {current.group: residencia_provincia_nombre = La Rioja}
#> INFO  [11:20:59.412] Processing {current.group: residencia_provincia_nombre = Mendoza}
#> INFO  [11:21:00.789] Processing {current.group: residencia_provincia_nombre = Misiones}
#> INFO  [11:21:01.846] Processing {current.group: residencia_provincia_nombre = Neuquén}
#> INFO  [11:21:03.054] Processing {current.group: residencia_provincia_nombre = Río Negro}
#> INFO  [11:21:04.316] Processing {current.group: residencia_provincia_nombre = Salta}
#> INFO  [11:21:05.406] Processing {current.group: residencia_provincia_nombre = San Juan}
#> INFO  [11:21:06.543] Processing {current.group: residencia_provincia_nombre = San Luis}
#> INFO  [11:21:07.661] Processing {current.group: residencia_provincia_nombre = Santa Cruz}
#> INFO  [11:21:08.843] Processing {current.group: residencia_provincia_nombre = Santa Fe}
#> INFO  [11:21:10.445] Processing {current.group: residencia_provincia_nombre = Santiago del Estero}
#> INFO  [11:21:11.606] Processing {current.group: residencia_provincia_nombre = SIN ESPECIFICAR}
#> INFO  [11:21:12.901] Processing {current.group: residencia_provincia_nombre = Tierra del Fuego}
#> INFO  [11:21:14.326] Processing {current.group: residencia_provincia_nombre = Tucumán}

data2plot <- covid19.ar.summary %>%
 filter(residencia_provincia_nombre %in% covid19.ar.provincia.summary.selected$residencia_provincia_nombre) %>%
 filter(confirmados > 0 ) %>%
 filter(positividad.porc <=0.6 | confirmados >= 20)

sepi.fechas <- covid19.curator$data %>%
                 group_by(sepi_apertura) %>%
                 summarize(ultima_fecha_sepi = max(fecha_apertura), .groups = "keep")
data2plot %<>% inner_join(sepi.fechas, by = "sepi_apertura")
dates <- sort(unique(data2plot$ultima_fecha_sepi))
total.dates <- length(dates)

report.date <- max(dates)


covplot <- data2plot %>%
  ggplot(aes(x = ultima_fecha_sepi, y = confirmados, color = "confirmados")) +
  geom_line() +
  facet_wrap(~residencia_provincia_nombre, ncol = 2, scales = "free_y") +
  labs(title = "Evolución de casos confirmados y tests\n en provincias > 100 confirmados")
covplot <- covplot +
  geom_line(aes(x = ultima_fecha_sepi, y = tests, color = "tests")) +
  facet_wrap(~residencia_provincia_nombre, ncol = 2, scales = "free_y")
covplot <- setupTheme(covplot, report.date = report.date, x.values = dates, x.type = "dates",
                      total.colors = 2,
                      data.provider.abv = "@msalnacion", base.size = 6)
covplot <- covplot + scale_y_log10()
#> Scale for 'y' is already present. Adding another scale for 'y', which will
#> replace the existing scale.
covplot

ggsave(file.path(data.dir, paste("provincias-confirmados-tests",".png", sep ="")),
       covplot,
       width = 7, height = 5, dpi = 300)
#> Error in file.path(data.dir, paste("provincias-confirmados-tests", ".png", : object 'data.dir' not found


covplot <- data2plot %>%
 ggplot(aes(x = ultima_fecha_sepi, y = positividad.porc, color = "positividad.porc")) +
 geom_line() +
 facet_wrap(~residencia_provincia_nombre, ncol = 2, scales = "free_y") +
 labs(title = "Porcentajes de positividad, uso de UCI, respirador y letalidad\n en provincias > 100 confirmados")
covplot <- covplot +
 geom_line(aes(x = ultima_fecha_sepi, y = cuidado.intensivo.porc, color = "cuidado.intensivo.porc")) +
 facet_wrap(~residencia_provincia_nombre, ncol = 2, scales = "free_y")
covplot <- covplot  +
 geom_line(aes(x = ultima_fecha_sepi, y = respirador.porc, color = "respirador.porc"))+
 facet_wrap(~residencia_provincia_nombre, ncol = 2, scales = "free_y")
covplot <- covplot +
 geom_line(aes(x = ultima_fecha_sepi, y = letalidad.min.porc, color = "letalidad.min.porc")) +
 facet_wrap(~residencia_provincia_nombre, ncol = 2, scales = "free_y")

covplot <- setupTheme(covplot, report.date = report.date, x.values = dates, x.type = "dates",
                     total.colors = 4,
                     data.provider.abv = "@msalnacion", base.size = 6)
covplot

ggsave(file.path(data.dir, paste("provincias-positividad",".png", sep ="")),
       covplot,
       width = 7, height = 5, dpi = 300)
#> Error in file.path(data.dir, paste("provincias-positividad", ".png", sep = "")): object 'data.dir' not found

Created on 2020-06-12 by the reprex package (v0.3.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant