Dashboard

Row

confirmed

418,678

death

18,625 (4.4%)

Row

Confirmed Cases

Death Cases

Data

Column

Locations of people killed by COVID-19

Column

Cumulative Data

Row

Cumulative Confirmed Cases

Row

Cumulative Death Cases

Spain

Column

Confirmed Cases in Spain

Column

confirmed

39885

death

2808
---
title: "Coronavirus"
author: "Rubén F. Bustillo"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    social: menu
    source_code: embed
    vertical_layout: fill
    theme: cerulean
---



```{r setup, include=FALSE}

#------------------ paquetes ------------------

devtools::install_github("RamiKrispin/coronavirus", force = T)
coronavirus<-coronavirus::coronavirus


# other dataset available:
# df <- read.csv("https://query.data.world/s/cdc5dussbvmp52xnluz6wvyntjn6am", header=TRUE, stringsAsFactors=FALSE)

library(flexdashboard)
library(coronavirus)
library(tidyverse)
library(echarts4r)
library(DT)


data(coronavirus)


# COLORES:

# https://www.w3.org/TR/css-color-3/#svg-color

confirmed_color <- "lightsteelblue"
active_color <- "orange"
recovered_color <- "limegreen"
death_color <- "red"



# DATASETS:

# confirmed/active/recovered/death cases by country
#df <- coronavirus %>% 
#  group_by(Country.Region, type) %>%
#  summarise(total = sum(cases)) %>%
#  pivot_wider(names_from =  type, 
#              values_from = total) %>%
#  mutate(unrecovered = confirmed - ifelse(is.na(recovered), 0, recovered) - ifelse(is.na(death), 0, death)) %>%
#  arrange(-confirmed) %>%
#  ungroup() %>%
#  mutate(country = if_else(Country.Region == "United Arab Emirates", "UAE", Country.Region)) %>%
#  mutate(country = if_else(country == "North Macedonia", "Macedonia", country)) %>%
#  mutate(country = if_else(country == "Czechia", "Czech Rep.", country)) %>%
#  mutate(country = if_else(country == "Bosnia and Herzegovina", "Bosnia and Herz.", country)) %>%
#  mutate(country = if_else(country == "Korea, South", "Korea", country)) %>%
#  mutate(country = if_else(country == "Dominican Republic", "Dominican Rep.", country)) %>%
#  mutate(country = if_else(country == "N.Macedonia", "Macedonia", country)) %>%
#  mutate(country = if_else(country == "Congo (Kinshasa)", "Dem. Rep. Congo", country)) %>%
#  mutate(country = if_else(country == "Republic of Moldova", "Moldova", country)) %>%
#  mutate(country = if_else(country == "Cote d'Ivoire", "Côte d'Ivoire", country)) %>%
#  mutate(country = if_else(country == "Central African Republic", "Central African Rep.", country)) %>%
#  mutate(country = if_else(country == "Congo (Brazzaville)", "Congo", country)) %>%
#  mutate(country = if_else(country == "	Eswatini", "Swaziland", country)) %>%
#  mutate(country = if_else(country == "Equatorial Guinea", "Eq. Guinea", country)) %>%
#  mutate(country = if_else(country == "occupied Palestinian territory", "Palestine", country)) %>%
#  mutate(country = trimws(country)) %>%
#  mutate(country = factor(country, levels = country))

  ### 

  df_updated <- coronavirus %>% 
    group_by(Country.Region, type) %>%
    summarise(total = sum(cases)) %>%
    pivot_wider(names_from =  type, 
                values_from = total) %>%
    arrange(-confirmed) %>%
    ungroup() %>%
    mutate(country = if_else(Country.Region == "United Arab Emirates", "UAE", Country.Region)) %>%
    mutate(country = if_else(country == "North Macedonia", "Macedonia", country)) %>%
    mutate(country = if_else(country == "Czechia", "Czech Rep.", country)) %>%
    mutate(country = if_else(country == "Bosnia and Herzegovina", "Bosnia and Herz.", country)) %>%
    mutate(country = if_else(country == "Korea, South", "Korea", country)) %>%
    mutate(country = if_else(country == "Dominican Republic", "Dominican Rep.", country)) %>%
    mutate(country = if_else(country == "N.Macedonia", "Macedonia", country)) %>%
    mutate(country = if_else(country == "Congo (Kinshasa)", "Dem. Rep. Congo", country)) %>%
    mutate(country = if_else(country == "Republic of Moldova", "Moldova", country)) %>%
    mutate(country = if_else(country == "Cote d'Ivoire", "Côte d'Ivoire", country)) %>%
    mutate(country = if_else(country == "Central African Republic", "Central African Rep.", country)) %>%
    mutate(country = if_else(country == "Congo (Brazzaville)", "Congo", country)) %>%
    mutate(country = if_else(country == "	Eswatini", "Swaziland", country)) %>%
    mutate(country = if_else(country == "Equatorial Guinea", "Eq. Guinea", country)) %>%
    mutate(country = if_else(country == "occupied Palestinian territory", "Palestine", country)) %>%
    mutate(country = trimws(country)) %>%
    mutate(country = factor(country, levels = country))
  


#df_spain <- df %>%
#  filter(country == "Spain")
  
  
df_spain <- df_updated %>%
    filter(country == "Spain")
    

# CUMULATIVE CASES:

#df_daily <- coronavirus %>% 
#  group_by(date, type) %>%
#  summarise(total = sum(cases, na.rm = TRUE)) %>%
#  pivot_wider(names_from = type,
#              values_from = total) %>%
#  arrange(date) %>%
#  ungroup() %>%
#  mutate(active =  confirmed - death - recovered) %>%
#  mutate(confirmed_cumulative = cumsum(confirmed),
#         death_cumulative = cumsum(death),
#         recovered_cumulative = cumsum(recovered),
#         active_cumulative = cumsum(active))


df_daily_updated <- coronavirus %>% 
  group_by(date, type) %>%
  summarise(total = sum(cases, na.rm = TRUE)) %>%
  pivot_wider(names_from = type,
              values_from = total) %>%
  arrange(date) %>%
  ungroup() %>%
  mutate(confirmed_cumulative = cumsum(confirmed),
         death_cumulative = cumsum(death))


df1 <- coronavirus %>% 
  filter(date == max(date))


#df_map <- df %>%
#  mutate(country = recode_factor(country,
#                                 `US` = "United States",
#                                 `UAE` = "United Arab Emirates"))

df_map_updated <- df_updated %>%
  mutate(country = recode_factor(country,
                                 `US` = "United States",
                                 `UAE` = "United Arab Emirates"))

```


