Prediksi dan Analisis Harga Bahan Baku Pangan
Indonesia merupakan salah satu negara terbesar di Asia Tenggara yang memproduksi berbagai macam komoditas bahan pangan. Komoditas sayuran mempunyai kontribusi besar terhadap produksi hortikultura Indonesia dan memberikan pendapatan bagi negara. Dengan berbagai macam jenis makanan di Indonesia, komoditas sayuran yang di produksi di tanah air sebagian besar di peruntukan untuk konsumsi rumah tangga. Di antara bebagai macam sayuran yang di produksi, ada 6 sayuran yang memiliki potensi untuk terus dikembangkan yaitu:
**data produksi tahun 2021 saat ini belum di publish oleh Badan Pusat Statistik
Tingkat konsumsi sayuran khusus nya rumah tangga meningkat di masa pandemi Covid-19 karena banyak masyarakat mulai sadar akan pentingnya konsumsi sayuran untuk mendukung pola hidup yang lebih sehat. Di daerah ibu kota Indonesia, DKI Jakarta, rata-rata konsumsi sayuran di tahun 2021 mencapai 1.500 ton per hari sumber. Meningkat nya tingkat konsumsi warga Jakarta menyebabkan pemerintah harus menambah pasokan sayur di daerah tersebut, karena supply sayuran yang di produksi di Jakarta tidak cukup untuk memenuhi kebutuhan daerah tesebut, sehingga sebagian besar masih harus di datangkan dari daerah lain. Tingkat kebutuhan sayuran yang meningkat, jika tidak di barengi dengan peningkatan produksi dapat mengakibatkan fluktuasi tinggi pada harga sayuran.
**Fluktuasi harga bawang merah di awal pandemi Covid-19
Pada bulanan Oktober 2020, harga bawang putih sempat melonjak disebabkan kelangkaan pasokan bawang putih di pasaran. Berdasarkan hal tersebut Kementrian Perdagangan melakukan upaya untuk menekan harga bawang putih yang naik dengan melakukan impor sumber.
**Harga bawang putih Oktober 2020
Ada beberapa faktor yang menyebabkan kenaikan harga sayur seperti faktor cuaca di daerah pertanian yang dapat menyebabkan gagal panen, faktor naik turunnya inflasi di suatu daerah hingga permainan tengkulak / distributor yang menahan distribusi produk demi menaikan harga pasar. Peningkatan harga sayuran dapat menyebabkan konsumen, khususnya sektor rumah tangga dan pelaku bisnis makanan harus menyesuaikan budget belanja mereka. Terlebih bila harga meningkat cukup signifikan, menyebabkan biaya produksi makanan untuk pelaku bisnis makanan membengkak, sehingga seringkali pelaku bisnis harus menghitung ulang harga jual mereka untuk menghindari kerugian.
Membuat model prediksi & rekomendasi untuk harga bahan baku komoditas pasar seperti bawang, cabai, kentang dll di daerah DKI Jakarta. Model prediksi nantinya diharapkan dapat membantu User untuk memprediksi harga bahan baku kedepannya, sehingga dapat membantu User seperti UMKM yang ingin membuat budgeting. Untuk model rekomendasi di tujukan untuk User yang ingin mendapatkan “best price” atas suatu komoditas pada tanggal tertentu, di suatu pasar berdasarkan lokasi tempat tinggal.
library(tidyverse) #data wrangling and visualization
library(leaflet) #map visualization
library(glue) #visualization label
library(plotly) #Interactive Visualization
library(forecast) # time series library
library(tseries) # for adf.test
library(MLmetrics) # calculate error
theme_set(theme_minimal())
Dalam melakukan prediksi dan analisis harga bahan baku kita akan menggunakan 2 data yaitu:
market
yang berisi informasi harga bahan baku per lokasi pasar di daerah DKI Jakarta dari tahun 2020 - 2021.city
yang berisi informasi harga bahan baku per lokasi kota bagian di daerah DKI Jakarta dari tahun 2020 - 2021.Inflation
yang berisi informasi inflasi per bulan dari situs BEIKedua data market
dan city
di peroleh secara manual per bulan melalui situs Info Pangan. Untuk informasi latitude
dan longitude
pada data market diperoleh dari google map.
<- readxl::read_xlsx("pasar.xlsx")
market head(market)
Berdasarkan observasi pada 6 data pertama, kita dapat melihat bahwa data market
memiliki 42 kolom yang berisi:
market
: Nama pasarcity
: Lokasi pasar berdasarkan kota bagian di DKI Jakartalatitude
& longitude
: Titik koordinat lokasidate
: tanggal per hari#to check unique value
unique(market$market)
## [1] "Pasar Anyer Bahari" "Pasar Baru Metro Atom"
## [3] "Pasar Cempaka Putih" "Pasar Cijantung"
## [5] "Pasar Cipete" "Pasar Ciplak"
## [7] "Pasar Glodok" "Pasar Gondangdia"
## [9] "Pasar Grogol" "Pasar Induk Kramat Jati"
## [11] "Pasar Jatinegara" "Pasar Jembatan Lima"
## [13] "Pasar Jembatan Merah" "Pasar Johar Baru"
## [15] "Pasar Kalibaru" "Pasar Kalideres"
## [17] "Pasar Kebayoran Lama" "Pasar Kelapa Gading"
## [19] "Pasar Koja Baru" "Pasar Kramat Jati"
## [21] "Pasar Lenteng Agung" "Pasar Mampang Prapatan"
## [23] "Pasar Mayestik" "Pasar Pademangan Timur"
## [25] "Pasar Pal Merah" "Pasar Cengkareng"
## [27] "Pasar Minggu" "Pasar Petojo Ilir"
## [29] "Pasar Senen Blok III - VI" "Pasar Paseban"
## [31] "Pasar Perumnas Klender" "Pasar Pesanggrahan"
## [33] "Pasar Pluit" "Pasar Pondok Labu"
## [35] "Pasar Pos Pengumben" "Pasar Pramuka"
## [37] "Pasar Pulo Gadung" "Pasar Rawa Badak"
## [39] "Pasar Rumput" "Pasar Sunter Podomoro"
## [41] "Pasar Tanah Abang Blok A-G" "Pasar Tebet Barat"
## [43] "Pasar Tomang Barat"
Pada data market
, terdapat kurang lebih 43 lokasi pasar dan 5 kota bagian di DKI Jakarta.
#to check unique value
unique(market$city)
## [1] "Jakarta Utara" "Jakarta Pusat" "Jakarta Timur" "Jakarta Selatan"
## [5] "Jakarta Barat"
#to check date range
range(market$date)
## [1] "2020-01-01 UTC" "2021-12-31 UTC"
#to check NA value from each columns
colSums(is.na(market))
## market city
## 0 0
## latitude longitude
## 0 0
## date Beras IR I (IR 64)
## 0 4686
## Beras IR II (IR 64) Ramos Beras IR III (IR 64)
## 4865 5704
## Beras Muncul I Beras IR 42/Pera
## 11257 3911
## Beras Setra I/Premium Minyak Goreng (Kuning/Curah)
## 6928 851
## Cabe Merah Keriting Cabe Merah Besar (TW)
## 0 1317
## Cabe Rawit Merah Cabe Rawit Hijau
## 0 0
## Bawang Merah Bawang Putih
## 0 0
## Daging Sapi Has (Paha Belakang) Daging Sapi Murni (Semur)
## 3717 1128
## Ayam Broiler/Ras Telur Ayam Ras
## 2955 731
## Gula Pasir Tepung Terigu
## 731 731
## Garam Dapur Kentang (sedang)
## 1462 0
## Tomat Buah Kelapa Kupas
## 0 2224
## Semangka Jeruk Medan
## 7999 8153
## Daging Kambing Daging Babi Berlemak
## 12264 17810
## Ikan Bandeng (sedang) Ikan Mas
## 4621 5418
## Ikan Lele Gas Elpiji 3kg
## 5400 17142
## Susu Bubuk Bendera 400gr Susu Bubuk Dancow 400gr
## 23456 20041
## Susu Kental Bendera 200gr Susu Kental Enak 200gr
## 761 3844
## Margarin Blueband Cup Margarin Blueband Sachet
## 3341 930
Berdasarkan pengecekan kolom NA dari data market
, kita dapat melihat ada banyak sekali kolom yang tidak memiliki informasi harga. Hal ini dikarenakan ada beberapa pasar yang tidak menjual keseluruhan 37 bahan baku, sehingga tidak ada informasi harga yang ditampilkan. Oleh karena itu, kita hanya akan melakukan prediksi dan analisis harga bahan baku pada kolom yang tidak memiliki NA value yaitu:
Cabe Merah Keriting
Cabe Rawit Merah
Cabe Rawit Hijau
Bawang Merah
Bawang Putih
Kentang (sedang)
Tomat Buah
Sekarang kita akan melakukan cleansing data dengan merubah format pada kolom market
, city
& date
dan melakukan select
pada kolom yang tidak memiliki NA.
#cleansing data
<-
market_clean %>%
market select(market, city, latitude, longitude, date, "Cabe Merah Keriting", "Cabe Rawit Merah", "Cabe Rawit Hijau", "Bawang Merah", "Bawang Putih", "Kentang (sedang)", "Tomat Buah") %>%
arrange(date) %>%
gather(key = commodity, value = price, "Cabe Merah Keriting":"Tomat Buah") %>%
mutate(market = as.factor(market),
city = as.factor(city),
date = as.Date(date),
commodity = as.factor(commodity))
head(market_clean)
Data yang digunakan untuk periode tahun 2020 - 2021 di ambil pada bulan Januari 2022, agar hasil prediksi bisa lebih up to date sekarang kita akan menambahkan data untuk tahun 2022 yang di ambil di bulan Maret 2022. Dikarenakan kita sudah menentukan commodity
yang akan kita prediksi, kita dapat mengambil data dari website Info Pangan berdasarkan komoditas saja. Format tabel apabila kita mengambil data per komoditas sedikit berbeda dengan data sebelumnya market
, jadi kita harus melakukan data wrangling terlebih dahulu untuk menyamakan format sebelum di gabung.
<- readxl::read_xlsx("pasar 2022.xlsx")
market2 head(market2)
<-
market2 %>%
market2 gather(key = market, value = price, "Pasar Induk Kramat Jati":"Pasar Anyer Bahari") %>%
mutate_if(is.character, as.factor) %>%
mutate(date = as.Date(date))
<-
location %>%
market_clean distinct(city, market, latitude, longitude)
<-
market2_comb merge(location, market2, by = "market"))
(
head(market2_comb)
<-
market_clean rbind(market_clean, market2_comb)
<- readxl::read_xlsx("kota.xlsx")
city head(city)
Berdasarkan observasi pada 6 data pertama, kita dapat melihat bahwa data city
memiliki 42 kolom yang berisi:
market
: Lokasi pasar berdasarkan kota bagian DKI Jakartadate
: tanggal per hari#check unique value
unique(city$market)
## [1] "Jakarta Barat" "Jakarta Pusat" "Jakarta Selatan" "Jakarta Timur"
## [5] "Jakarta Utara"
Pada data city
terdapat 5 kota bagian di DKI Jakarta.
#to check date range
range(city$date)
## [1] "2020-01-01 UTC" "2022-02-28 UTC"
#to check NA value
colSums(is.na(city))
## market date
## 0 0
## Beras IR I (IR 64) Beras IR II (IR 64) Ramos
## 0 0
## Beras IR III (IR 64) Beras Muncul I
## 0 0
## Beras IR 42/Pera Beras Setra I/Premium
## 0 0
## Minyak Goreng (Kuning/Curah) Cabe Merah Keriting
## 0 0
## Cabe Merah Besar (TW) Cabe Rawit Merah
## 0 0
## Cabe Rawit Hijau Bawang Merah
## 0 0
## Bawang Putih Daging Sapi Has (Paha Belakang)
## 0 0
## Daging Sapi Murni (Semur) Ayam Broiler/Ras
## 0 0
## Telur Ayam Ras Gula Pasir
## 0 0
## Tepung Terigu Garam Dapur
## 0 0
## Kentang (sedang) Tomat Buah
## 0 0
## Kelapa Kupas Semangka
## 0 0
## Jeruk Medan Daging Kambing
## 0 0
## Daging Babi Berlemak Ikan Bandeng (sedang)
## 0 0
## Ikan Mas Ikan Lele
## 0 0
## Gas Elpiji 3kg Susu Bubuk Bendera 400gr
## 0 0
## Susu Bubuk Dancow 400gr Susu Kental Bendera 200gr
## 0 0
## Susu Kental Enak 200gr Margarin Blueband Cup
## 0 0
## Margarin Blueband Sachet
## 0
Data city
tidak memiliki NA Value. Berdasarkan pemilihan kolom yang akan digunakan untuk analisis & prediksi dari data market
, hal yang sama akan di aplikasikan juga untuk data city
. Kita juga akan melakukan perubahan format pada kolom market
& date
.
#Cleansing Data
<-
city_clean %>%
city select(market, date, "Cabe Merah Keriting", "Cabe Rawit Merah", "Cabe Rawit Hijau", "Bawang Merah", "Bawang Putih", "Kentang (sedang)", "Tomat Buah") %>%
gather(key = commodity, value = price, "Cabe Merah Keriting":"Tomat Buah") %>%
mutate(market = as.factor(market),
date = as.Date(date),
commodity = as.factor(commodity)) %>%
arrange(date)
tail(city_clean)
<- readxl::read_xlsx("inflasi.xlsx")
inflation head(inflation)
# Rename inflation column to Inflasi
names(inflation)[3] <- "Inflasi"
<-
inflation %>%
inflation mutate(Inflasi = ifelse(grepl("%", Inflasi),
as.numeric(gsub("%", "", Inflasi)), as.numeric(Inflasi))) %>% # To delete "%" value in Inflasi column
separate(Periode, sep = " ", into = c("Month", "Year")) # to seperate Periode value into Month and Year column
$Month <- plyr::mapvalues(inflation$Month, from = c("Januari", "Februari", "Maret", "Mei", "Juni", "Juli", "Agustus", "Oktober", "Desember"),
inflationto = c("January", "February", "March", "May", "June", "July", "August", "October", "December")) # to translate month into English
# to join column Month and Year
<-
inflation %>%
inflation mutate(Periode = paste(Month, Year, sep = " "),
Inflasi = Inflasi * 100) %>%
select(Periode, Inflasi)
#To create date column in daily format
<-
date %>%
city filter(market == "Jakarta Barat") %>%
select(date) %>%
mutate(Periode = format(date, "%B %Y"))
#Combine inflation rate to each date
<-
inflasi merge(inflation, date, by = "Periode")) %>%
(arrange(date)
head(inflasi)
%>%
market_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Cabe Merah Keriting") %>%
ggplot(aes(x = market, y = mean_price))+
geom_segment( aes(x=reorder(market, mean_price) ,xend=market, y=0, yend=mean_price))+
geom_point(size=3, color="steelblue")+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Average Price by Commodity")+
labs(x = "Market",
y = "Average Price (IDR)", fill = "")+
theme(axis.text = element_text(colour = "navyblue"),
plot.title = element_text(hjust = 0.5))+
facet_wrap(~commodity)
%>%
market_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Cabe Rawit Merah") %>%
ggplot(aes(x = market, y = mean_price))+
geom_segment( aes(x=reorder(market, mean_price) ,xend=market, y=0, yend=mean_price))+
geom_point(size=3, color="steelblue")+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Average Price by Commodity")+
labs(x = "Market",
y = "Average Price (IDR)", fill = "")+
theme(axis.text = element_text(colour = "navyblue"),
plot.title = element_text(hjust = 0.5))+
facet_wrap(~commodity)
%>%
market_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Cabe Rawit Hijau") %>%
ggplot(aes(x = market, y = mean_price))+
geom_segment( aes(x=reorder(market, mean_price) ,xend=market, y=0, yend=mean_price))+
geom_point(size=3, color="steelblue")+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Average Price by Commodity")+
labs(x = "Market",
y = "Average Price (IDR)", fill = "")+
theme(axis.text = element_text(colour = "navyblue"),
plot.title = element_text(hjust = 0.5))+
facet_wrap(~commodity)
%>%
market_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Bawang Merah") %>%
ggplot(aes(x = market, y = mean_price))+
geom_segment( aes(x=reorder(market, mean_price) ,xend=market, y=0, yend=mean_price))+
geom_point(size=3, color="steelblue")+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Average Price by Commodity")+
labs(x = "Market",
y = "Average Price (IDR)", fill = "")+
theme(axis.text = element_text(colour = "navyblue"),
plot.title = element_text(hjust = 0.5))+
facet_wrap(~commodity)
%>%
market_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Bawang Putih") %>%
ggplot(aes(x = market, y = mean_price))+
geom_segment( aes(x=reorder(market, mean_price) ,xend=market, y=0, yend=mean_price))+
geom_point(size=3, color="steelblue")+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Average Price by Commodity")+
labs(x = "Market",
y = "Average Price (IDR)", fill = "")+
theme(axis.text = element_text(colour = "navyblue"),
plot.title = element_text(hjust = 0.5))+
facet_wrap(~commodity)
%>%
market_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Kentang (sedang)") %>%
ggplot(aes(x = market, y = mean_price))+
geom_segment( aes(x=reorder(market, mean_price) ,xend=market, y=0, yend=mean_price))+
geom_point(size=3, color="steelblue")+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Average Price by Commodity")+
labs(x = "Market",
y = "Average Price (IDR)", fill = "")+
theme(axis.text = element_text(colour = "navyblue"),
plot.title = element_text(hjust = 0.5))+
facet_wrap(~commodity)
%>%
market_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Tomat Buah") %>%
ggplot(aes(x = market, y = mean_price))+
geom_segment( aes(x=reorder(market, mean_price) ,xend=market, y=0, yend=mean_price))+
geom_point(size=3, color="steelblue")+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Average Price by Commodity")+
labs(x = "Market",
y = "Average Price (IDR)", fill = "")+
theme_minimal()+
theme(axis.text = element_text(colour = "navyblue"),
plot.title = element_text(hjust = 0.5))+
facet_wrap(~commodity)
Berdasarkan visualisasi rata-rata harga sayuran per lokasi pasar di daerah DKI Jakarta, Pasar Mayestik yang berlokasi di daerah Jakarta Selatan memiliki harga rata-rata tertinggi untuk sayuran cabe rawit merah
, cabe rawit hijau
, bawang merah
, bawang putih
dan tomat buah
. Untuk harga rata-rata tertinggi sayuran cabe merah keriting
dan kentang
berlokasi di Pasar Pluit dan Pasar Jembatan Merah.
#create icon for leaflet
<-
icons awesomeIcons(icon = "map-pin",
iconColor = "red",
markerColor = "black",
library = "fa")
#create market popup name
<- unique(market$market) name
Berikut peta persebaran lokasi 43 pasar yang ada di daerah DKI Jakarta.
%>%
market_clean group_by(market) %>%
summarise(latitude = mean(latitude),
longitude = mean(longitude)) %>%
leaflet() %>%
addTiles() %>%
addMarkers(lng = ~longitude,
lat = ~latitude,
popup = name,
clusterOptions = markerClusterOptions())
unique(market_clean$commodity)
## [1] Cabe Merah Keriting Cabe Rawit Merah Cabe Rawit Hijau
## [4] Bawang Merah Bawang Putih Kentang (sedang)
## [7] Tomat Buah
## 7 Levels: Bawang Merah Bawang Putih Cabe Merah Keriting ... Tomat Buah
%>%
market_clean group_by(city, market) %>%
summarise(n = mean(longitude)) %>%
select(-n) %>%
group_by(city) %>%
tally() %>%
ggplot(aes(x = reorder(city, n), y = n))+
geom_bar(stat = "identity", aes(fill=city))+
labs(x = "Inner City",
y = "Number of Market")+
theme(legend.position = "none")+
coord_flip()
Daerah Jakarta Selatan dan Jakarta Pusat memiliki jumlah pasar tradisional terbanyak di bandingkan dengan 3 daerah lain nya di DKI Jakarta.
%>%
city_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Cabe Merah Keriting") %>%
arrange(mean_price) %>%
ggplot(aes(x=reorder(market, mean_price), y=mean_price)) +
geom_bar(stat = "identity", aes(fill = mean_price))+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Cabe Merah Keriting")+
theme(legend.position = "none")+
labs(x = "Market Location",
y = "Average Price (IDR)", fill = "")
%>%
city_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Cabe Rawit Merah") %>%
arrange(mean_price) %>%
ggplot(aes(x=reorder(market, mean_price), y=mean_price)) +
geom_bar(stat = "identity", aes(fill = mean_price))+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
ggtitle("Cabe Rawit Merah")+
theme(legend.position = "none")+
labs(x = "Market Location",
y = "Average Price (IDR)", fill = "")
%>%
city_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Cabe Rawit Hijau") %>%
arrange(mean_price) %>%
ggplot(aes(x=reorder(market, mean_price), y=mean_price)) +
geom_bar(stat = "identity", aes(fill = mean_price))+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
theme(legend.position = "none")+
ggtitle("Cabe Rawit Hijau")+
labs(x = "Market Location",
y = "Average Price (IDR)", fill = "")
%>%
city_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Bawang Merah") %>%
arrange(mean_price) %>%
ggplot(aes(x=reorder(market, mean_price), y=mean_price)) +
geom_bar(stat = "identity", aes(fill = mean_price))+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
theme(legend.position = "none")+
ggtitle("Bawang Merah")+
labs(x = "Market Location",
y = "Average Price (IDR)", fill = "")
%>%
city_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Bawang Putih") %>%
arrange(mean_price) %>%
ggplot(aes(x=reorder(market, mean_price), y=mean_price)) +
geom_bar(stat = "identity", aes(fill = mean_price))+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
theme(legend.position = "none")+
ggtitle("Bawang Putih")+
labs(x = "Market Location",
y = "Average Price (IDR)", fill = "")
%>%
city_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Kentang (sedang)") %>%
arrange(mean_price) %>%
ggplot(aes(x=reorder(market, mean_price), y=mean_price)) +
geom_bar(stat = "identity", aes(fill = mean_price))+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
theme(legend.position = "none")+
ggtitle("Kentang (sedang)")+
labs(x = "Market Location",
y = "Average Price (IDR)", fill = "")
%>%
city_clean group_by(market, commodity) %>%
summarise(mean_price = mean(price)) %>%
arrange(mean_price) %>%
filter(commodity == "Tomat Buah") %>%
arrange(mean_price) %>%
ggplot(aes(x=reorder(market, mean_price), y=mean_price)) +
geom_bar(stat = "identity", aes(fill = mean_price))+
coord_flip()+
scale_y_continuous(labels = scales::comma)+
theme(legend.position = "none")+
ggtitle("Tomat Buah")+
labs(x = "Market Location",
y = "Average Price (IDR)", fill = "")
Berdasarkan rata-rata harga per daerah bagian DKI Jakarta, harga rata-rata tertinggi dari cabe rawit merah
, cabe rawit hijau
, bawang merah
, kentang
dan tomat buah
berlokasi di Jakarta Selatan. Untuk bawang putih
dan cabe merah keriting
harga rata-rata tertinggi berlokasi di Jakarta Utara.
%>%
city_clean filter(commodity == "Cabe Merah Keriting") %>%
arrange(price) %>%
ggplot(aes(x = date, y = price, color = market))+
geom_point(size = 0.1)+
geom_line()+
scale_x_date(date_breaks = "4 month",
date_labels = "%B")+
scale_y_continuous(labels = scales::comma)+
ggtitle("Cabe Merah Keriting")+
labs(x = "Date",
y = "Price")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 35, hjust = 1))+
facet_wrap(~market)
Harga Cabe Merah Keriting
mengalami kenaikan di awal tahun 2020 lalu turun secara signifikan dan mencapai titik terendah di bulan Agustus 2020. Mendekati akhir tahun 2020, harga kembali melambung naik
%>%
city_clean filter(commodity == "Cabe Rawit Merah") %>%
arrange(price) %>%
ggplot(aes(x = date, y = price, color = market))+
geom_point(size = 0.1)+
geom_line()+
scale_x_date(date_breaks = "4 month",
date_labels = "%B")+
scale_y_continuous(labels = scales::comma)+
ggtitle("Cabe Rawit Merah")+
labs(x = "Date",
y = "Price")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 35, hjust = 1))+
facet_wrap(~market)
%>%
city_clean filter(commodity == "Cabe Rawit Hijau") %>%
arrange(price) %>%
ggplot(aes(x = date, y = price, color = market))+
geom_point(size = 0.1)+
geom_line()+
scale_x_date(date_breaks = "4 month",
date_labels = "%B")+
scale_y_continuous(labels = scales::comma)+
ggtitle("Cabe Rawit Hijau")+
labs(x = "Date",
y = "Price")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 35, hjust = 1))+
facet_wrap(~market)
%>%
city_clean filter(commodity == "Bawang Merah") %>%
arrange(price) %>%
ggplot(aes(x = date, y = price, color = market))+
geom_point(size = 0.1)+
geom_line()+
scale_x_date(date_breaks = "4 month",
date_labels = "%B")+
scale_y_continuous(labels = scales::comma)+
ggtitle("Bawang Merah")+
labs(x = "Date",
y = "Price")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 35, hjust = 1))+
facet_wrap(~market)
%>%
city_clean filter(commodity == "Bawang Putih") %>%
arrange(price) %>%
ggplot(aes(x = date, y = price, color = market))+
geom_point(size = 0.1)+
geom_line()+
scale_x_date(date_breaks = "4 month",
date_labels = "%B")+
scale_y_continuous(labels = scales::comma)+
ggtitle("Bawang Putih")+
labs(x = "Date",
y = "Price")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 35, hjust = 1))+
facet_wrap(~market)
%>%
city_clean filter(commodity == "Kentang (sedang)") %>%
arrange(price) %>%
ggplot(aes(x = date, y = price, color = market))+
geom_point(size = 0.1)+
geom_line()+
scale_x_date(date_breaks = "4 month",
date_labels = "%B")+
scale_y_continuous(labels = scales::comma)+
ggtitle("Kentang (sedang)")+
labs(x = "Date",
y = "Price")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 35, hjust = 1))+
facet_wrap(~market)
%>%
city_clean filter(commodity == "Tomat Buah") %>%
arrange(price) %>%
ggplot(aes(x = date, y = price, color = market))+
geom_point(size = 0.1)+
geom_line()+
scale_x_date(date_breaks = "4 month",
date_labels = "%B")+
scale_y_continuous(labels = scales::comma)+
ggtitle("Tomat Buah")+
labs(x = "Date",
y = "Price")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 35, hjust = 1))+
facet_wrap(~market)
Read data GADM
library(rgdal)
<- readOGR(dsn = "GDAM/gadm36_IDN_shp", layer = "gadm36_IDN_2") gadm
## OGR data source with driver: ESRI Shapefile
## Source: "C:\Users\Terap\Documents\Algoritma\DCD\Pubs\GDAM\gadm36_IDN_shp", layer: "gadm36_IDN_2"
## with 502 features
## It has 13 fields
<- gadm[gadm$NAME_1 == "Jakarta Raya",] gadm
<- sf::st_as_sf(gadm) gadm_sf
<-
city_bm %>%
city_clean filter(commodity == "Bawang Merah") %>%
group_by(market, commodity) %>%
summarise(price = mean(price))
<-
gadm_bm %>%
gadm_sf left_join(city_bm, by = c("NAME_2"="market"))
<- (fivenum(city_bm$price))
mybin_bm
<- colorBin(palette = "Spectral", domain = gadm_bm, na.color = "transparent", bins = mybin_bm)
mypalette_bm
<- paste(
mytext_bm
$TYPE_2," ", gadm_bm$NAME_2, "<br/>",
gadm_bm"Commodity ", gadm_bm$commodity, "<br/>",
"Average Price IDR ", scales::comma(round(gadm_bm$price,0)), "<br/>",
sep = "") %>%
lapply(htmltools::HTML)
leaflet(gadm_bm) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolygons(
fillColor = ~ mypalette_bm(gadm_bm$price),
weight = 1,
opacity = 1,
color = "white",
dashArray = "2",
fillOpacity = 0.7,
label = mytext_bm,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)%>%
) addLegend("bottomleft",
pal = mypalette_bm,
values = ~gadm_bm$price,
title = "Average Price",
labFormat = labelFormat(),
opacity = 1)
<-
city_bp %>%
city_clean filter(commodity == "Bawang Putih") %>%
group_by(market, commodity) %>%
summarise(price = mean(price))
<-
gadm_bp %>%
gadm_sf left_join(city_bp, by = c("NAME_2"="market"))
<- (fivenum(city_bp$price))
mybin_bp
<- colorBin(palette = "Spectral", domain = gadm_bp, na.color = "transparent", bins = mybin_bp)
mypalette_bp
<- paste(
mytext_bp
$TYPE_2," ", gadm_bp$NAME_2, "<br/>",
gadm_bp"Commodity ", gadm_bp$commodity, "<br/>",
"Average Price IDR ", scales::comma(round(gadm_bp$price,0)), "<br/>",
sep = "") %>%
lapply(htmltools::HTML)
leaflet(gadm_bp) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolygons(
fillColor = ~ mypalette_bp(gadm_bp$price),
weight = 1,
opacity = 1,
color = "white",
dashArray = "2",
fillOpacity = 0.7,
label = mytext_bp,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)%>%
) addLegend("bottomleft",
pal = mypalette_bp,
values = ~gadm_bp$price,
title = "Average Price",
labFormat = labelFormat(),
opacity = 1)
<-
city_cmk %>%
city_clean filter(commodity == "Cabe Merah Keriting") %>%
group_by(market, commodity) %>%
summarise(price = mean(price))
<-
gadm_cmk %>%
gadm_sf left_join(city_cmk, by = c("NAME_2"="market"))
<- (fivenum(city_cmk$price))
mybin_cmk
<- colorBin(palette = "Spectral", domain = gadm_cmk, na.color = "transparent", bins = mybin_cmk)
mypalette_cmk
<- paste(
mytext_cmk
$TYPE_2," ", gadm_cmk$NAME_2, "<br/>",
gadm_cmk"Commodity ", gadm_cmk$commodity, "<br/>",
"Average Price IDR ", scales::comma(round(gadm_cmk$price,0)), "<br/>",
sep = "") %>%
lapply(htmltools::HTML)
leaflet(gadm_cmk) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolygons(
fillColor = ~ mypalette_cmk(gadm_cmk$price),
weight = 1,
opacity = 1,
color = "white",
dashArray = "2",
fillOpacity = 0.7,
label = mytext_cmk,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)%>%
) addLegend("bottomleft",
pal = mypalette_cmk,
values = ~gadm_cmk$price,
title = "Average Price",
labFormat = labelFormat(),
opacity = 1)
<-
city_crm %>%
city_clean filter(commodity == "Cabe Rawit Merah") %>%
group_by(market, commodity) %>%
summarise(price = mean(price))
<-
gadm_crm %>%
gadm_sf left_join(city_crm, by = c("NAME_2"="market"))
<- (fivenum(city_crm$price))
mybin_crm
<- colorBin(palette = "Spectral", domain = gadm_crm, na.color = "transparent", bins = mybin_crm)
mypalette_crm
<- paste(
mytext_crm
$TYPE_2," ", gadm_crm$NAME_2, "<br/>",
gadm_crm"Commodity ", gadm_crm$commodity, "<br/>",
"Average Price IDR ", scales::comma(round(gadm_crm$price,0)), "<br/>",
sep = "") %>%
lapply(htmltools::HTML)
leaflet(gadm_crm) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolygons(
fillColor = ~ mypalette_crm(gadm_crm$price),
weight = 1,
opacity = 1,
color = "white",
dashArray = "2",
fillOpacity = 0.7,
label = mytext_crm,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)%>%
) addLegend("bottomleft",
pal = mypalette_crm,
values = ~gadm_crm$price,
title = "Average Price",
labFormat = labelFormat(),
opacity = 1)
<-
city_crh %>%
city_clean filter(commodity == "Cabe Rawit Hijau") %>%
group_by(market, commodity) %>%
summarise(price = mean(price))
<-
gadm_crh %>%
gadm_sf left_join(city_crh, by = c("NAME_2"="market"))
<- (fivenum(city_crh$price))
mybin_crh
<- colorBin(palette = "Spectral", domain = gadm_crh, na.color = "transparent", bins = mybin_crh)
mypalette_crh
<- paste(
mytext_crh
$TYPE_2," ", gadm_crh$NAME_2, "<br/>",
gadm_crh"Commodity ", gadm_crh$commodity, "<br/>",
"Average Price IDR ", scales::comma(round(gadm_crh$price,0)), "<br/>",
sep = "") %>%
lapply(htmltools::HTML)
leaflet(gadm_crh) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolygons(
fillColor = ~ mypalette_crh(gadm_crh$price),
weight = 1,
opacity = 1,
color = "white",
dashArray = "2",
fillOpacity = 0.7,
label = mytext_crh,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)%>%
) addLegend("bottomleft",
pal = mypalette_crh,
values = ~gadm_crh$price,
title = "Average Price",
labFormat = labelFormat(),
opacity = 1)
<-
city_k %>%
city_clean filter(commodity == "Kentang (sedang)") %>%
group_by(market, commodity) %>%
summarise(price = mean(price))
<-
gadm_k %>%
gadm_sf left_join(city_k, by = c("NAME_2"="market"))
<- (fivenum(city_k$price))
mybin_k
<- colorBin(palette = "Spectral", domain = gadm_k, na.color = "transparent", bins = mybin_k)
mypalette_k
<- paste(
mytext_k
$TYPE_2," ", gadm_k$NAME_2, "<br/>",
gadm_k"Commodity ", gadm_k$commodity, "<br/>",
"Average Price IDR ", scales::comma(round(gadm_k$price,0)), "<br/>",
sep = "") %>%
lapply(htmltools::HTML)
leaflet(gadm_k) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolygons(
fillColor = ~ mypalette_k(gadm_k$price),
weight = 1,
opacity = 1,
color = "white",
dashArray = "2",
fillOpacity = 0.7,
label = mytext_k,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)%>%
) addLegend("bottomleft",
pal = mypalette_k,
values = ~gadm_k$price,
title = "Average Price",
labFormat = labelFormat(),
opacity = 1)
<-
city_tb %>%
city_clean filter(commodity == "Kentang (sedang)") %>%
group_by(market, commodity) %>%
summarise(price = mean(price))
<-
gadm_tb %>%
gadm_sf left_join(city_tb, by = c("NAME_2"="market"))
<- (fivenum(city_tb$price))
mybin_tb
<- colorBin(palette = "Spectral", domain = gadm_tb, na.color = "transparent", bins = mybin_tb)
mypalette_tb
<- paste(
mytext_tb
$TYPE_2," ", gadm_tb$NAME_2, "<br/>",
gadm_tb"Commodity ", gadm_tb$commodity, "<br/>",
"Average Price IDR ", scales::comma(round(gadm_tb$price,0)), "<br/>",
sep = "") %>%
lapply(htmltools::HTML)
leaflet(gadm_tb) %>%
addProviderTiles(providers$CartoDB.DarkMatter) %>%
addPolygons(
fillColor = ~ mypalette_tb(gadm_tb$price),
weight = 1,
opacity = 1,
color = "white",
dashArray = "2",
fillOpacity = 0.7,
label = mytext_tb,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "13px",
direction = "auto"
)%>%
) addLegend("bottomleft",
pal = mypalette_tb,
values = ~gadm_tb$price,
title = "Average Price",
labFormat = labelFormat(),
opacity = 1)
%>%
inflasi mutate(periode = lubridate::my(Periode)) %>%
ggplot(aes(x = periode, y = Inflasi))+
geom_point()+
geom_line(color = "red")+
scale_x_date(date_breaks = "2 month",
date_labels = "%B %Y")+
ggtitle("Inflation Rate")+
labs(x = "Month",
y = "Inflation Rate")+
theme(legend.position = "none",
plot.title = element_text(hjust = 0.5),
axis.text.x = element_text(angle = 50, hjust = 1))
Berdasarkan visualisasi dari data
inflasi
, terdapat penurunan yang cukup significant dari awal tahun 2020, tepatnya dari bulan Maret sampai dengan titik terendah di bulan Agustus 2020. Pada pertengahan tahun 2021, inflasi mulai meningkat lagi sampai dengan January 2022.
<-
city_list %>%
city_clean select(-date) %>%
unite("series", market, commodity, sep = "_") %>%
nest(-series)
<- list(weekly = function(x) ts(x, frequency = 7)) seasonal
<- crossing(city_list, seasonal) list_crossing
<- list_crossing$data %>%
ts map2(.y = list_crossing$seasonal,
.f = ~exec(.y, .x))
1]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[1],
y = "Price", x = NULL)
8]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[8],
y = "Price", x = NULL)
15]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[15],
y = "Price", x = NULL)
22]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[22],
y = "Price", x = NULL)
29]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[29],
y = "Price", x = NULL)
2]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[2],
y = "Price", x = NULL)
9]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[9],
y = "Price", x = NULL)
16]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[16],
y = "Price", x = NULL)
23]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[23],
y = "Price", x = NULL)
30]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[30],
y = "Price", x = NULL)
3]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[3],
y = "Price", x = NULL)
10]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[10],
y = "Price", x = NULL)
17]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[17],
y = "Price", x = NULL)
24]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[24],
y = "Price", x = NULL)
31]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[31],
y = "Price", x = NULL)
4]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[4],
y = "Price", x = NULL)
11]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[11],
y = "Price", x = NULL)
18]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[18],
y = "Price", x = NULL)
25]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[25],
y = "Price", x = NULL)
32]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[32],
y = "Price", x = NULL)
5]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[5],
y = "Price", x = NULL)
12]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[12],
y = "Price", x = NULL)
19]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[19],
y = "Price", x = NULL)
26]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[26],
y = "Price", x = NULL)
33]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[33],
y = "Price", x = NULL)
6]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[6],
y = "Price", x = NULL)
13]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[13],
y = "Price", x = NULL)
20]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[20],
y = "Price", x = NULL)
27]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[27],
y = "Price", x = NULL)
34]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[34],
y = "Price", x = NULL)
7]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[7],
y = "Price", x = NULL)
14]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[14],
y = "Price", x = NULL)
21]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[21],
y = "Price", x = NULL)
28]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[28],
y = "Price", x = NULL)
35]] %>%
ts[[decompose() %>%
autoplot()+
labs(subtitle = list_crossing$series[35],
y = "Price", x = NULL)