Column 1

Casos por semana epidemiológica

Incidência em março/2023 por unidade da federação

Média móvel dos casos para 14 dias

Evolução mensal dos casos

Column 2

Óbitos por semana epidemiológica

Mortalidade em março/2023 por unidade da federação

Média móvel dos óbitos

Evolução mensal dos óbitos

---
title: "Dashboard COVID-19 no Brasil em 2023"
date: "Atualização: `r format(Sys.time(), '%d')`/`r format(Sys.time(), '%m')`/`r format(Sys.time(), '%Y')` às `r format(Sys.time(), '%H:%M')`h"
output: 
  flexdashboard::flex_dashboard:
    theme:
      bg: "#EAECEE"
      fg: "black" 
      primary: "#21618C"
      base_font:
        google: Space Grotesk
      code_font:
        google: Fira Code
    orientation: columns
    vertical_layout: scroll
    social: menu
    source_code: embed
---

```{r setup, include=FALSE}

library(flexdashboard)
library(tidyverse)

df <- covid19br::downloadCovid19(level = "brazil")

```

Column 1
---------------------------------------------------------------

### Casos por semana epidemiológica

```{r fig.height=4, fig.width=8}

df |>  
  mutate(ano = as.factor(lubridate::year(date))) |> 
  filter(date >= "2022-01-01") |>  
  ggplot(aes(y = newCases, x = epi_week, fill = ano)) +
  geom_col() +
  scale_y_continuous(labels = scales::comma_format(big.mark = ".")) +
  scale_fill_manual(values = c("#2E8BC0", "#05445E")) +
  labs(y = "Casos novos", x = "Semana epidemiológica") +
  hrbrthemes::theme_ipsum() +
  theme(panel.grid.minor.y = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(linetype = "dashed", color = "grey50"),
        plot.title = element_text(size = 15),
        axis.title.x = element_text(size = 12, color = "#F39C12"),
        axis.title.y = element_text(size = 12, color = "#F39C12"),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 11),
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"))

```

### Incidência em março/2023 por unidade da federação

```{r include=FALSE}

uf <- covid19br::downloadCovid19(level = "state")
uf <- uf |> filter(date >= "2023-03-01")

uf <- uf |> 
  group_by(state) |>  
  summarise(incidencia = round((sum(newCases) / max(pop)) * 100000, digits = 2),
            mortalidade = round((sum(newDeaths) / max(pop)) * 100000, digits = 2),
            letalidade = round((sum(newDeaths) / max(newCases)) * 100, digits = 2))

geo <- geobr::read_state()

```

```{r fig.height=5, fig.width=5}

geo |>  
  left_join(uf, by = c("abbrev_state" = "state")) %>% 
  ggplot(aes(fill = incidencia)) +
  geom_sf(colour = "black") +
  theme_void() +
  labs(fill = "Casos a cada 100.000 habitantes") +
  theme(legend.position = "bottom",
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"),
        legend.background = element_rect(fill = "transparent", color = NA)) +
  scale_fill_distiller(direction = 1, palette = "Blues")

```

### Média móvel dos casos para 14 dias

```{r fig.height=4, fig.width=8}

df |> 
  filter(date >= "2022-01-01") |>  
  mutate(mediamovel = zoo::rollmean(newCases, k = 14, fill = NA, align = "right"),
         ano = as.factor(lubridate::year(date))) |> 
  ggplot(aes(y = mediamovel, x = date, color = ano)) +
  geom_line(size = 1.5) +
  hrbrthemes::theme_ipsum() +
  scale_y_continuous(labels = scales::comma_format(big.mark = ".")) +
    scale_color_manual(values = c("#2E8BC0", "#05445E")) +
  labs(x = "Data da notificação", y = "Média móvel") +
  theme(panel.grid.minor.y = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(linetype = "dashed", color = "grey50"),
        plot.title = element_text(size = 15),
        axis.title.x = element_text(size = 12, color = "#F39C12"),
        axis.title.y = element_text(size = 12, color = "#F39C12"),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 11),
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"))

```

### Evolução mensal dos casos

