bersatulawancovid <- c("cuci tangan", "pakai masker", "jaga jarak")
bersatulawancovid
## [1] "cuci tangan" "pakai masker" "jaga jarak"
Rekapitulasi data COVID-19 Indonesia tersedia dalam API publik yang beralamat di https://data.covid19.go.id/public/api/update.json.maka kita akan langsung mengambil data pada laman website tersebut.
library(httr)
## Warning: package 'httr' was built under R version 4.0.4
resp <- GET ("https://data.covid19.go.id/public/api/update.json")
library(httr)
resp <- GET("https://data.covid19.go.id/public/api/update.json")
status_code (resp)
## [1] 200
#Status Code - 2
dan sekarang kita akan mencoba mengetahui status permintaan dengan cara mengakses elemen dari resp. Status code tersebut tersedia dengan nama status_code dan dapat diakses dengan menggunakan operator $ pada obyek resp.
library(httr)
resp <- GET("https://data.covid19.go.id/public/api/update.json")
resp$status_code
## [1] 200
identical(resp$status_code, status_code(resp))
## [1] TRUE
#Mengekstrak isi Respon
library(httr)
resp <- GET("https://data.covid19.go.id/public/api/update.json")
cov_id_raw <- content(resp, as = "parsed", simplifyVector = TRUE)
#Mengekstrak isi Respon - Pt 2
length(cov_id_raw)
## [1] 2
names(cov_id_raw)
## [1] "data" "update"
cov_id_update <- cov_id_raw$update
#Analisa Data
sekarang kita akan menganalisa data diantaranya :
Kapan tanggal pembaharuan data penambahan kasus? Berapa jumlah penambahan kasus sembuh? Berapa jumlah penambahan kasus meninggal? Berapa jumlah total kasus positif hingga saat ini? Berapa jumlah total kasus meninggal hingga saat ini?
lapply(cov_id_update, names)
## $penambahan
## [1] "jumlah_positif" "jumlah_meninggal" "jumlah_sembuh" "jumlah_dirawat"
## [5] "tanggal" "created"
##
## $harian
## [1] "key_as_string" "key" "doc_count"
## [4] "jumlah_meninggal" "jumlah_sembuh" "jumlah_positif"
## [7] "jumlah_dirawat" "jumlah_positif_kum" "jumlah_sembuh_kum"
## [10] "jumlah_meninggal_kum" "jumlah_dirawat_kum"
##
## $total
## [1] "jumlah_positif" "jumlah_dirawat" "jumlah_sembuh" "jumlah_meninggal"
cov_id_update$penambahan$tanggal
## [1] "2021-05-29"
cov_id_update$penambahan$jumlah_sembuh
## [1] 5417
cov_id_update$penambahan$jumlah_meninggal
## [1] 162
cov_id_update$total$jumlah_positif
## [1] 1809926
cov_id_update$total$jumlah_meninggal
## [1] 50262
#COVID-19 Di Sekitar Jawa Timur, Apa Kabar ?
sebelum melangkah lebih jauh mari kita jawab pertanyaan - pertanyaan berikut :
Berapa jumlah total kasus COVID-19 di Jawa Timur? Berapa persentase kematian akibat COVID-19 di Jawa Timur? Berapa persentase tingkat kesembuhan dari COVID-19 di Jawa Timur?
library(httr)
resp_jatim <- GET("https://data.covid19.go.id/public/api/prov_detail_JAWA_TIMUR.json")
cov_jatim_raw <- content(resp_jatim, as = "parsed", simplifyVector = TRUE)
names(cov_jatim_raw)
## [1] "last_date" "provinsi" "kasus_total"
## [4] "kasus_tanpa_tgl" "kasus_dengan_tgl" "meninggal_persen"
## [7] "meninggal_tanpa_tgl" "meninggal_dengan_tgl" "sembuh_persen"
## [10] "sembuh_tanpa_tgl" "sembuh_dengan_tgl" "list_perkembangan"
## [13] "data"
cov_jatim_raw$kasus_total
## [1] 154315
cov_jatim_raw$meninggal_persen
## [1] 7.3175
cov_jatim_raw$sembuh_persen
## [1] 91.31193
#Memperoleh Informasi yang Lebih Lengkap
Informasi umum mengenai COVID-19 di Jawa Timur telah Anda dapatkan. Namun informasi akan lebih lengkap jika Anda memiliki data perkembangan COVID-19 dari waktu ke waktu, apakah Anda setuju?
cov_jatim <- cov_jatim_raw$list_perkembangan
str(cov_jatim)
## 'data.frame': 508 obs. of 9 variables:
## $ tanggal : num 1.58e+12 1.58e+12 1.58e+12 1.58e+12 1.58e+12 ...
## $ KASUS : int 9 0 0 0 0 0 0 0 0 0 ...
## $ MENINGGAL : int 3 1 1 3 3 0 0 0 0 0 ...
## $ SEMBUH : int 1 23 14 8 1 0 0 0 0 4 ...
## $ DIRAWAT_OR_ISOLASI : int 5 -24 -15 -11 -4 0 0 0 0 -4 ...
## $ AKUMULASI_KASUS : int 9 9 9 9 9 9 9 9 9 9 ...
## $ AKUMULASI_SEMBUH : int 1 24 38 46 47 47 47 47 47 51 ...
## $ AKUMULASI_MENINGGAL : int 3 4 5 8 11 11 11 11 11 11 ...
## $ AKUMULASI_DIRAWAT_OR_ISOLASI: int 5 -19 -34 -45 -49 -49 -49 -49 -49 -53 ...
head(cov_jatim)
## tanggal KASUS MENINGGAL SEMBUH DIRAWAT_OR_ISOLASI AKUMULASI_KASUS
## 1 1.578442e+12 9 3 1 5 9
## 2 1.578528e+12 0 1 23 -24 9
## 3 1.578614e+12 0 1 14 -15 9
## 4 1.578701e+12 0 3 8 -11 9
## 5 1.578787e+12 0 3 1 -4 9
## 6 1.578874e+12 0 0 0 0 9
## AKUMULASI_SEMBUH AKUMULASI_MENINGGAL AKUMULASI_DIRAWAT_OR_ISOLASI
## 1 1 3 5
## 2 24 4 -19
## 3 38 5 -34
## 4 46 8 -45
## 5 47 11 -49
## 6 47 11 -49
Setelah mengekstrak dan mengamati cov_jatim, Anda menemukan beberapa kejanggalan pada data tersebut. Diantaranya adalah kejanggalan data pada kolom tanggal dan format penulisan kolom yang tidak konsisten. Sekarang Anda akan mencoba melakukan beberapa tahapan untuk menjinakan data tersebut sehingga dapat diolah dan dianalisis dengan lebih mudah. sebagai berikut :
library(dplyr)
## Warning: package 'dplyr' was built under R version 4.0.5
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
new_cov_jatim <-
cov_jatim %>%
select(-contains("DIRAWAT_OR_ISOLASI")) %>%
select(-starts_with("AKUMULASI")) %>%
rename(
kasus_baru = KASUS,
meninggal = MENINGGAL,
sembuh = SEMBUH
) %>%
mutate(
tanggal = as.POSIXct(tanggal / 1000, origin = "1970-01-01"),
tanggal = as.Date(tanggal)
)
str(new_cov_jatim)
## 'data.frame': 508 obs. of 4 variables:
## $ tanggal : Date, format: "2020-01-08" "2020-01-09" ...
## $ kasus_baru: int 9 0 0 0 0 0 0 0 0 0 ...
## $ meninggal : int 3 1 1 3 3 0 0 0 0 0 ...
## $ sembuh : int 1 23 14 8 1 0 0 0 0 4 ...
#Menunjukkan Melalui Gambar
selanjutnya komponen utama untuk membuat visualisasi antara lain adalah tabel data, kolom data, serta bentuk geometri untuk mempresentasikan data. Sebagai contoh untuk membuat scatter-plot yang diperlukan adalah bentuk geometri titik (geom_col()), line-chart memerlukan geometri garis (geom_line()), sedangkan bar-chart memerlukan bentuk geometri batang atau kolom (geom_bar() atau geom_col()).
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.0.4
library(hrbrthemes)
## Warning: package 'hrbrthemes' was built under R version 4.0.5
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
## Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
## if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
ggplot(new_cov_jatim, aes(x = tanggal, y = kasus_baru)) +
geom_col()
#Menunjukkan Melalui Gambar - Pt 2
Anda telah berhasil membuat bar-chart yang diminta. Namun grafik tersebut belum memiliki informasi yang jelas serta cenderung membosankan untuk dilihat. Sekarang silakan buat kembali grafik tersebut dengan menggunakan baris kode yang telah dimodifikasi berikut:
library(ggplot2)
library(hrbrthemes)
ggplot(new_cov_jatim, aes(tanggal, kasus_baru)) +
geom_col(fill = "salmon") +
labs(
x = NULL,
y = "Jumlah kasus",
title = "Kasus Harian Positif COVID-19 di Jawa Timur",
subtitle = "Terjadi pelonjakan kasus di awal bulan Januari akibat klaster penyebaran",
caption = "Sumber data: covid.19.go.id"
) +
theme_ipsum(
base_size = 13,
plot_title_size = 21,
grid = "Y",
ticks = TRUE
) +
theme(plot.title.position = "plot")
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
#Grafik untuk Kasus Sembuh
library(ggplot2)
library(hrbrthemes)
ggplot(new_cov_jatim, aes(tanggal, sembuh)) +
geom_col(fill = "olivedrab2") +
labs(
x = NULL,
y = "Jumlah kasus",
title = "Kasus Harian Sembuh Dari COVID-19 di Jawa Timur",
caption = "Sumber data: covid.19.go.id"
) +
theme_ipsum(
base_size = 13,
plot_title_size = 21,
grid = "Y",
ticks = TRUE
) +
theme(plot.title.position = "plot")
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
#Grafik untuk Kasus Meninggal
library(ggplot2)
library(hrbrthemes)
ggplot(new_cov_jatim, aes(tanggal, meninggal)) +
geom_col(fill = "darkslategray4") +
labs(
x = NULL,
y = "Jumlah kasus",
title = "Kasus Harian Meninggal Akibat COVID-19 di Jawa Timur",
caption = "Sumber data: covid.19.go.id"
) +
theme_ipsum(
base_size = 13,
plot_title_size = 21,
grid = "Y",
ticks = TRUE
) +
theme(plot.title.position = "plot")
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
#Apakah Pekan ini Lebih Baik?
Setelah mengamati grafik perkembangan kasus Anda menyadari bahwa terjadi fluktuasi pertambahan kasus harian. Dilandasi hal tersebut Anda kemudian ingin mencoba mengamati bagaimana perkembangan kasus dalam rentang waktu pekanan. Bagaimanakah caranya? Anda dapat dengan mudah bekerja dengan data tanggal apabila menggunakan paket lubridate. Adapun yang akan digunakan untuk mengekstrak informasi pekan dalam satu tahun adalah fungsi week().sebagai berikut :
library(dplyr)
library(lubridate)
## Warning: package 'lubridate' was built under R version 4.0.4
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
cov_jatim_pekanan <- new_cov_jatim %>%
count(
tahun = year(tanggal),
pekan_ke = week(tanggal),
wt = kasus_baru,
name = "jumlah"
)
glimpse(cov_jatim_pekanan)
## Rows: 74
## Columns: 3
## $ tahun <dbl> 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2~
## $ pekan_ke <dbl> 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1~
## $ jumlah <int> 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 59, 110, 295, 140, 247, 316~
#Menjawab Pertanyaan
Pertanyaan baru muncul di benak Anda setelah melakukan inspeksi terhadap data cov_jatim_pekanan tersebut: “Apakah pekan ini lebih baik dari pekan kemarin?”.
Demi menjawab hal tersebut Anda melakukan kalkulasi sederhana dengan tahapan berikut:
Membuat kolom baru yang berisi jumlah kasus baru dalam satu pekan sebelumnya. Kolom ini diberi nama “jumlah_pekanlalu”. Mengganti nilai NA pada kolom “jumlah_pekanlalu” dengan nilai 0 Melakukan komparasi antara kolom “jumlah” dengan kolom “jumlah_pekanlalu”. Hasil komparasi ini disimpan dalam kolom baru dengan nama “lebih_baik”, isinya adalah TRUE apabila jumlah kasus baru pekan ini lebih rendah dibandingkan jumlah kasus pekan lalu
library(dplyr)
cov_jatim_pekanan <-
cov_jatim_pekanan %>%
mutate(
jumlah_pekanlalu = dplyr::lag(jumlah, 1),
jumlah_pekanlalu = ifelse(is.na(jumlah_pekanlalu), 0, jumlah_pekanlalu),
lebih_baik = jumlah < jumlah_pekanlalu
)
glimpse(cov_jatim_pekanan)
## Rows: 74
## Columns: 5
## $ tahun <dbl> 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020,~
## $ pekan_ke <dbl> 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 1~
## $ jumlah <int> 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 59, 110, 295, 140, ~
## $ jumlah_pekanlalu <dbl> 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 46, 59, 110, 295, 14~
## $ lebih_baik <lgl> FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE~
#Membuat Bar Chart
library(ggplot2)
library(hrbrthemes)
ggplot(cov_jatim_pekanan, aes(pekan_ke, jumlah, fill = lebih_baik)) +
geom_col(show.legend = FALSE) +
scale_x_continuous(breaks = 9:29, expand = c(0, 0)) +
scale_fill_manual(values = c("TRUE" = "seagreen3", "FALSE" = "salmon")) +
labs(
x = NULL,
y = "Jumlah kasus",
title = "Kasus Pekanan Positif COVID-19 di Jawa Timur",
subtitle = "Kolom hijau menunjukan penambahan kasus baru lebih sedikit dibandingkan satu pekan sebelumnya",
caption = "Sumber data: covid.19.go.id"
) +
theme_ipsum(
base_size = 13,
plot_title_size = 21,
grid = "Y",
ticks = TRUE
) +
theme(plot.title.position = "plot")
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
#Pola dan Dinamika
Ada yang akhirnya sembuh, namun tak sedikit pula yang meninggal akibat COVID-19. Sementara itu penambahan kasus baru terus terjadi di masyarakat. Hal ini mungkin memicu pertanyaan lain di diri Anda: “Hingga saat ini ada berapa kasus yang masih aktif?”. Aktif dalam artian sedang dalam perawatan atau isolasi.
library(dplyr)
cov_jatim_akumulasi <-
new_cov_jatim %>%
transmute(
tanggal,
akumulasi_aktif = cumsum(kasus_baru) - cumsum(sembuh) - cumsum(meninggal),
akumulasi_sembuh = cumsum(sembuh),
akumulasi_meninggal = cumsum(meninggal)
)
tail(cov_jatim_akumulasi)
## tanggal akumulasi_aktif akumulasi_sembuh akumulasi_meninggal
## 503 2021-05-24 1933 140003 11186
## 504 2021-05-25 1945 140186 11208
## 505 2021-05-26 2056 140312 11228
## 506 2021-05-27 2068 140494 11252
## 507 2021-05-28 2089 140700 11271
## 508 2021-05-29 2122 140903 11290
#Membuat Line Chart
library(ggplot2)
ggplot(data = cov_jatim_akumulasi, aes(x = tanggal, y = akumulasi_aktif)) +
geom_line()
Kesimpulan apa yang dapat Anda tarik dari grafik tersebut?
#Kabar Buruk dan Kabar Baik
library(ggplot2)
ggplot(data = cov_jatim_akumulasi, aes(x = tanggal)) +
geom_line(aes(x = tanggal, y = akumulasi_aktif), color = "blue") +
geom_line(aes(x = tanggal, y = akumulasi_sembuh), color = "green") +
geom_line(aes(x = tanggal, y = akumulasi_meninggal), color = "red")
#Transformasi Data
library(dplyr)
library(tidyr)
## Warning: package 'tidyr' was built under R version 4.0.4
dim(cov_jatim_akumulasi)
## [1] 508 4
cov_jatim_akumulasi_pivot <-
cov_jatim_akumulasi %>%
gather(
key = "kategori",
value = "jumlah",
-tanggal
) %>%
mutate(
kategori = sub(pattern = "akumulasi_", replacement = "", kategori)
)
dim(cov_jatim_akumulasi_pivot)
## [1] 1524 3
glimpse(cov_jatim_akumulasi_pivot)
## Rows: 1,524
## Columns: 3
## $ tanggal <date> 2020-01-08, 2020-01-09, 2020-01-10, 2020-01-11, 2020-01-12, ~
## $ kategori <chr> "aktif", "aktif", "aktif", "aktif", "aktif", "aktif", "aktif"~
## $ jumlah <int> 5, -19, -34, -45, -49, -49, -49, -49, -49, -53, -61, -61, -61~
cov_jatim_akumulasi_pivot <-
cov_jatim_akumulasi %>%
pivot_longer(
cols = -tanggal,
names_to = "kategori",
names_prefix = "akumulasi_",
values_to = "jumlah"
)
dim(cov_jatim_akumulasi_pivot)
## [1] 1524 3
glimpse(cov_jatim_akumulasi_pivot)
## Rows: 1,524
## Columns: 3
## $ tanggal <date> 2020-01-08, 2020-01-08, 2020-01-08, 2020-01-09, 2020-01-09, ~
## $ kategori <chr> "aktif", "sembuh", "meninggal", "aktif", "sembuh", "meninggal~
## $ jumlah <int> 5, 1, 3, -19, 24, 4, -34, 38, 5, -45, 46, 8, -49, 47, 11, -49~
#Dinamika Kasus Covid di Jawa Timur
library(ggplot2)
library(hrbrthemes)
ggplot(cov_jatim_akumulasi_pivot, aes(tanggal, jumlah, colour = (kategori))) +
geom_line(size = 0.9) +
scale_y_continuous(sec.axis = dup_axis(name = NULL)) +
scale_colour_manual(
values = c(
"aktif" = "salmon",
"meninggal" = "darkslategray4",
"sembuh" = "olivedrab2"
),
labels = c("Aktif", "Meninggal", "Sembuh")
) +
labs(
x = NULL,
y = "Jumlah kasus akumulasi",
colour = NULL,
title = "Dinamika Kasus COVID-19 di Jawa Timur",
caption = "Sumber data: covid.19.go.id"
) +
theme_ipsum(
base_size = 13,
plot_title_size = 21,
grid = "Y",
ticks = TRUE
) +
theme(
plot.title = element_text(hjust = 0.5),
legend.position = "top"
)
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
#Sekian dan Terimakasih