Ringkasan

Row

terkonfirmasi

1 790

active

1 508 (84.2%)

recovered

112 (6.3%)

death

170 (9.5%)

Row

Akumulasi kasus harian (Indonesia)

Perbandingan

Column

Akumulasi kasus setiap hari

Sebaran kasus berdasarkan tipe kasus

Kasus Harian

Column

Kasus baru harian (di Indonesia)

Kasus baru harian (Dunia)

Tingkat Kematian

Column

Daftar negara berdasarkan tingkat kematian

Negara dengan tingkat kematian tertinggi

Peta Sebaran

Peta sebarab kasus di dunia (gunakan ikon + dan - untuk zoom in/out)

About

Dashboard ini dibuat menggunakan RStudio. Package yang digunakan antara lain tidyverse, flexdashboard, DT, dan plotly. Sedangkan data yang digunakan pada dashboard ini diambil dari data.humdata.org yang diperbaharui setiap hari.

---
title: "Coronavirus di Indonesia"
author: "by U"
output:
  flexdashboard::flex_dashboard:
    orientation: rows
    source_code: embed
    vertical_layout: fill
  html_document:
    df_print: paged
---

```{r setup, include=FALSE}
#------------------ Packages ------------------
library(flexdashboard)

confirmed_color <- "purple"
active_color <- "#1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"

library(flipTime)
UpdateEvery(2, "hours", options = "wakeup") 

confirmed <- read.csv("https://data.humdata.org/hxlproxy/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_covid19_confirmed_global.csv&filename=time_series_covid19_confirmed_global.csv")
death <- read.csv("https://data.humdata.org/hxlproxy/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_covid19_deaths_global.csv&filename=time_series_covid19_deaths_global.csv")
recovered <- read.csv("https://data.humdata.org/hxlproxy/api/data-preview.csv?url=https%3A%2F%2Fraw.githubusercontent.com%2FCSSEGISandData%2FCOVID-19%2Fmaster%2Fcsse_covid_19_data%2Fcsse_covid_19_time_series%2Ftime_series_covid19_recovered_global.csv&filename=time_series_covid19_recovered_global.csv")

library(tidyverse)

con_data <- confirmed %>%
  pivot_longer(-(1:4), names_to = "date", values_to = "confirmed")
dea_data <- death %>%
  pivot_longer(-(1:4), names_to = "date", values_to = "death")
rec_data <- recovered %>%
  pivot_longer(-(1:4), names_to = "date", values_to = "recovered")

data <- full_join(con_data, dea_data)
data <- full_join(data, rec_data)

data$date <- substring(data$date, 2)
data$date <- gsub("[.]", "-", data$date)
data$date <- as.Date(data$date, "%m-%d-%y")

db <- data %>%
  filter(Country.Region == "Indonesia", date > "2020-02-15") %>%
  arrange(date) %>%
  mutate(unrecover = confirmed - death - recovered)

db$daily_con <- 0
for (i in 1 : nrow(db)) {
  if (i == 1) {
    db$daily_con[i] <- 0
  } else {
    db$daily_con[i] <- db$confirmed[i] - db$confirmed[i-1]
  }
}

db$daily_dea <- 0
for (i in 1 : nrow(db)) {
  if (i == 1) {
    db$daily_dea[i] <- 0
  } else {
    db$daily_dea[i] <- db$death[i] - db$death[i - 1]
  }
}

db$daily_rec <- 0
for (i in 1 : nrow(db)) {
  if (i == 1) {
    db$daily_rec[i] <- 0
  } else {
    db$daily_rec[i] <- db$recovered[i] - db$recovered[i - 1]
  }
}

db1 <- db %>% filter(date == max(date))
```

Ringkasan
=======================================================================

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

### terkonfirmasi {.value-box}

```{r}

valueBox(
  value = paste(format(db1$confirmed, big.mark = " "), "", sep = " "),
  caption = "Terkonfirmasi",
  icon = "fas fa-user-md",
  color = confirmed_color
)
```


### active {.value-box}

```{r}
valueBox(
  value = paste(format(db1$unrecover, big.mark = " "), " (",
    round(100 * db1$unrecover / db1$confirmed, 1),
    "%)",
    sep = ""
  ),
  caption = "Dalam Perawatan (% dari terkonfirmasi)", icon = "fas fa-ambulance",
  color = active_color
)
```

