fhi::DashboardInitialiseOpinionated("sykdomspuls",
                                    PACKAGE_DIR=params$package_dir,
                                    FORCE_DEV_PACKAGE_LOAD = params$dev,
                                    SILENT=TRUE)

suppressMessages(library(data.table))
suppressMessages(library(ggplot2))
suppressMessages(library(kableExtra))
suppressMessages(library(fhiplot))
suppressMessages(library(lubridate))
suppressMessages(library(fhidata))


start_date = ymd("2019-01-01")

conn <- DBI::dbConnect(odbc::odbc(),
    driver = fd::config$db_config$driver,
    server = fd::config$db_config$server,
    port = fd::config$db_config$port,
    user = fd::config$db_config$user,
    password = fd::config$db_config$password
    )
fd::use_db(conn, fd::config$db_config$db)
db <- dplyr::tbl(conn, "spuls_standard_results")
d <- db %>% dplyr::filter(tag=="emerg1" & granularity_time=="weekly") %>%
    dplyr::select(date, age, n, location_code, granularity_geo) %>% dplyr::collect()

setDT(d)

county <- d[granularity_geo =="county" | granularity_geo =="national"]
municip <- d[granularity_geo =="municip"]
county <- county[,age:=factor(age,levels=names(CONFIG$AGES))]
county_year = county[date >=start_date]
municip_year = municip[date >=start_date]

\newpage

Epi-curve

q <- ggplot(county_year[location_code=="Norge" & age == "Totalt"]) +
    geom_col(aes(x=date, y=n), fill = fhiplot::base_color, width = 4) +
    theme_fhi_lines() +
    ylab("") 
q

County Map

pd <- fhidata::norway_map_counties

plot_data <- data.table(pd)[county_year[, .(N=sum(n)), by=.(location_code)], on="location_code", nomatch=0]
max <- max(plot_data$N)
plot_data <- plot_data[, binned := cut(N , round(max/5 * 0:5))]
q <- ggplot()
q <- q + geom_polygon(data = plot_data, aes( x = long, y = lat, group = group, fill=binned), color="black")
q <- q + theme_void()
q <- q + coord_quickmap()
q <- q + fhiplot::scale_fill_fhi("Cases", palette = "map_seq_complete", direction = 1) 
q

Muncipalities with the most cases

pop <- fhidata::norway_population_current

pop <- data.table(pop)[, .(pop=sum(pop)), by=.(location_code)]

municip_cases <- municip_year[,  .(N=sum(n)), by=.(location_code)][pop, on=.(location_code=location_code), nomatch=0]

municip_cases <- municip_cases[, .(location_code, N,  incidence = round(N / pop * 1000, 1))][data.table(fhidata::norway_locations_current), on=.(location_code=municip_code), nomatch=0]


table <- municip_cases[order(-N), .(municip_name, N, incidence)][1:35]
 setnames(table,c(
    "Municipality","Cases","Incidence per 1000 inhabitants")

  )

  k <- knitr::kable(table, "latex",
                      booktabs = T,
                      align = "c",
                      linesep = "")
   print(k)


folkehelseinstituttet/dashboards_sykdomspuls documentation built on May 10, 2020, 10:44 a.m.