Visualisasi perkembangan kasus Covid-19 di Indonesia. Data harian bersumber dari covid19.go.id dan data perprovinsi dari BNPB. Last update : 2020-09-11
NOTE : Sejak tanggal 10 Agustus data dari BNPB tidak sesuai dengan data resmi gugus tugas sehingga kurvanya menjadi anomali dan tidak valid.
NOTE : Sejak tanggal 10 Agustus data dari BNPB tidak sesuai dengan data resmi gugus tugas sehingga kurvanya menjadi anomali dan tidak valid.
---
title: "COVID-19 INDONESIA UPDATE"
output:
flexdashboard::flex_dashboard:
vertical_layout: scroll
social: menu
source_code: embed
---
Visualisasi perkembangan kasus Covid-19 di Indonesia. Data harian bersumber dari [covid19.go.id](https://data.covid19.go.id/) dan data perprovinsi dari [BNPB](https://bnpb-inacovid19.hub.arcgis.com/).
Last update : `r format(Sys.Date(), "%Y-%m-%d")`
```{r global, include=FALSE}
library(flexdashboard)
source("R/function.R")
source("R/variables.R")
ina_daily <- getData(INA_DAILY) %>% cleanData() %>% mutate(Tanggal = as.Date(harian.key_as_string))
ina_province <- getData(INA_PROVINCE) %>% cleanData()
update_date <- UPDATE_DATE
```
### TOTAL TERKONFIRMASI
```{r confirmed valuebox}
confirmed <- ina_daily %>% subset(Tanggal == update_date, select = total.jumlah_positif) %>%
format(round(0), big.mark = ",")
confirmed_new <- ina_daily %>% subset(Tanggal==update_date, select = penambahan.jumlah_positif) %>%
format(round(0), big.mark = ",")
valueBox(confirmed, caption = sprintf("TERKONFIRMASI (%s)", if(confirmed_new>0) paste0("+",confirmed_new) else confirmed_new), icon = "fa fa-thermometer-full")
```
### TOTAL DIRAWAT
```{r hospitilized valuebox}
hospitilized <- ina_daily %>% subset(Tanggal==update_date, select = total.jumlah_dirawat) %>%
format(round(0), big.mark = ",")
hospitilized_new <- ina_daily %>% subset(Tanggal==update_date, select = penambahan.jumlah_dirawat) %>%
format(round(0), big.mark = ",")
valueBox(hospitilized, caption = sprintf("DALAM PERAWATAN (%s)", if(hospitilized_new>0) paste0("+",hospitilized_new) else hospitilized_new), icon = "fa fa-hospital-o", color = "orange")
```
### TOTAL SEMBUH
```{r recover valuebox}
recovered <- ina_daily %>% subset(Tanggal==update_date, select = total.jumlah_sembuh) %>%
format(round(0), big.mark = ",")
recovered_new <- ina_daily %>% subset(Tanggal==update_date, select = penambahan.jumlah_sembuh) %>%
format(round(0), big.mark = ",")
valueBox(recovered, caption = sprintf("SEMBUH (%s)", if(recovered_new>0) paste0("+",recovered_new) else recovered_new), icon = "fa fa-heart", color = "green")
```
### TOTAL MENINGGAL
```{r death valuebox}
death <- ina_daily %>% subset(Tanggal==update_date, select = total.jumlah_meninggal) %>%
format(round(0), big.mark = ",")
death_new <- ina_daily %>% subset(Tanggal==update_date, select = penambahan.jumlah_meninggal) %>%
format(round(0), big.mark = ",")
valueBox(death, caption = sprintf("MENINGGAL (%s)", if(death_new>0) paste0("+",death_new) else death_new), icon = "fa fa-plus-square", color = "red")
```
### TREND KASUS KUMULATIF {data-padding=10}
```{r cummulative trend}
library(dplyr)
library(dygraphs)
library(xts)
dygraph_df <- ina_daily %>%
select(Tanggal, harian.jumlah_positif_kum.value, harian.jumlah_sembuh_kum.value, harian.jumlah_meninggal_kum.value)%>%
filter(Tanggal < update_date + 1) %>%
rename(TERKONFIRMASI = harian.jumlah_positif_kum.value, SEMBUH = harian.jumlah_sembuh_kum.value, MENINGGAL = harian.jumlah_meninggal_kum.value)
xts_df <- xts(dygraph_df[,-1], dygraph_df[,1])
dygraph_plot_cum <- xts_df %>%
dygraph(main = "TREND KASUS KUMULATIF", ylab = "Total Kasus") %>%
dyRangeSelector(height = 20) %>%
dyGroup(c("TERKONFIRMASI", "SEMBUH", "MENINGGAL"), drawPoints = TRUE, color = c("blue", "green", "red")) %>%
dyLegend(width = 300) %>%
dyShading(from = "2020/04/10", to = "2020-06-01", color = "#FFE6E6") %>%
dyShading(from = "2020/06/01", to = max(ina_daily$Tanggal), color = "#CCEBD6") %>%
dyEvent("2020/04/10", "Pemberlakuan PSBB", labelLoc = "bottom") %>%
dyEvent("2020/05/23", "Lebaran", labelLoc = "bottom") %>%
dyEvent("2020/06/01", "New Normal / Transisi / AKB", labelLoc = "bottom")
dygraph_plot_cum
```
### TREND KASUS BARU PERHARI
```{r daily trend}
library(dplyr)
library(dygraphs)
library(xts)
dygraph_df <- ina_daily %>%
filter(Tanggal < update_date + 1) %>%
select(Tanggal, harian.jumlah_positif.value, harian.jumlah_sembuh.value, harian.jumlah_meninggal.value)%>%
mutate(Tanggal=as.Date(Tanggal)) %>%
rename(TERKONFIRMASI = harian.jumlah_positif.value, SEMBUH = harian.jumlah_sembuh.value, MENINGGAL = harian.jumlah_meninggal.value)
xts_df <- xts(dygraph_df[,-1], dygraph_df[,1])
dygraph_plot_new_case <- xts_df %>%
dygraph(main = "TREND KASUS BARU PERHARI", ylab = "Jumlah Kasus Baru") %>%
dyGroup(c("TERKONFIRMASI", "SEMBUH", "MENINGGAL"), drawPoints = TRUE, color = c("blue", "green", "red")) %>%
dyRangeSelector(height = 20) %>%
dyLegend(width = 300) %>%
dyShading(from = "2020/04/10", to = "2020/06/01", color = "#FFE6E6") %>%
dyEvent("2020/05/23", "Lebaran", labelLoc = "bottom") %>%
dyShading(from = "2020/06/01", to = max(ina_daily$Tanggal), color = "#CCEBD6") %>%
dyEvent("2020/04/10", "Pemberlakuan PSBB", labelLoc = "bottom") %>%
dyEvent("2020/05/23", "Lebaran", labelLoc = "bottom") %>%
dyEvent("2020/06/01", "New Normal / Transisi / AKB", labelLoc = "bottom")
dygraph_plot_new_case
```
### TREND PERPROVINSI
```{r daily trend by province}
library(RcppRoll)
# code refference https://github.com/dioariadi/covid-19/blob/master/covid-19-tracker-indonesia.Rmd
case_by_prov <- ina_province %>%
select(Provinsi, Tanggal, Penambahan_Harian_Kasus_Terkonf) %>%
filter(Provinsi != "Indonesia") %>%
mutate(Tanggal = as.Date(Tanggal)) %>%
filter(Tanggal != "2020-08-03" & Tanggal < "2020-08-10") %>%
arrange(Tanggal) %>%
group_by(Provinsi) %>%
mutate(casesroll_avg=round(roll_mean(Penambahan_Harian_Kasus_Terkonf, 7, align="right", fill=0),0)) %>%
ungroup()
filter_daily <- case_by_prov %>%
group_by(Provinsi) %>%
filter(casesroll_avg >= 5) %>%
slice(min(which(casesroll_avg >= 5))) %>%
ungroup() %>%
#mutate(Tanggal = as.Date(Tanggal)) %>%
rename(filter_week = Tanggal)
case_by_prov_daily <- case_by_prov %>% ungroup() %>%
left_join(filter_daily[,c(1,2)], by = c("Provinsi")) %>%
filter(Tanggal >= filter_week) %>%
arrange(Tanggal) %>%
group_by(Provinsi) %>%
mutate(day_since_n_case = row_number()) %>%
ungroup()
```
```{r daily trend by province plot}
library(highcharter)
case_prov_daily_plot <- hchart(case_by_prov_daily, "line",
hcaes(x = day_since_n_case, y = casesroll_avg, group = Provinsi),
showInLegend = FALSE) %>%
hc_xAxis(
title = list(text = "Jumlah Hari Sejak Rata-rata Kasus Perhari diatas 4"),
gridLineWidth = 0
) %>%
hc_yAxis(
title = list(text = "Penambahan Kasus Perhari"),
type = "linear",
min = 0,
accessibility = list(
rangeDescription = 'Range: 1 to 1000'),
gridLineWidth = 0
) %>%
hc_title(
style = list(color = hex_to_rgba("black", 0.7)),
text = "Penambahan Kasus Perprovinsi"
) %>%
hc_subtitle(
style = list(color = hex_to_rgba("black", 0.5)),
text = "Rolling Average 7 hari Penambahan Kasus Terkonfirmasi Perhari"
) %>%
hc_caption(
text = sprintf("Data as of : %s", max(case_by_prov$Tanggal))
)
case_prov_daily_plot
```
> NOTE : Sejak tanggal 10 Agustus data dari BNPB tidak sesuai dengan data resmi gugus tugas sehingga kurvanya menjadi anomali dan tidak valid.
### PROVINSI STATUS
```{r province status}
prov_status <- ina_province %>%
select(Provinsi, Tanggal, Kasus_Terkonfirmasi_Akumulatif, Kasus_Sembuh_Akumulatif, Kasus_Meninggal_Akumulatif, Kasus_Aktif_Akumulatif) %>%
filter(Provinsi != "Indonesia") %>%
filter(as.Date(Tanggal) == max(as.Date(Tanggal))) %>%
mutate(death_rate = round(Kasus_Meninggal_Akumulatif / Kasus_Terkonfirmasi_Akumulatif, 4) * 100) %>%
mutate(recovery_rate = round(Kasus_Sembuh_Akumulatif / Kasus_Terkonfirmasi_Akumulatif, 4) * 100)
```
```{r province status plot}
library(highcharter)
#colorised status based on death_rate dan recovery_rate
prov_status$Status <- with(prov_status, ifelse(
death_rate < mean(prov_status$death_rate) & recovery_rate < mean(prov_status$recovery_rate), 'LowDeathLowRecover', ifelse(
death_rate > mean(prov_status$death_rate) & recovery_rate < mean(prov_status$recovery_rate), 'HighDeathLowRecover', ifelse(
death_rate > mean(prov_status$death_rate) & recovery_rate > mean(prov_status$recovery_rate), 'HighDeathHighRecover', ifelse(
death_rate < mean(prov_status$death_rate) & recovery_rate > mean(prov_status$recovery_rate), 'LowDeathHighRevover', 'Others')))))
colors <- c('#FFA500', '#FF4500', '#7FFF00', '#FFD700', '#FFC100')
x <- c("Provinsi", "Recovery Rate", "Death Rate", "Kasus Aktif")
#y <- sprintf("{point.%s:.2f}", c("Provinsi", "recovery_rate", "death_rate", "Kasus_Aktif_Akumulatif"))
y <- c("{point.Provinsi}", "{point.recovery_rate}%", "{point.death_rate}%", "{point.Kasus_Aktif_Akumulatif}")
tooltip_tb <- tooltip_table(x, y)
hchart(
prov_status,
"scatter",
hcaes(
as.numeric(recovery_rate),
as.numeric(death_rate),
size = Kasus_Terkonfirmasi_Akumulatif,
group = Status
),
minSize = 15,
maxSize = 55
) %>%
hc_chart(
backgroundColor = "white",
backgroundColor = hex_to_rgba("white", 0.5)
) %>%
hc_colors(colors = colors) %>%
hc_xAxis(
title = list(text = "Recovery Rate"),
labels = list(format = '{value}%'),
plotLines = list(list(
value = mean(prov_status$recovery_rate),
label = list(
text = sprintf("Rata-rata Nasional (%s%%)", round(mean(prov_status$recovery_rate),2)),
rotation = 0,
style = list(fontStyle = 'italic')),
color = 'black',
width = 2,
dashStyle = 'dot'
)),
gridLineWidth = 0,
reversed = FALSE
) %>%
hc_yAxis(
title = list(text = "Death Rate"),
labels = list(format = '{value}%'),
min = 0,
max = max(prov_status$death_rate) + 1,
plotLines = list(list(
value = mean(prov_status$death_rate),
label = list(
text = sprintf("Rata-rata Nasional (%s%%)", round(mean(prov_status$death_rate),2)),
rotation = 0,
style = list(fontStyle = 'italic')),
color = 'black',
width = 2,
dashStyle = 'dot'
)),
gridLineWidth = 0
) %>%
hc_title(
style = list(color = hex_to_rgba("black", 0.7)),
text = "Status Perprovinsi"
) %>%
hc_subtitle(
style = list(color = hex_to_rgba("black", 0.5)),
text = "Berdasarkan Fatality Rate"
) %>%
hc_caption(
text = sprintf("Data as of : %s", max(case_by_prov$Tanggal))
) %>%
#
# hc_plotOptions(
# series = list(
# dataLabels = list(
# enabled = TRUE,
# format = '{point.Provinsi}',
# allowOverlap = TRUE,
# style = list(
# color = "black",
# fontSize = "9px",
# fontWeight = "bold",
# textOutline = "0.5px contrast"
# )
# )
# )
#) %>%
hc_tooltip(
useHTML = TRUE,
headerFormat = "",
pointFormat = tooltip_tb
) %>%
hc_plotOptions(
series = list(
maxSize = 70)
)
```
> NOTE : Sejak tanggal 10 Agustus data dari BNPB tidak sesuai dengan data resmi gugus tugas sehingga kurvanya menjadi anomali dan tidak valid.