Jumat, 23 Februari 2018

Transaksi mie instant meningkat menjelang tanggal tua.


Transaksi mie instant  meningkat menjelang tanggal tua.
Tampilan dashboard shiny


Teringat masa kuliah, ketika menjelang tanggal tua uang saku menipis kira kira menu apa yang akan kita santap untuk mengisi perut. Sudah menjadi rahasia umum bagi mahasiswa perantauan saat itu, ya apalagi kalau bukan mie instant. Kebiasaan ini ternyata masih berlanjut, padahal kebanyakan makan mi instan itu kan tidak sehat.  Simpel saja sih alasannya daripada perut lapar kan tidak bisa belajar.
Fenomena tersebut yang mengusik pikiran saya untuk meyakinkan apakah benar pada tanggal tua transaksi mie instan meningkat. Untuk menjawab  hal tersebut saya mencoba menganalisa data transaksi dari sebuah minimarket di sekitar kampus.


Gb1
Karena datanya tidak besar, saya gunakan pengamatan empiris lewat grafik, yang diproses dengan R programming, divisualkan dengan shiny aplikasi, berikut script R nya:


Gb2


#--- Persiapan Data
head(dm)
  year month date_of_month day_of_week mie_instan
1 2000     1             1           6        120
2 2000     1             2           7         99
3 2000     1             3           1        123
4 2000     1             4           2        132
5 2000     1             5           3        133
6 2000     1             6           4        100
dim(dm)
[1] 5479    5


library(shiny) #untuk visualisasi
library(ggplot2) #untuk Grafis
library(dplyr) #Untuk proses