### recovered {.value-box}

```{r}
valueBox(
  value = paste(format(db1$recovered, big.mark = " "), " (",
    round(100 * db1$recovered / db1$confirmed, 1),
    "%)",
    sep = ""
  ),
  caption = "Sembuh (% dari terkonfirmasi)", icon = "fas fa-smile-beam",
  color = recovered_color
)
```

### death {.value-box}

```{r}

valueBox(
  value = paste(format(db1$death, big.mark = " "), " (",
    round(100 * db1$death / db1$confirmed, 1),
    "%)",
    sep = ""
  ),
  caption = "Meninggal",
  icon = "fas fa-heart-broken",
  color = death_color
)
```


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

### **Akumulasi kasus harian** (Indonesia)
    
```{r}
plotly::plot_ly(data = db) %>%
  plotly::add_trace(
    x = ~date,
    y = ~confirmed,
    type = "scatter",
    mode = "lines+markers",
    name = "Terkonfirmasi",
    line = list(color = confirmed_color),
    marker = list(color = confirmed_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~death,
    type = "scatter",
    mode = "lines+markers",
    name = "Meninggal",
    line = list(color = death_color),
    marker = list(color = death_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~recovered,
    type = "scatter",
    mode = "lines+markers",
    name = "Sembuh",
    line = list(color = recovered_color),
    marker = list(color = recovered_color)
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-02"),
    y = 1,
    text = paste("Kasus Pertama"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -90,
    ay = -90
  ) %>%
  plotly::add_annotations(
    x = as.Date("2020-03-11"),
    y = 3,
    text = paste("Kematian Pertama"),
    xref = "x",
    yref = "y",
    arrowhead = 5,
    arrowhead = 3,
    arrowsize = 1,
    showarrow = TRUE,
    ax = -10,
    ay = -90
  ) %>%
  plotly::layout(
    title = "",
    yaxis = list(title = "Banyaknya kasus (kumulatif)"),
    xaxis = list(title = "Tanggal"),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  )
```


Perbandingan
=======================================================================


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


### **Akumulasi kasus setiap hari**
    
```{r}
daily_confirmed <- data %>%
  filter(date >= "2020-02-29") %>%
  mutate(country = Country.Region) 

#----------------------------------------
# Plotting the data

daily_confirmed %>%
    filter(country == "Malaysia") %>%
  plotly::plot_ly() %>%
  plotly::add_trace(
    x = ~date,
    y = ~confirmed,
    type = "scatter",
    mode = "lines+markers",
    name = "Malaysia"
  ) %>%
  plotly::add_trace(
    x = ~daily_confirmed$date[daily_confirmed$country == "Japan"],
    y = ~daily_confirmed$confirmed[daily_confirmed$country == "Japan"],
    type = "scatter",
    mode = "lines+markers",
    name = "Japan"
  ) %>%
  plotly::add_trace(
    x = ~daily_confirmed$date[daily_confirmed$country == "Singapore"],
    y = ~daily_confirmed$confirmed[daily_confirmed$country == "Singapore"],
    type = "scatter",
    mode = "lines+markers",
    name = "Singapore"
  ) %>%
  plotly::add_trace(
    x = ~daily_confirmed$date[daily_confirmed$country == "Indonesia"],
    y = ~daily_confirmed$confirmed[daily_confirmed$country == "Indonesia"],
    type = "scatter",
    mode = "lines+markers",
    name = "Indonesia"
  ) %>%
  plotly::layout(
    title = "",
    legend = list(x = 0.1, y = 0.9),
    yaxis = list(title = "Akumulasi kasus harian"),
    xaxis = list(title = "Tanggal"),
    # paper_bgcolor = "black",
    # plot_bgcolor = "black",
    # font = list(color = 'white'),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )
```
 
### **Sebaran kasus berdasarkan tipe kasus**

