Buat Bidang Kasus Virus Corona dengan R Studio Cloud

install.packages (c ("devtools", "flexdashboard", "leaflet", "leafpop"))
perpustakaan (devtools) 
perpustakaan (flexdashboard)
perpustakaan (leaflet)
perpustakaan (leafpop)
devtools :: install_github ("RamiKrispin / coronavirus")
library (coronavirus) --- 
judul: "Coronavirus in Indonesia"
penulis: "Reza Hartono"
output:
flexdashboard :: flex_dashboard:
orientasi: baris
# social: ["facebook", "twitter", "twitter", "twitterin"]
source_code: embed
vertical_layout : mengisi
--- `` `{r setup, termasuk = FALSE}
perpustakaan (flexdashboard)
# install.packages ( "devtools")
# devtools :: install_github ( "RamiKrispin / coronavirus", gaya = TRUE)
library (coronavirus)
Data (coronavirus)
update_dataset ()
# Lihat (coronavirus)
# max (coronavirus $ date)
`%>%` <- magrittr :: `%>% `
# ------------------ Parameter ------------------
# Atur warna
#https://www.w3.org/TR/css-color-3/#svg-color confirm_color
<- "purple"
active_color <- "# 1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
# - ---------------- Data ------------------
df <- coronavirus%>%
# dplyr :: filter (date = = maks (tanggal))%>%
dplyr :: filter (negara == "Indonesia")%>%
dplyr :: group_by (negara, jenis)%>%
dplyr :: merangkum (jumlah = jumlah (kasus))%>> %
tidyr :: pivot_wider (
names_from = type,
values_from = total
)%>%
# dplyr :: bermutasi (tidak dipulihkan = dikonfirmasi - ifelse (is.na (pulih), 0, pulih) - ifelse (is.na (kematian), 0, kematian))%>%
dplyr :: bermutasi (belum ditemukan = dikonfirmasi - ifelse (is.na (kematian), 0, kematian))%>%
dplyr :: atur (-confirmed)%>%
dplyr :: ungroup ()%>%
dplyr :: mutate (negara = dplyr :: if_else (negara == "Uni Emirat Arab", "UEA", negara))%>%
dplyr :: bermutasi (negara = dplyr :: if_else (negara == "Daratan Tiongkok", "Tiongkok" , negara))%>%
dplyr :: bermutasi (negara = dplyr :: if_else (negara == "Makedonia Utara", "N.Macedonia", negara))%>%
dplyr :: bermutasi (negara = trimws (negara) )%>%
dplyr :: mutate (negara = faktor (negara, level = negara))
df_daily <- coronavirus%>%
dplyr :: filter (negara == "Indonesia")%>%
dplyr :: group_by (tanggal, jenis )%>%
dplyr :: merangkum (total = jumlah (kas, na.rm = BENAR))%>%
tidyr :: pivot_wider (
names_from = jenis,
values_from = total
)%>%
dplyr :: atur (tanggal)%>%
dplyr :: ungroup ()%>%
#dplyr :: bermutasi (aktif = dikonfirmasi - kematian - pulih)% >%
dplyr :: bermutasi (aktif = dikonfirmasi - kematian)%>%
dplyr :: bermutasi (
dikonfirmasi_cum = cumsum (dikonfirmasi),
death_cum = cumsum (kematian),
# recovered_cum = cumsum (pulih),
active_cum = cumsum (aktif)
)
df1 <- coronavirus%>% dplyr :: filter (date == max (date))
`` `Ringkasan
========================== ============================================= Baris {data-lebar = 400}
-------------------------------------------------- --------------------- ### dikonfirmasi {.value-box} `` `{r}
valueBox (
value = paste (format (jumlah (df $ dikonfirmasi ), big.mark = ","), "", sep = ""),
caption = "Jumlah kasus yang dikonfirmasi",
ikon = "fas fa-user-md",
color = confirm_color
)
`` `<! - ### active {.value-box} -> <! - `` `{r} ->
<! - valueBox (->
<! - value = paste (format (jumlah (df $ belum pulih) , na.rm = BENAR), big.mark = ","), "(", ->
<! - bulat (100 * jumlah (df $ belum pulih, na.rm = BENAR) / jumlah (df $ dikonfirmasi ), 1), ->
<! - "%)", ->
<! - sep = "" ->
<! -), ->
<! - caption = "Kasing aktif (% dari total kasing)", icon = "fas fa-ambulance", ->
<! - color = active_color ->
<! -) ->
<! - `` `-> ### death {.value-box}` `` {r}
valueBox (
value = paste ( format (jumlah (df $ kematian, na.rm = BENAR), big.mark = ","), "(",
bulat (100 * jumlah (df $ kematian, na.rm = BENAR) / jumlah (df $ dikonfirmasi ), 1),
"%)",
sep = ""
),
caption = "Kasus kematian (angka kematian)",
ikon = "fas fa-heart-broken",
color = death_color
)
`` `Baris
---- -------------------------------------------------- ----------------- ### ** Kasus kumulatif harian menurut jenis ** (hanya Indonesia)

`` `{r}
plotly :: plot_ly (data = df_daily)%> %
plotly :: add_trace (
x = ~ date,
# y = ~ active_cum,
y = ~ confirm_cum,
ketik = "scatter",
mode = "lines + spiders",
# name = "Active",
name = "Dikonfirmasi",
line = daftar (warna = active_color),
marker = daftar (warna = active_color)
) %>%
plotly :: add_trace (
x = ~ tanggal,
y = ~ death_cum,
ketik = "scatter",
mode = "garis + spidol",
nama = "Kematian",
baris = daftar (warna = death_color),
marker = daftar (color = death_color)
)%>%
plotly :: add_annotations (
x = as.Date ("2020-03-02"),
y = 1,
text = paste (" Case pertama"),
xref = "x",
yref = "y",
panah = 5,
panah = 3, panah
ukuran = 1,
showarrow = BENAR,
kapak = -10,
ay = -90
)%>%
plotly :: add_annotations (
x = as.Date ("2020-03-11"),
y = 1,
teks = tempel ("Kematian pertama"),
xref = "x",
yref = "y",
panah = 5,
panah = 3, panah
ukuran = 1,
showarrow = BENAR,
kapak = -10,
ay = -90
)%>%
plotly :: layout (
title = "",
yaxis = daftar (title = "Jumlah kasus kumulatif"),
xaxis = daftar (judul = "Tanggal"),
legenda = daftar (x = 0,1, y = 0,9),
hovermode = "bandingkan"
)
`` `Perbandingan
============================================== ========================= Kolom {data-width = 400}
----------------- -------------------- ### ** Setiap hari kasus baru yang dikonfirmasi **

`` `{r}
daily_confirmed <- coronavirus%>%
dplyr :: filter (ketik == "dikonfirmasi")%>%
dplyr :: filter (date> = "2020-02-29")%>%
dplyr :: mutate (negara = negara)%>%
dplyr :: group_by (tanggal, negara)% >%
dplyr :: merangkum (total = jumlah (kasus))%>%
dplyr :: ungroup ()%>%
tidyr :: pivot_wider (names_from = negara, values_from = total)
# ---------- ------------------------------
#
Memplot data daily_confirmed%>%
plotly :: plot_ly ()%>%
plotly ::add_trace (
x = ~ date,
y = ~ Indonesia,
ketik = "scatter",
mode = "lines + spiders",
name = "Indonesia"
)%>%
plotly :: add_trace (
x = ~ date,
y = ~ Malaysia,
type = "scatter",
mode = "lines + spiders",
name = "Malaysia"
)%>%
plotly :: add_trace (
x = ~ tanggal,
y = ~ Singapura,
ketik = "scatter",
mode = "lines + spiders",
name = "Singapura"
)%>%
plotly :: add_trace (
x = ~ tanggal,
y = ~ Thailand,
ketik = "sebar",
mode = "baris + spidol ",
name =" Thailand "
)%>%
plotly :: tata letak (
title = "",
legenda = daftar (x = 0,1, y = 0,9),
yaxis = daftar (judul = "Jumlah kasus yang dikonfirmasi baru"),
xaxis = daftar (judul = "Tanggal"),
# paper_bgcolor = "hitam",
# plot_bgcolor = "hitam",
# font = daftar (warna = 'putih'),
hovermode = "bandingkan",
margin = daftar (
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
`` `

### ** Distribusi kasus berdasarkan tipe **` `` {r daily_summary}
df_EU <- coronavirus%>%
# dplyr :: filter (tanggal == maks (tanggal)) %>%
dplyr :: filter (negara == "Indonesia "|
negara == "Malaysia" |
negara == "Singapura" |
negara == "Thailand")%>%
dplyr :: group_by (negara, tipe)%>%
dplyr :: merangkum (total = jumlah (kasus))%>%
tidyr :: pivot_wider (
names_from = jenis,
values_from = total
) %>%
# dplyr :: mutate (belum ditemukan = dikonfirmasi - ifelse (is.na (recovered), 0, recovered) - ifelse (is.na (kematian), 0, death))%>%
dplyr :: mutate (unrecovered = dikonfirmasi - ifelse (is.na (kematian), 0, death))%>%
dplyr :: atur (dikonfirmasi)%>%
dplyr :: ungroup ()%>%
dplyr :: bermutasi (negara = dplyr :: if_else (negara == "Uni Emirat Arab", "UEA", negara))%>%
dplyr :: bermutasi (negara = dplyr :: if_else (negara == "China Daratan", "China", negara))%>%
dplyr :: bermutasi (negara = dplyr :: if_else (negara == "Makedonia Utara", "N.Macedonia", negara))%>%
dplyr :: bermutasi (negara = trimws (negara))%>%
dplyr :: bermutasi (negara = faktor (negara, level = negara))
plotly :: plot_ly (
data = df_EU,
x = ~ negara,
# y = ~ belum pulih,
y = ~ dikonfirmasi,
# teks = ~ dikonfirmasi,
# textposition = 'auto',
ketik = "bar",
nama = "Dikonfirmasi",
penanda = daftar (warna = active_color )
)%>%
plotly :: add_trace (
y = ~ kematian,
# text = ~ kematian,
# textposition = 'auto',
name = "Death",
marker = list (color = death_color)
)%>%
plotly :: layout (
barmode = "stack",
yaxis = daftar (judul = "Total kasus"),
xaxis = daftar (judul = "") ,
hovermode = "bandingkan",
margin = daftar (
# l = 60,
# r = 40,
b = 10,
t = 10,
pad = 2
)
)
`` `Peta
============ ================================================== ========= ### ** Peta dunia kasus ** (* gunakan ikon + dan - untuk memperbesar / memperkecil *) `` `{r}
# tab peta ditambahkan oleh
perpustakaan Art Steinmetz (leaflet )
perpustakaan (leafpop)
perpustakaan (purrr)
cv_data_for_plot <- coronavirus%>%
# dplyr :: filter (negara == "Indonesia")%>%
dplyr :: filter (kasing> 0)%>%
dplyr :: group_by (negara, provinsi, lat, panjang, ketik)%>%
dplyr :: merangkum (case = jumlah (
kasing ))%>% dplyr :: bermutasi (log_cases = 2 * log (kasing))%>%
dplyr :: ungroup ()
cv_data_for_plot.split <- cv_data_for_plot%>% split (cv_data_for_plot $ type)
pal <- colorFactor (c ("oranye", "merah", "hijau"), domain = c ("dikonfirmasi", "kematian", "pulih"))
map_object <- leaflet ()%>% addProviderTiles (penyedia $ Stamen .Toner)
names (cv_data_for_plot.split)%>%
purrr :: walk (fungsi (df) {
map_object << - map_object%>%
addCircleMarkers (
data = cv_data_for_plot.split [[df]],
lng = ~ panjang, lat = ~ lat,
# label = ~ as.character (kasing),
warna = ~ 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", "case", "country", "country")
),
grup = df,
# clusterOptions = markerClusterOptions (removeOutsideVisibleBounds = F),
labelOptions = labelOptions (
noHide = F,
direction = "auto"
)
)
})
map_object%>%
addLayersControl (
overlayGroups = names (cv_data_for_plot.split),
options = layersControlOptions (diciutkan = FALSE)
)
`` `Tentang
====================== =============================================== * Dasbor Coronavirus: kasus Indonesia ** Ini [dasbor Coronavirus: kasus Indonesia] ( https://www.antoinesoetewey.com/files/coronavirus-dashboard.html ) memberikan ikhtisar 2019 Novel Coronavirus COVID- 19 (2019-nCoV) epidemi untuk Indonesia. Dasbor ini dibangun dengan R menggunakan kerangka kerja Makrdown R dan diadaptasi dari [dasbor] ini ( https://ramikrispin.github.io/coronavirus_dashboard/){target= "_blank"} oleh Rami Krispin.
**Kode**
Kode di balik dasbor ini tersedia di [GitHub] ( https://github.com/AntoineSoetewey/coronavirus_dashboard){target= "_blank"}.
** Data ** Data
input untuk dasbor ini adalah dataset yang tersedia dari [`{coronavirus}`] ( https://github.com/RamiKrispin/coronavirus){target= "_blank"} paket R. Pastikan untuk mengunduh versi pengembangan paket untuk mendapatkan data terbaru:
`` `
install.packages (" devtools ")
devtools :: install_github (" RamiKrispin / coronavirus ")
` ``
Data dan dasbor di-refresh setiap hari dasar.
Data mentah diambil dari Pusat Coronavirus [repositori] Universitas Johns Hopkins untuk Sains dan Teknik Sistem (JHU CCSE) (https://github.com/RamiKrispin/coronavirus-csv){target= "_blank"}.
** Informasi dan kontak **
Informasi lebih lanjut tentang dasbor ini dan cara mereplikasi untuk negara Anda sendiri dapat ditemukan di [artikel] ini ( https://www.statsandr.com/blog/how-to-create-a- simple-coronavirus-dashboard-specific-to-your-in-r / ).
Untuk pertanyaan atau tanggapan, Anda dapat [menghubungi saya] ( https://www.statsandr.com/contact/ ).
** Perbarui **
Data dalam format `r (maks (coronavirus $ date),"% A% B% d,% Y ")` dan dasbor telah diperbarui pada format `r (Sys.time () , "% A% B% d,% Y") `.
Situs

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Reza Hartono

Reza Hartono

More from Medium

​​🤝 S-Wallet values 🤝

Daisies

The Usage of CHACHA TOKEN 1.

yumetees.com