#---Panel UI Shiny Application
ui <- fluidPage(
  # Some custom CSS for a smaller font for preformatted text
  tags$head(
    tags$style(HTML("
                    pre, table.table {
                    font-size: smaller;
                    }
                    ")
  ),
 
  fluidRow(
    column(width = 4, wellPanel(
      radioButtons("plot_type", "Plot type",
                   c("P1-Sales-2000", "P2-Sales-2001","P3-Sales-2002","P4-Sales-2003","P5-Sales-2004",
                     "P6-Sales-2005","P7-Sales-2006","P8-Sales-2007",
                     "P9-Sales-2008","P10-Sales-2009","P11-Sales-2010",
                     "P12-Sales-2011","P13-Sales-2012","P14-Sales-2013","P15-Sales-2014",
                     "Sales-Total-Year","Salest-Total-Split-Year")
      )
    )),
    column(width = 4,
           # In a plotOutput, passing values for click, dblclick, hover, or brush
           # will enable those interactions.
           plotOutput("plot1", brush = "plot_brush", width = 500, height = 350),
           verbatimTextOutput("info"))
    )
  )
 )

#---Data proccess
library(shiny)
library(ggplot2)
library(dplyr)

#---Data local 
dm <- read.csv("G:/new-program/mie instant/rsconnect/Data/mi.csv")

#---count number days each year
#n_day_year1 <- dm  %>% count(year) %>% arrange(desc(year)) %>% slice(1:15)
#n_day_year1
# A tibble: 15 ? 2
#   year     n
#  <int> <int>
#1   2014   365
#2   2013   365
#3   2012   366
#4   2011   365
#5   2010   365
#6   2009   365
#7   2008   366
#8   2007   365
#9   2006   365
#10  2005   365
#11  2004   366
#12  2003   365
#13  2002   365
#14  2001   365
#15  2000   366
#---Mean per year
d1 <- dm[1:366,]
gd1 <- d1 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P1 <- ggplot(gd1, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2000",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d2 <- dm[367:731,]
gd2 <- d2 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P2 <- ggplot(gd2, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2001",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d3 <- dm[732:1096,]
gd3 <- d3 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P3 <- ggplot(gd3, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2002",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d4 <- dm[1097:1461,]
gd4 <- d4 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P4 <- ggplot(gd4, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2003",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d5 <- dm[1462:1821,]
gd5 <- d5 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P5 <- ggplot(gd5, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2004",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d6 <- dm[1828:2192,]
gd6 <- d6 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P6 <- ggplot(gd6, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2005",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d7 <- dm[2193:2557,]
gd7 <- d7 %>%
  group_by(date_of_month)%>%
  mutate(md=mean(mie_instan))
P7 <- ggplot(gd7, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2006",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d8 <- dm[2558:2922,]
gd8 <- d8 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P8 <- ggplot(gd8, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2007",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()
d9 <- dm[2923:3288,]
gd9 <- d9 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P9 <- ggplot(gd9, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2008",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()

d10 <- dm[3289:3653,]
gd10 <- d10 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P10 <- ggplot(gd10, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2009",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()

d11 <- dm[3654:4018,]
gd11 <- d11 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P11 <- ggplot(gd11, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2010",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()

d12 <- dm[4019:4383,]
gd12 <- d12 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P12 <- ggplot(gd12, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2011",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()

d13 <- dm[4384:4749,]
gd13 <- d13 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P13 <- ggplot(gd13, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2012",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()

d14 <- dm[4750:5114,]
gd14 <- d14 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P14 <- ggplot(gd14, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2013",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()

d15 <- dm[5115:5479,]
gd15 <- d15 %>%
  group_by(date_of_month) %>%
  mutate(md=mean(mie_instan))
P15 <- ggplot(gd15, aes(x = date_of_month, y = md)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  ggtitle("Sales Mie-Instant 2014",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
  theme_bw()

#---Binding mean per year
Py <- rbind(gd1,gd2,gd3,gd4,gd5,gd6,gd7,gd8,gd9,
            gd10,gd11,gd12,gd13,gd14,gd15)

#---Grafik mean th 2000-2014
Sales_Total_Year <- ggplot(Py, aes(x = date_of_month, y = md)) +
  geom_line() +
  ggtitle("Sales Mie Instant per month 2000-2014",subtitle = "Crafted by  www.realrapplication.blogspot.com") +
  labs(x = "Day", y = "Mean") +
   theme_bw()
#---Grafik split per th
Salest_Total_Split_Year <- ggplot(Py,aes(x = date_of_month, y = md, group = year)) +
  geom_line(color = "dark red", size = 1, na.rm = T) +
  facet_wrap(~ year) +
  labs(title = "Sales Mie-instant per month per year\n Crafted by  www.realrapplication.blogspot.com") +
  labs(subtitle = "2000-14") +
  labs(x = "Day", y = "Mean") +
   theme_bw()

#---Panel server Shiny Application
server <- function(input, output) {
  output$plot1 <- renderPlot({
    if (input$plot_type == "P1-Sales-2000") {
      P1
    } else if (input$plot_type == "P2-Sales-2001") {
      P2
    } else if (input$plot_type == "P3-Sales-2002") {
      P3
    }else if (input$plot_type == "P4-Sales-2003") {
      P4
    }else if (input$plot_type == "P5-Sales-2004") {
      P5
    }else if (input$plot_type == "P6-Sales-2005") {
      P6
    }else if (input$plot_type == "P7-Sales-2006") {
      P7
    }else if (input$plot_type == "P8-Sales-2007") {
      P8
    }else if (input$plot_type == "P9-Sales-2008") {
      P9
    }else if (input$plot_type == "P10-Sales-2009") {
      P10
    }else if (input$plot_type == "P11-Sales-2010") {
      P11
    }else if (input$plot_type == "P12-Sales-2011") {
      P12
    }else if (input$plot_type == "P13-Sales-2012") {
      P13
    }else if (input$plot_type == "P14-Sales-2013") {
      P14
    }else if (input$plot_type == "P15-Sales-2014") {
      P15
    }else if (input$plot_type == "Sales-Total-Year") {
      Sales_Total_Year
    }else if (input$plot_type == "Salest-Total-Split-Year") {
      Salest_Total_Split_Year
    }
  })
  output$info <- renderPrint({
    brushedPoints(Py, input$plot_brush)
  })
}
shinyApp(ui=ui,server=server)


Kesimpulan:
1.  Mengamati grafik P1-P15, yaitu penjualan mie instan per bulan, nampak jelas penjualan meningkat di sekitar tgl tua tiap bulan. Berdasar data empiris transaksi per bulan tsb  makin jelas divisualkan dalam Grafik "Sales Mie Instant per month 2000-2014".Lihat Gb1
2.  Kalo diamati lebih dalam juga terjadi fenomena transaksi mie instant periodically per 7 hari, analisa lebih detail bisa dilanjutkan lain waktu.
3.  Bagi pemilik minimarket ini adalah info yang sangat penting, karena berhubungan dengan persediaan barang.Lihat Gb2
4.  Dengan R programming prosesnya cepat, pengalaman penulis pernah memproses data transaksi terdiri dari 1/2 juta baris, tidak terlalu lama, running di laptop Azus 1.65 HZ, RAM 4 GB.

Referensi:
http://rsudio.
https://datascienceplus.com/

Tidak ada komentar:

Posting Komentar

Kapan Puncak Covid19 di Indonesia ?

Prediksi Covid19, kapan mencapai puncaknya? Selamat Idhul Fitri from Home, menjawab pertanyaan kapan covid19 mencapai puncaknya? ...