```{r daily_summary}
db2 <- data %>%
  filter(Country.Region == "Malaysia" | Country.Region == "Indonesia" |
           Country.Region == "Singapore" | Country.Region == "Japan") %>%
  filter(date == max(date))
db2 <- db2 %>%
  mutate(unrecovered = confirmed - death -recovered,
         country = factor(Country.Region, levels = Country.Region))

plotly::plot_ly(
  data = db2,
  x = ~country,
  y = ~unrecovered,
  # text =  ~ confirmed,
  # textposition = 'auto',
  type = "bar",
  name = "Dirawat",
  marker = list(color = active_color)
) %>%
  plotly::add_trace(
    y = ~recovered,
    # text =  ~ death,
    # textposition = 'auto',
    name = "Sembuh",
    marker = list(color = recovered_color)
  ) %>%
  plotly::add_trace(
    y = ~death,
    # text =  ~ death,
    # textposition = 'auto',
    name = "Meninggal",
    marker = list(color = death_color)
  ) %>%
  plotly::layout(
    barmode = "stack",
    yaxis = list(title = "Total Kasus"),
    xaxis = list(title = ""),
    hovermode = "compare",
    margin = list(
      # l = 60,
      # r = 40,
      b = 10,
      t = 10,
      pad = 2
    )
  )
```


Kasus Harian
=======================================================================

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

### **Kasus baru harian** (di Indonesia)

```{r}
plotly::plot_ly(data = db) %>%
  plotly::add_trace(
    x = ~date,
    y = ~daily_con,
    type = "scatter",
    mode = "lines+markers",
    name = "Terkonfirmasi",
    line = list(color = confirmed_color),
    marker = list(color = confirmed_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~daily_dea,
    type = "scatter",
    mode = "lines+markers",
    name = "Meninggal",
    line = list(color = death_color),
    marker = list(color = death_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~daily_rec,
    type = "scatter",
    mode = "lines+markers",
    name = "Sembuh",
    line = list(color = recovered_color),
    marker = list(color = recovered_color)
  ) %>%
  plotly::layout(
    title = "",
    yaxis = list(title = "Banyaknya kasus"),
    xaxis = list(title = "Tanggal"),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  )
```


### **Kasus baru harian** (Dunia)
    
```{r}
dw <- data %>%
  group_by(date) %>%
  summarize(confirmed = sum(confirmed, na.rm = T),
            death =  sum(death, na.rm = T),
            recovered = sum(recovered, na.rm = T))

dw$daily_con <- 0
for (i in 1 : nrow(dw)) {
  if (i == 1) {
    dw$daily_con[i] <- 0
  } else {
    dw$daily_con[i] <- dw$confirmed[i] - dw$confirmed[i-1]
  }
}

dw$daily_dea <- 0
for (i in 1 : nrow(dw)) {
  if (i == 1) {
    dw$daily_dea[i] <- 0
  } else {
    dw$daily_dea[i] <- dw$death[i] - dw$death[i - 1]
  }
}

dw$daily_rec <- 0
for (i in 1 : nrow(dw)) {
  if (i == 1) {
    dw$daily_rec[i] <- 0
  } else {
    dw$daily_rec[i] <- dw$recovered[i] - dw$recovered[i - 1]
  }
}

dw <- filter(dw, date > "2020-02-15")
plotly::plot_ly(data = dw) %>%
  plotly::add_trace(
    x = ~date,
    y = ~daily_con,
    type = "scatter",
    mode = "lines+markers",
    name = "Terkonfirmasi",
    line = list(color = confirmed_color),
    marker = list(color = confirmed_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~daily_dea,
    type = "scatter",
    mode = "lines+markers",
    name = "Meninggal",
    line = list(color = death_color),
    marker = list(color = death_color)
  ) %>%
  plotly::add_trace(
    x = ~date,
    y = ~daily_rec,
    type = "scatter",
    mode = "lines+markers",
    name = "Sembuh",
    line = list(color = recovered_color),
    marker = list(color = recovered_color)
  ) %>%
  plotly::layout(
    title = "",
    yaxis = list(title = "Banyaknya kasus"),
    xaxis = list(title = "Tanggal"),
    legend = list(x = 0.1, y = 0.9),
    hovermode = "compare"
  )
```



Tingkat Kematian
=======================================================================

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


### **Daftar negara berdasarkan tingkat kematian**
    
