Visualisasi Perbandingan Corona Virus di Empat Negara

install.packages ("plotly") 
install.packages ("tidyr")
install.packages ("magrittr")
perpustakaan (plotly)
perpustakaan (tidyr)
perpustakaan (magrittr)
install.packages (c ("devtools", "flexdashboard", "leaflet", "leafpop")) 
perpustakaan (devtools)
perpustakaan (flexdashboard)
perpustakaan (leaflet)
perpustakaan (leaflet) perpustakaan (leafpop)
devtools :: install_github ("RamiKrispin / coronavirus") 
perpustakaan (coronavirus)
search () 
ls (2)
update_dataset () 
Lihat (coronavirus)
str (coronavirus)
$ coronavirus negara
df <- coronavirus%>% 
dplyr :: filter (negara == "Indonesia")%>%
dplyr :: group_by (negara, jenis)%>%
dplyr :: merangkum (jumlah = jumlah (kasus))
df
df_harian <- coronavirus%>% 
dplyr :: filter (negara == "Indonesia")%>%
dplyr :: filter (date> = "2020-03-01")%>%
dplyr :: group_by (tanggal, jenis) %>%
dplyr :: summarize (total = jumlah (case, na.rm = TRUE))%>%
tidyr :: pivot_wider (
names_from = type,
values_from = total
)%>%
dplyr :: atur (tanggal)%>%
dplyr :: ungroup ()%>%
dplyr :: bermutasi (aktif = dikonfirmasi - kematian)%>%
dplyr :: bermutasi (
dikonfirmasi_cum = cumsum (dikonfirmasi),
death_cum = cumsum (kematian),
active_cum = cumsum (aktif)
)
df_harian

confirm_color <- "purple" active_color <- "# 1f77b4"
recovered_color <- "forestgreen"
death_color <- "red"
plotly :: plot_ly (data = df_harian)%>%
plotly :: add_trace (
x = ~ tanggal,
# y = ~ active_cum,
y = ~ confirm_cum,
type = "scatter",
mode = "lines + spiders",
name = "Confirmed",
line = daftar (warna = active_color),
marker = daftar (color = active_color)
)%>%
plotly :: add_trace (
x = ~ tanggal,
y = ~ death_cum,
ketik = " sebar ",
mode = "garis + spidol",
nama = "Kematian",
line = daftar (warna = death_color),
marker = list (color = death_color)
)%>%
plotly :: add_annotations (
x = as.Date ("2020-03-02-02"),
y = 1,
teks = tempel ("Kasus Pertama"),
xref = "x ",
yref =" y ",
panah = 5,
panah = 3 , panah
ukuran = 1,
showarrow = BENAR,
kapak = -10,
ay = -80
)%>%
plotly :: add_annotations (
x = as.Date (" 2020) -03-11 "),
y = 3,
text = paste (" Kematian Pertama "),
xref =" x ",
yref =" y ",
panah = 5,
panah = 3,
panahukuran = 1,
showarrow = BENAR,
kapak = -90,
ay = -90
)%>%
plotly :: layout (
title = "",
yaxis = daftar (title = "Jumlah kumulatif banyak kasus"),
xaxis = daftar (judul = "Tanggal"),
legenda = daftar (x = 0,1 , y = 0,9),
hovermode = "bandingkan"
)
konfirmasi_harian <- coronavirus%>% 
dplyr :: filter (ketik == "dikonfirmasi")%>%
dplyr :: filter (date> = "2020-02-25")%>%
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)
konfirmasi_harian%>%
plotly :: plot_ly ()%>%
plotly :: add_trace (
x = ~ date,
y = ~ Indonesia,
ketik = "scatter",
mode = "lines + spiders",
name = "Indonesia"
) %>%
plotly :: add_trace (
x = ~ date,
y = ~ Brunei,
type = "sebar",
mode = "lines + spiders",
name = "Brunei"
)%>%
plotly :: add_trace (
x = ~ date,
y = ~ Filipina,
ketik = "scatter",
mode = "lines + spiders",
name = "Philippines "
)%>%
plotly :: add_trace (
x = ~ tanggal,
y = ~ Malaysia,
ketik =" scatter ",
mode =" lines + spiders ",
name =" Malaysia "
)%>%
plotly :: tata letak (
judul = "",
legenda = daftar (x = 0,1, y = 0,9),
yaxis = daftar (judul = "Jumlah kasus positif baru"),
xaxis = daftar (judul = "Tanggal"),
hovermode = "bandingkan",
margin = daftar (
b = 10,
t = 10,
path = 2
)
)
kematian_harian <- coronavirus%>% 
dplyr :: filter (ketik == "death")%>%
dplyr :: filter (date> = "2020-02-25")%>%
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)
kematian_harian%>%
plotly :: plot_ly ()%>%
plotly :: add_trace (
x = ~ date,
y = ~ Indonesia,
ketik = "scatter",
mode = "lines + spiders",
name = "Indonesia"
) %>%
plotly :: add_trace (
x = ~ date,
y = ~ Brunei,
type = "sebar",
mode = "lines + spiders",
name = "Brunei"
)%>%
plotly :: add_trace (
x = ~ date,
y = ~ Filipina,
ketik = "scatter",
mode = "lines + spiders",
name = "Philippines "
)%>%
plotly :: add_trace (
x = ~ tanggal,
y = ~ Malaysia,
ketik =" scatter ",
mode =" lines + spiders ",
name =" Malaysia "
)%>%
plotly :: tata letak (
judul = "",
legenda = daftar (x = 0,1, y = 0,9),
yaxis = daftar (judul = "Jumlah kematian baru"),
xaxis = daftar (judul = "Tanggal"),
hovermode = "bandingkan",
margin = daftar (
b = 10,
t = 10,
path = 2
)
)

--

--

--

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

CS 373 Spring 2022: Bruce Nguyen

All you need to know about Poriverse!

Here is Why You Shouldn’t Show off Your Dreams and Goals in Public

Cinderella