Sidebar {.sidebar}
=======================================================================

### Last Update {.value-box}

```{r}

valueBox(value = head(df1$date, n=1), 
         caption = "Last update")
```

\

\

\


This dashboard presents information on COVID-19. The {coronavirus} dataset package is available on CRAN and comes from the [John Hopkins University Center for Systems Science and Engineering](https://hub.jhu.edu/2020/01/23/coronavirus-outbreak-mapping-tool-649-em1-art1-dtd-health/). The {coronavirus} dataset is updated daily by @Rami_Krispin (https://ramikrispin.github.io/coronavirus/)).

I take this opportunity to thank Rami Krispin for sharing his work and code with the #rstat community. His dashboard on coronavirus has helped me tremendously to improve my knowledge of the {flexdashboard} package.

[www.rquer.netlify.com](https://rquer.netlify.com/)

Dashboard
=======================================================================

Row
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}

valueBox(value = paste(format(sum(df_updated$confirmed), big.mark = ","), "", sep = " "), 
         caption = "Total Confirmed Cases", 
         color = confirmed_color)
```


```{r eval=FALSE, include=FALSE}

valueBox(value = paste(format(sum(df_updated$unrecovered, na.rm = TRUE), big.mark = ","), 
                       " (", round(100 * sum(df$unrecovered, na.rm = TRUE) / sum(df$confirmed), 1), 
                       "%)", sep = ""), 
         caption = "Active Cases",  
         color = active_color)
```


```{r eval=FALSE, include=FALSE}

valueBox(value = paste(format(sum(df$recovered, na.rm = TRUE), big.mark = ","), 
                       " (", round(100 * sum(df$recovered, na.rm = TRUE) / sum(df$confirmed), 1), 
                       "%)", sep = ""), 
         caption = "Recovered Cases", 
         color = recovered_color)
```

### death {.value-box}

```{r}

valueBox(value = paste(format(sum(df_updated$death, na.rm = TRUE), big.mark = ","), 
                       " (", round(100 * sum(df_updated$death, na.rm = TRUE) / sum(df_updated$confirmed), 1), 
                       "%)", sep = ""),
         caption = "Death Cases", 
         color = death_color)

```


Row {.tabset .tabset-fade}
-----------------------------------------------------------------------

### Confirmed Cases

```{r}

df_map_updated %>%
  e_charts(country) %>%
  e_map(confirmed) %>%
  e_title("Confirmed Cases by Country", left= "center") %>%
  e_visual_map() %>%
  e_theme("infographic") %>%
  e_visual_map_range(selected= list(0,200))
  

```

###

```{r eval=FALSE, include=FALSE}

df_map %>%
  e_charts(country) %>%
  e_map(unrecovered) %>%
  e_title("Active Cases by Country", left= "center") %>%
  e_visual_map() %>%
  e_theme("infographic")%>%
  e_visual_map_range(selected= list(1,200))
  

```

### 

```{r eval=FALSE, include=FALSE}

df_map %>%
  e_charts(country) %>%
  e_map(recovered) %>%
  e_title("Recovered Cases by Country", left= "center") %>%
  e_visual_map() %>%
  e_theme("infographic") %>%
  e_visual_map_range(selected= list(1,200))
  

```

### Death Cases 

```{r}

df_map_updated %>%
  e_charts(country) %>%
  e_map(death) %>%
  e_title("Death Cases by Country", left= "center") %>%
  e_visual_map() %>%
  e_theme("infographic") %>%
  e_visual_map_range(selected= list(1,200))
  

```




Data
=======================================================================

Column 
-------------------------------------
    
### 
    
```{r}

df_table <- df_updated %>%
  select(country, confirmed, death)

df_table %>%
  datatable(rownames = FALSE)

```
   
   
### Locations of people killed by COVID-19

```{r, fig.width=10, fig.height=7}

mapa_mundo <- map_data("world")


coronavirus_mapa <- coronavirus %>%
  filter(type == "death") %>%
  filter(cases != 0)

mapa_mundo %>%
  ggplot() +
  geom_polygon(aes(x=long, y=lat, group=group),
               fill= "grey30",
               color= "white") +
  geom_point(data = coronavirus_mapa, 
             aes(x = Long,
             y = Lat,
             color = "orange",
             alpha = 0.7,
             size = 1.2)) +
  theme_classic() +
  theme(
    axis.line = element_blank(),
    axis.text = element_blank(),
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    legend.position = "none"
  ) 

```
   
Column 
-------------------------------------
   
### 

```{r eval=FALSE, include=FALSE}

plotly::plot_ly(data = df, 
                x = ~ country, 
                y = ~ unrecovered, 
                type = "bar", 
                name = "Unrecovered",
                marker = list(color = "darkorange")) %>%
  plotly::add_trace(y = ~ recovered, 
                    name = "Recovered",
                    marker = list(color = recovered_color)) %>%
  plotly::add_trace(y = ~ death, 
                    name = "Death",
                    marker = list(color = death_color)) %>%
  plotly::layout(barmode = 'stack',
                 yaxis = list(title = "Total Cases (log)",
                              type = "log"),
                 xaxis = list(title = ""),
                 hovermode = "compare")

```   
 
```{r}

plotly::plot_ly(data = df_updated, 
                x = ~ country, 
                y = ~ death, 
                type = "bar", 
                name = "Unrecovered",
                marker = list(color = "darkorange"))%>%
  plotly::layout(barmode = 'stack',
                 yaxis = list(title = "Death Cases (log)",
                              type = "log"),
                 xaxis = list(title = ""),
                 hovermode = "compare")


```


Cumulative Data
=======================================================================


Row
-----------------------------------------------------------------------

### Cumulative Confirmed Cases

```{r}

plotly::plot_ly(data = df_daily_updated) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ confirmed_cumulative,
                    type = "bar",
                    name = "Active",
                    line = list(color = confirmed_color),
                    marker = list(color = confirmed_color)) %>%
  plotly::layout(yaxis = list(title = "Confirmed Cases (cumulative)"),
                 xaxis = list(title = ""))

