Loading Data

setwd("C:/Users/ahmet/Desktop/MEF_BDA/R_Data")
data <- read_xlsx("EVDS_istanbul_property_data_R.xlsx")

New House Sales vs Old House Sales vs Mortgage House Sales

data_ratios= data %>% mutate(new_sales_ratio=new_building_sales/total_sales, 
                             old_sales_ratio= old_building_sales/total_sales, 
                             mortgage_sales_ratio= total_sales_mortgage/total_sales,
                             foreign_sales_ratio=foreign_sales/total_sales) %>% 
  select(date_ist,total_sales, total_sales, new_sales_ratio, old_sales_ratio, mortgage_sales_ratio,
          foreign_sales_ratio, new_building_price_index, price_index, `house_unit_price_Tl/m2`)


data_ratios
## # A tibble: 93 x 9
##    date_ist total_sales new_sales_ratio old_sales_ratio mortgage_sales_~
##    <chr>          <dbl>           <dbl>           <dbl>            <dbl>
##  1 2013-01        18235           0.455           0.545            0.462
##  2 2013-02        18971           0.436           0.564            0.466
##  3 2013-03        21570           0.442           0.558            0.471
##  4 2013-04        20791           0.421           0.579            0.468
##  5 2013-05        22030           0.425           0.575            0.490
##  6 2013-06        19357           0.422           0.578            0.504
##  7 2013-07        20668           0.437           0.563            0.487
##  8 2013-08        14930           0.466           0.534            0.458
##  9 2013-09        18514           0.439           0.561            0.440
## 10 2013-10        14866           0.453           0.547            0.422
## # ... with 83 more rows, and 4 more variables: foreign_sales_ratio <dbl>,
## #   new_building_price_index <dbl>, price_index <dbl>,
## #   `house_unit_price_Tl/m2` <dbl>
plot_df2 <- data_ratios %>% select(date_ist,total_sales,new_sales_ratio,old_sales_ratio,mortgage_sales_ratio,foreign_sales_ratio) 
plot_df2
## # A tibble: 93 x 6
##    date_ist total_sales new_sales_ratio old_sales_ratio mortgage_sales_~
##    <chr>          <dbl>           <dbl>           <dbl>            <dbl>
##  1 2013-01        18235           0.455           0.545            0.462
##  2 2013-02        18971           0.436           0.564            0.466
##  3 2013-03        21570           0.442           0.558            0.471
##  4 2013-04        20791           0.421           0.579            0.468
##  5 2013-05        22030           0.425           0.575            0.490
##  6 2013-06        19357           0.422           0.578            0.504
##  7 2013-07        20668           0.437           0.563            0.487
##  8 2013-08        14930           0.466           0.534            0.458
##  9 2013-09        18514           0.439           0.561            0.440
## 10 2013-10        14866           0.453           0.547            0.422
## # ... with 83 more rows, and 1 more variable: foreign_sales_ratio <dbl>
plot_df3 = plot_df2 %>% select(date_ist, new_sales_ratio, old_sales_ratio, mortgage_sales_ratio)

ggplot(plot_df2, aes(x=date_ist, y=new_sales_ratio,group=1)) + geom_line()+ geom_point(color="blue") + labs(x = "Months", y = "Sales Ratio of New Houses")

plot_df3 %>% pivot_longer(.,-date_ist) %>% ggplot(.,aes(x=date_ist,y=value, group=1,color=name)) + geom_line() + labs(x = "Months", y = "Sales Ratios")

ggplot()+
    geom_line(data=plot_df2,aes(x=date_ist, y=new_sales_ratio,group=1, colour="darkblue"),size=1 )+
    geom_line(data=plot_df2,aes(x=date_ist, y=old_sales_ratio,group=1, colour="red"),size=1) +
    geom_line(data=plot_df2,aes(x=date_ist, y=mortgage_sales_ratio,group=1, colour="green"), size=1)+   
    scale_color_discrete(name = "House Categories", labels = c("new house sales ratio", "old house sales ratio","mortgage house sales ratio")) + labs(x = "date", y = "Sales Ratios")

Average Monthly Sales for Years

data_yearly= data %>%filter(date_ist<"2020-09") %>% group_by(year = substr(date_ist,1,4)) %>%
  summarise(avg_mean_sales = mean(total_sales), avg_new_bldg_pi=mean(new_building_price_index), avg_price_index=mean(price_index))
## `summarise()` ungrouping output (override with `.groups` argument)
data_yearly
## # A tibble: 8 x 4
##   year  avg_mean_sales avg_new_bldg_pi avg_price_index
##   <chr>          <dbl>           <dbl>           <dbl>
## 1 2013          19566.            53.6            52.5
## 2 2014          18788.            63.6            63.2
## 3 2015          19981.            78.6            79.0
## 4 2016          19369             91.6            92.4
## 5 2017          19865.           100.            100. 
## 6 2018          19505.           102.            102. 
## 7 2019          19806.           102.            101. 
## 8 2020          22004.           122.            116.
ggplot(data_yearly, aes(x=year, y=avg_mean_sales,group=1)) + geom_line()+ geom_point(color="red") + labs(x = "Years", y = "Monthly Number of Sales")