```{r}
dr <- data %>%
  select(Country.Region, date, confirmed, death, recovered)
#dr$Country.Region <- fct_explicit_na(dr$Country.Region)
dr <- dr %>%
  group_by(Country.Region) %>%
  filter(date == max(date))
dr <- dr %>%
  group_by(Country.Region) %>%
  summarize(confirmed = sum(confirmed),
            death = sum(death),
            recovered = sum(recovered))
dr <- dr %>%
  mutate(death_rate = round(death / confirmed *100, 2)) %>%
  filter(confirmed > 0) %>%
  arrange(desc(death_rate)) 
dr1 <- dr
names(dr1) <- c("Negara", "Terkonfirmasi", "Meninggal", "Sembuh", "Tingkat Kematian (%)")

DT::datatable(dr1, options = list(lengthMenu = c(10, 20, 50, 100), pageLength = 10))
```
 
### **Negara dengan tingkat kematian tertinggi**

```{r}
dr1 <- dr[1:15,]
dr1$Country.Region <- factor(dr1$Country.Region, levels = dr1$Country.Region)
plotly::plot_ly(
  data = dr1,
  x = ~Country.Region,
  y = ~death_rate,
  # text =  ~ confirmed,
  # textposition = 'auto',
  type = "bar",
  name = "Dirawat",
  marker = list(color = death_color)
) %>%
  plotly::layout(
    title = "",
    yaxis = list(title = "Tingkat Kematian (%)"),
    xaxis = list(title = "Negara"),
    hovermode = "compare"
  )
```


Peta Sebaran
=======================================================================

### **Peta sebarab kasus di dunia** (*gunakan ikon + dan - untuk zoom in/out*)

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

dbmap <- data %>%
  select(Province.State, Country.Region, date, Lat, Long, confirmed, death, recovered)
#dr$Country.Region <- fct_explicit_na(dr$Country.Region)
dbmap <- dbmap %>%
  group_by(Country.Region, Province.State) %>%
  filter(date == max(date)) %>%
  select(-date)
names(dbmap) <- c("Province.State", "Country.Region", "Lat", "Long", "Terkonfirmasi", "Meninggal", "Sembuh")

dbmap <- dbmap %>%
  pivot_longer(5:7, names_to = "type", values_to = "cases")

cv_data_for_plot <- dbmap %>%
  # dplyr::filter(Country.Region == "Belgium") %>%
  dplyr::filter(cases > 0) %>%
  dplyr::group_by(Country.Region, Province.State, Lat, Long, type) %>%
  dplyr::summarise(cases = sum(cases)) %>%
  dplyr::mutate(log_cases = 2 * log(cases)) %>%
  dplyr::ungroup()
cv_data_for_plot.split <- cv_data_for_plot %>% split(cv_data_for_plot$type)
pal <- colorFactor(c("red", "green", "orange"), domain = c("Terkonfirmasi", "Meninggal", "Sembuh"))
map_object <- leaflet() %>% addProviderTiles(providers$Stamen.Toner)
names(cv_data_for_plot.split) %>%
  purrr::walk(function(df) {
    map_object <<- map_object %>%
      addCircleMarkers(
        data = cv_data_for_plot.split[[df]],
        lng = ~Long, lat = ~Lat,
        #                 label=~as.character(cases),
        color = ~ pal(type),
        stroke = FALSE,
        fillOpacity = 0.8,
        radius = ~log_cases,
        popup = leafpop::popupTable(cv_data_for_plot.split[[df]],
          feature.id = FALSE,
          row.numbers = FALSE,
          zcol = c("type", "cases", "Country.Region", "Province.State")
        ),
        group = df,
        #                 clusterOptions = markerClusterOptions(removeOutsideVisibleBounds = F),
        labelOptions = labelOptions(
          noHide = F,
          direction = "auto"
        )
      )
  })

map_object %>%
  addLayersControl(
    overlayGroups = names(cv_data_for_plot.split),
    options = layersControlOptions(collapsed = FALSE)
  )
```



About
=======================================================================

**Dashboard** ini dibuat menggunakan **RStudio**. *Package* yang digunakan antara lain ```tidyverse```, ```flexdashboard```, ```DT```, dan ```plotly```. Sedangkan **data** yang digunakan pada *dashboard* ini diambil dari [data.humdata.org](https://data.humdata.org/dataset/novel-coronavirus-2019-ncov-cases#){target="_blank"} yang diperbaharui setiap hari.