요약

Row

confirmed

40

death

0 (0%)

Row

유형별 누적 사례 수, 인천 (확진=Confirmed, 사망=deceased, 해제=released)

주요 시도 비교

Column

일별 누적 사례 수

유형별 막대 그래프 (확진=Confirmed, 사망=deceased)

공간정보

국내 사례 수

---
title: "코로나 19"       
author: "updragon(LEE SANG YONG)"
output: 
  flexdashboard::flex_dashboard:
    orientation: rows
    # social: ["facebook", "twitter", "linkedin"]
    source_code: embed      # source_code 포함 여부
    vertical_layout: fill
---

```{r setup, include=FALSE}
#------------------ Packages ------------------
library(data.table)
library(tidyverse)
library(lubridate)
library(coronavirus)  # update_datasets("coronavirus")
library(pander)
library(flexdashboard)


data <- fread("covid19.csv") # https://www.kaggle.com/kimjihoo/coronavirusdataset
str(data)

data <- data[ , -2]

ymd(data$date) -> data$date
as.factor(data$province) -> data$province

`%>%` <- magrittr::`%>%`

confirmed_color <- "#1f77b4"
released_color <- "purple"
deceased_color <- "red"


df <- data %>% 
  tail(17) %>% 
  select(province, confirmed:deceased) %>%
  mutate(unrecovered = confirmed - released) %>% 
  arrange(-confirmed)

df %>% 
  filter(province=="Incheon") -> df4

# df1 <- data %>% filter(date == max(date))
# df1
```


```{r}
Incheon <- data %>%
  filter(province=="Incheon")
Busan <- data %>%
  filter(province=="Busan")

```


요약
=======================================================================

Row {data-width=400}
-----------------------------------------------------------------------

### confirmed {.value-box}

```{r}
valueBox(
  value = paste(format(sum(df4$confirmed), big.mark = ","), "", sep = " "),
  caption = "확진자 수",
  icon = "fas fa-user-md",
  color = confirmed_color
)
```


### death {.value-box}

```{r}
valueBox(
  value = paste(format(sum(df4$deceased, na.rm = TRUE), big.mark = ","), " (",
    round(100 * sum(df4$deceased, na.rm = TRUE) / sum(df4$confirmed), 1),
    "%)",
    sep = ""
  ),
  caption = "사망 사례 (사망율)",
  icon = "fas fa-heart-broken",
  color = "red"   #deceased_color
)
```

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

### **유형별 누적 사례 수, 인천**   (확진=Confirmed, 사망=deceased, 해제=released)


```{r}
plotly::plot_ly(data = Incheon) %>%
  plotly::add_trace(
    x = ~date,
    # y = ~active_cum,
    y = ~confirmed,
    type = "scatter",
    mode = "lines+markers",
    # name = "Active",
    name = "Confirmed",
    line = list(color = confirmed_color),
    marker = list(color = confirmed_color)
  )  %>% 
  plotly::add_trace(
    x = ~date,
    y = ~released,
    type = "scatter",
    mode = "lines+markers",
    name = "released",
    line = list(color = released_color),
    marker = list(color = released_color)
  ) %>% 
  plotly::add_trace(
    x = ~date,
    y = ~deceased,
    type = "scatter",
    mode = "lines+markers",
    name = "deceased",
    line = list(color = deceased_color),
    marker = list(color = deceased_color)
  ) %>%
  plotly::layout(
    title = "",
    yaxis = list(title = "Cumulative number of cases"),
    xaxis = list(title = "Date"),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  ) %>% 
  plotly::add_annotations(
    x = as.Date("2020-02-18"),
    y = 1,
    text = paste("신천지 첫 확진자"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -150
  ) %>% 
  plotly::add_annotations(
    x = as.Date("2020-02-22"),
    y = 2,
    text = paste("인천 내국인 첫 확진자"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -90
  ) 

```

주요 시도 비교
=======================================================================

Column {data-width=400}
-------------------------------------

### **일별 누적 사례 수**

    
```{r}
data %>% 
  pivot_wider(names_from = province, values_from = confirmed) -> data_1

data_1 %>%
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~date,
    y = ~Incheon ,
    type = "scatter",
    mode = "lines+markers",
    name = "Incheon"
    # line = list(color = "red"),
    # marker = list(color = "black")
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Seoul ,
    type = "scatter",
    mode = "lines+markers",
    name = "Seoul"
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~Daegu,
    type = "scatter",
    mode = "lines+markers",
    name = "Daegu"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 0.1, y = 0.9),
    yaxis = list(title = "Number of new cases"),
    xaxis = list(title = "Date"),
    # paper_bgcolor = "black",
    # plot_bgcolor = "black",
    # font = list(color = 'white'),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )

```


### **유형별 막대 그래프**    (확진=Confirmed, 사망=deceased)

```{r }

plotly::plot_ly(
  data = data,
  x = ~province,
  # y = ~unrecovered,
  y = ~ confirmed,
  # text =  ~ confirmed,
  # textposition = 'auto',
  type = "bar",
  name = "Confirmed",
  marker = list(color = confirmed_color)
) %>%
  plotly::add_trace(
    y = ~deceased,
    # text =  ~ death,
    # textposition = 'auto',
    name = "deceased",
    marker = list(color = deceased_color)
  ) %>%
  plotly::layout(
    barmode = "relative",  # bar relative stack
    yaxis = list(title = "Total cases"),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )

```


```{r}
data %>% 
  pivot_longer(cols = confirmed:deceased, values_to = "count") %>% 
  arrange(-desc(count)) -> data_2

data_for_plot <- data_2 %>%
  # filter(Country.Region == "Korea_South") %>%
  filter(count > 0) %>%
  group_by(province, longitude, latitude, name) %>%
  summarise(count = sum(count)) %>%
  mutate(log_count = 2 * log(count)) %>%
  ungroup()

data_for_plot.split <- data_for_plot %>% split(data_for_plot$name)

```


공간정보
=======================================================================

### **국내 사례 수** 

```{r}
# map tab added by Art Steinmetz
library(leaflet)
library(leafpop)
library(purrr)

pal <- colorFactor(c("orange", "green", "red"), domain = c("confirmed", "released", "deceased"))
map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(data_for_plot.split) %>%
  purrr::walk(function(df) {
    map_object <<- map_object %>%
      addCircleMarkers(
        data = data_for_plot.split[[df]],
        lng = ~longitude, lat = ~latitude,
        #                 label=~as.character(cases),
        color = ~ pal(name),
        stroke = FALSE,
        fillOpacity = 0.8,
        radius = ~log_count,
        popup = leafpop::popupTable(data_for_plot.split[[df]],
                                    feature.id = FALSE,
                                    row.numbers = FALSE,
                                    zcol = c("province", "name", "count")
        ),
        group = df,
           # clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
        labelOptions = labelOptions(
          noHide = F,
          direction = "auto"
        )
      )
  })
map_object %>%
  addLayersControl(
    overlayGroups = names(data_for_plot.split),
    options = layersControlOptions(collapsed = FALSE)
  )

```