```{r fig.height=4, fig.width=8}

df |> 
  filter(date >= "2022-01-01") |> 
  mutate(mes = lubridate::month(date, label = TRUE, abbr = TRUE),
         ano = as.factor(lubridate::year(date))) %>% 
  ggplot(aes(y = newCases, x = mes, fill = ano)) +
  geom_col() +
  scale_y_continuous(labels = scales::comma_format(big.mark = ".")) +
  scale_fill_manual(values = c("#2E8BC0", "#05445E")) +
  labs(y = "Casos novos", x = "Mês de notificação") +
  hrbrthemes::theme_ipsum() +
  theme(panel.grid.minor.y = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(linetype = "dashed", color = "grey50"),
        plot.title = element_text(size = 15),
        axis.title.x = element_text(size = 12, color = "#F39C12"),
        axis.title.y = element_text(size = 12, color = "#F39C12"),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 11),
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"))

```

Column 2 
---------------------------------------------------------------

### Óbitos por semana epidemiológica

```{r fig.height=4, fig.width=8}

df |>  
  mutate(ano = as.factor(lubridate::year(date))) |> 
  filter(date >= "2022-01-01") |>  
  ggplot(aes(y = newDeaths, x = epi_week, fill = ano)) +
  geom_col() +
  scale_y_continuous(labels = scales::comma_format(big.mark = ".")) +
  scale_fill_manual(values = c("#2E8BC0", "#05445E")) +
  labs(y = "Novos óbitos", x = "Semana epidemiológica") +
  hrbrthemes::theme_ipsum() +
  theme(panel.grid.minor.y = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(linetype = "dashed", color = "grey50"),
        plot.title = element_text(size = 15),
        axis.title.x = element_text(size = 12, color = "#F39C12"),
        axis.title.y = element_text(size = 12, color = "#F39C12"),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 11),
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"))

```

### Mortalidade em março/2023 por unidade da federação

```{r fig.height=5, fig.width=5}

geo |>  
  left_join(uf, by = c("abbrev_state" = "state")) %>% 
  ggplot(aes(fill = mortalidade)) +
  geom_sf(colour = "black") +
  theme_void() +
  labs(fill = "Óbitos a cada 100.000 habitantes") +
  theme(legend.position = "bottom",
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"),
        legend.background = element_rect(fill = "transparent", color = NA)) +
  scale_fill_distiller(direction = 1, palette = "Blues")


```

### Média móvel dos óbitos

```{r fig.height=4, fig.width=8}

df |> 
  filter(date >= "2022-01-01") |>  
  mutate(mediamovel = zoo::rollmean(newDeaths, k = 14, fill = NA, align = "right"),
         ano = as.factor(lubridate::year(date))) |> 
  ggplot(aes(y = mediamovel, x = date, color = ano)) +
  geom_line(size = 1.5) +
  hrbrthemes::theme_ipsum() +
  scale_y_continuous(labels = scales::comma_format(big.mark = ".")) +
    scale_color_manual(values = c("#2E8BC0", "#05445E")) +
  labs(x = "Data da notificação", y = "Média móvel") +
  theme(panel.grid.minor.y = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(linetype = "dashed", color = "grey50"),
        plot.title = element_text(size = 15),
        axis.title.x = element_text(size = 12, color = "#F39C12"),
        axis.title.y = element_text(size = 12, color = "#F39C12"),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 11),
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"))

```

### Evolução mensal dos óbitos

```{r fig.height=4, fig.width=8}

df |> 
  filter(date >= "2022-01-01") |> 
  mutate(mes = lubridate::month(date, label = TRUE, abbr = TRUE),
         ano = as.factor(lubridate::year(date))) %>% 
  ggplot(aes(y = newDeaths, x = mes, fill = ano)) +
  geom_col() +
  scale_y_continuous(labels = scales::comma_format(big.mark = ".")) +
  scale_fill_manual(values = c("#2E8BC0", "#05445E")) +
  labs(y = "Novos óbitos", x = "Mês de notificação") +
  hrbrthemes::theme_ipsum() +
  theme(panel.grid.minor.y = element_blank(),
        panel.grid.minor.x = element_blank(),
        panel.grid.major.x = element_blank(),
        panel.grid.major.y = element_line(linetype = "dashed", color = "grey50"),
        plot.title = element_text(size = 15),
        axis.title.x = element_text(size = 12, color = "#F39C12"),
        axis.title.y = element_text(size = 12, color = "#F39C12"),
        axis.text.x = element_text(size = 11),
        axis.text.y = element_text(size = 11),
        plot.background = element_rect(fill = "#EAECEE", color = "#EAECEE"))

```