```


```{r eval=FALSE, include=FALSE}

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ active_cumulative,
                    type = "bar",
                    name = "Active",
                    line = list(color = active_color),
                    marker = list(color = active_color)) %>%
  plotly::layout(yaxis = list(title = "Active Cases (cumulative)"),
                 xaxis = list(title = ""))

```


Row
-------------------------------------------------------------------------

```{r eval=FALSE, include=FALSE}

plotly::plot_ly(data = df_daily) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ recovered_cumulative,
                    type = "bar",
                    name = "Recovered",
                    line = list(color = recovered_color),
                    marker = list(color = recovered_color)) %>%
  plotly::layout(yaxis = list(title = "Recovered Cases (cumulative)"),
                 xaxis = list(title = ""))

```



### Cumulative Death Cases

```{r}

plotly::plot_ly(data = df_daily_updated) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ death_cumulative,
                    type = "bar",
                    name = "Death",
                    line = list(color = death_color),
                    marker = list(color = death_color))%>%
  plotly::layout(yaxis = list(title = "Death Cases (cumulative)"),
                 xaxis = list(title = ""))

```


Spain
=======================================================================

Column 
-------------------------------------
    
### 
    
```{r, figh.height = 10}

df_Spain <- coronavirus %>% 
  filter(Country.Region == "Spain") %>%
  group_by(date, type) %>%
  summarise(total = sum(cases, na.rm = F)) %>%
  pivot_wider(names_from = type,
              values_from = total) %>%
  arrange(date) %>%
  ungroup()

df_Spain %>%
  datatable(rownames = FALSE)

```
   
   
### Confirmed Cases in Spain

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

plotly::plot_ly(data = df_Spain) %>%
  plotly::add_trace(x = ~ date,
                    y = ~ confirmed,
                    type = "bar",
                    line = list(color = active_color),
                    marker = list(color = active_color)) %>%
  plotly::layout(yaxis = list(title = "Confirmed Cases"),
                 xaxis = list(title = ""))

```
   
Column 
-------------------------------------
   
### confirmed {.value-box}

```{r}

valueBox(value = df_spain$confirmed, 
         caption = "Confirmed Cases in Spain", 
         color = confirmed_color)
```


```{r eval=FALSE, include=FALSE}

valueBox(value = df_spain$unrecovered, 
         caption = "Active Cases",  
         color = active_color)
```


```{r eval=FALSE, include=FALSE}

valueBox(value = df_spain$recovered, 
         caption = "Recovered Cases", 
         color = recovered_color)
```

### death {.value-box}

```{r}

valueBox(value = df_spain$death,
         caption = "Death Cases", 
         color = death_color)

```