11 October 2018

Overview

This application allows user to study the changing trends of divorce rates in Singapore across various ethicities and marriage duration between 1980 and 2016, of divorces that are under Women's Charter. The data was taken from official database repository at https://data.gov.sg/. This dataset was compiled by Singapore Department of Statistics, and they filed under the database entitled: "Divorces under the Women's Charter by Ethnic Group of Couple and Duration of Marriage, Annual".

This application allows user to:
  • Select the ethnicity type ("Chinese", "Indian", "Others", "Inter-ethnic"), and the various marriage duration bands. Do note that the data only includes divorces that are filed under Women's Charter. Hence, divorces for "Malay" enthic group are not included here.
  • The first input is the "Ethnicity". The default selection is "Total".
  • The second input is to "Marriage Duration". The default selection is "Under 5 Years".
  • The app will churn out two graphs on number of divorce cases in Singapore between 1980-2016 based on selected paramaters. The first graph is a histogram that illustrates how many divorce cases are occuring in specific bands, and how spread out these cases are. The second graph is a time series plot that illustrates the overall trend over the years.

Resources

Image of application

Here is an image of the application. To access the actual application, please click here

Annex: Source Codes - Part 1 of 3

Here is part 1 of the source codes

rm(list=ls())
library(shiny)
data <- read.csv("divorces-under-the-womens-charter-by-ethnic-group-of-couple-and-duration-of-marriage.csv", header=TRUE, na.strings=c(""))
data <- transform(data, year = as.Date(as.character(year), "%Y"))

varList_L1 <- c("Total", "Chinese", "Indians", "Others", "Inter-ethnic")
varList_L2 <- c("Under 5 Years", "5-9 Years", "10-14 Years", "15-19 Years", "20-24 Years", "25-29 Years", "30 Years & Over")

Annex: Source Codes - Part 2 of 3

Here is part 2 of the source codes

library(shiny)
ui<- shinyUI(fluidPage(
  titlePanel("Divorce Rates in Singapore by Ethincity and Duration of Marriages"),
  sidebarLayout(
    sidebarPanel(
      selectInput("varNames1", "Select Ethnicity", selected = varList_L1[1], varList_L1),
      selectInput("varNames2", "Select Marriage Duration", selected = varList_L2[1], varList_L2)
    ),
    mainPanel(
      h3("Graphs on Divorces in Singapore (1980-2016)"),
      plotOutput("plot1")
    )
  )
))

Annex: Source Codes - Part 3 of 3

Here is part 3 of the source codes

server <- shinyServer(function(input, output) {

  output$plot1 <- renderPlot({
    y <- data[data$level_1==input$varNames1 & data$level_2==input$varNames2,"value"]
    timeseries <- ts(y, start=1980)
    
    par(mfrow = c(1,2))
    with(data,{
      hist(y, main="Histogram", xlab="Number of Divorces", ylab="Frequency", col="#AB1301")
      plot.ts(timeseries, type="l", main="Time Series Plot", xlab="Years", las=3, ylab="Number of Divorces", col="#09509C", lwd=2)
    })

  })
})
shinyApp(ui=ui, server=server)

Thank You
More analysis on this topic coming your way.