library(csodata)
library(tidyverse)
library(knitr)
library(kableExtra)
library(ggplot2)
library(lubridate)
library(ggrepel)
library(zoo)
library(sf)
library(tmap)
library(rgdal)
library(readxl)
library(maps)
library(mapproj)
library(mapview)
library(patchwork)
library(Hmisc)
library(formattable)
library(scales)

#Load

## NDQ07
NDQ07 <- cso_get_data("NDQ07")
NDQ07_long <- NDQ07 %>%
  pivot_longer(!1:2, names_to = "year_qtr")
NDQ07 <- NDQ07_long
rm(NDQ07_long)
### Date transformation

NDQ07$Year_Q <- as.yearqtr(NDQ07$year_qtr)
NDQ07$Year <- year(NDQ07$Year_Q)

## GeoSpatial
setwd("/Users/charten/OneDrive - Glenveagh Properties/Research & Development/1. Analysis/")
#shp = readOGR(dsn=".", layer = "Constituency_Boundaries_Ungeneralised___OSi_National_Electoral_Boundaries___2017")
#shp = readOGR(dsn=".", layer = "counties")
shp <- sf::read_sf("Constituency_Boundaries_Ungeneralised___OSi_National_Electoral_Boundaries___2017.shp")
GEO_Merge <- readxl::read_xlsx(path="C:\\Users\\charten\\OneDrive - Glenveagh Properties\\Research & Development\\1. Analysis\\HPM04_GEO.xlsx",sheet = 1)

NDQ07_A <- NDQ07 %>%
  filter(Eircode.Output=="All")

NDQ07_B <- NDQ07 %>%
  filter(Eircode.Output!="All")

NDQ07_join <- full_join(NDQ07_B, GEO_Merge, by = "Eircode.Output")
NDQ07 <- NDQ07_join
rm(NDQ07_join)
rm(NDQ07_B)
NDQ07_A_24 <- tail(NDQ07_A,24)
Bar_24 <- ggplot(data=NDQ07_A_24, aes(x=Year_Q, y=value))+
  geom_col(alpha = 0.5, colour="#373634", fill = "#1b5545")+
  labs(title = "New Dwelling Completions, by Quarter - NDQ07" ,
       subtitle = "24 Month Series",
       y="Units Completed",
       x="Year-Qtr")+
  geom_text(aes(label=value),vjust= 1.5, size=2)+
  theme(legend.position = "bottom")

tbl_NDQ07_A_Year <-  NDQ07_A %>%
  group_by(Year)%>%
  summarise(Average_Value = mean(value),
            Total = sum(value))

Bar_Yr <- ggplot(data=tbl_NDQ07_A_Year, aes(x=Year, y=Total))+
  geom_col(alpha = 0.5, colour="#373634", fill = "#02218A")+
  labs(title = "New Dwelling Completions, by Year - NDQ07" ,
       subtitle = "total sample",
       y="Units Completed",
       x="Year")+
  geom_text(aes(label=Total),vjust= 1.5, size=3)+
  theme(legend.position = "bottom")+
  scale_x_continuous(breaks=pretty_breaks(n = 5))

The Government’s Housing for All plan targets 24,600 completions in 2022, 29,000 in 2023 and 33,450 in 2024.

Headline & Summary

NDQ07_A_tail <- tail(NDQ07_A,1)
NDQ07_A_tail_lag <-head(tail(NDQ07_A,2),1)
NDQ07_A_tail_yonylag <-head(tail(NDQ07_A,5),1)

The headline completion number for 2022 Q2 is 7654. This represents a 1992 change from 2022 Q1 which was 5662. Year on year this represents a 2664 change from 2021 Q2 which was 4990.


Figures

Bar_24

Bar_Yr

NDQ07_Map <- NDQ07 %>%
  filter(year_qtr == NDQ07_A_tail$year_qtr)
NDQ07_Map_Dub <- NDQ07_Map %>% 
  filter(grepl('Dublin|Laoghaire', Seat_Tag))

shpNDQ <- merge(shp,NDQ07_Map, by.x = "CON_SEAT_", by.y="Seat_Tag")
shpNDQDub <- merge(shp,NDQ07_Map_Dub, by.x = "CON_SEAT_", by.y="Seat_Tag")

Map_1 <-  shpNDQ %>%
  ggplot()+
  geom_sf(aes(fill = value))+
 scale_fill_stepsn(n.breaks = 10,
    colors=c("#ECEFFB","#3966FE","#02218A"),
    name = "completions")+
    ggtitle('Eircode Output Aggregated to Constituency: Latest Quarter')+
  theme_void()+
  theme(legend.title = element_text(size = 10),
        legend.text = element_text(size = 8))+
    theme(legend.position = "left")+
  theme(plot.title = element_text(hjust = 1))

Map_2 <- shpNDQDub %>%
  ggplot()+
  geom_sf(aes(fill = value))+
 scale_fill_stepsn(n.breaks = 10,
    colors=c("#ECEFFB","#3966FE","#02218A"),
    name = "completions")+
    theme_void()+
  theme(legend.position = "none")


Map_View <- Map_1 + Map_2 +
  plot_layout(widths = c(2,1))

Map_View

Table%>%
  kbl(caption = "New Dwelling Completions - Sorted by Total")%>%
  kable_styling(bootstrap_options = c("striped", "hover", "condensed"), full_width = T)%>%
  scroll_box(width = "600px", height = "300px") 
New Dwelling Completions - Sorted by Total
Eircode.Output Year_Q Constituency value
D18: Dublin 18 2022 Q2 Dublin Rathdown 528
D12: Dublin 12 2022 Q2 Dublin South Central 377
D09: Dublin 9 2022 Q2 Dublin North-West 340
H91: Galway 2022 Q2 Galway West 255
T12: Cork Southside 2022 Q2 Cork North-Central 234
A92: Drogheda 2022 Q2 Louth 225
W91: Naas 2022 Q2 Kildare North 220
C15: Navan 2022 Q2 Meath West 219
D07: Dublin 7 2022 Q2 Dublin West 219
W23: Celbridge 2022 Q2 Kildare North 196
V94: Limerick 2022 Q2 Limerick City 190
D22: Dublin 22 2022 Q2 Dublin South Central 189
A63: Greystones 2022 Q2 Wicklow 166
K78: Lucan 2022 Q2 Dublin Mid-West 159
V95: Ennis 2022 Q2 Clare 144
R95: Kilkenny 2022 Q2 Carlow-Kilkenny 138
A91: Dundalk 2022 Q2 Louth 133
V92: Tralee 2022 Q2 Kerry 120
W12: Newbridge 2022 Q2 Kildare South 115
R32: Portlaoise 2022 Q2 Laois-Offaly 114
D16: Dublin 16 2022 Q2 Dublin South-West 111
D13: Dublin 13 2022 Q2 Dublin Bay North 94
V93: Killarney 2022 Q2 Kerry 92
P43: Carrigaline 2022 Q2 Cork South-Central 91
T23: Cork Northside 2022 Q2 Cork North-Central 88
T45: Glanmire 2022 Q2 Cork North-Central 87
K36: Malahide 2022 Q2 Dublin Fingal 84
A67: Wicklow 2022 Q2 Wicklow 81
D01: Dublin 1 2022 Q2 Dublin Central 79
K56: Rush 2022 Q2 Dublin Fingal 78
N91: Mullingar 2022 Q2 Longford-Westmeath 70
D24: Dublin 24 2022 Q2 Dublin South-West 68
Y35: Wexford 2022 Q2 Wexford 68
P51: Mallow 2022 Q2 Cork East 67
X91: Waterford 2022 Q2 Waterford 63
F92: Letterkenny 2022 Q2 Donegal 62
R35: Tullamore 2022 Q2 Laois-Offaly 61
K32: Balbriggan 2022 Q2 Dublin Fingal 57
K45: Lusk 2022 Q2 Dublin Fingal 54
F94: Donegal 2022 Q2 Donegal 51
F93: Lifford 2022 Q2 Donegal 49
A85: Dunshaughlin 2022 Q2 Meath East 48
D17: Dublin 17 2022 Q2 Dublin Fingal 48
H12: Cavan 2022 Q2 Cavan-Monaghan 48
R93: Carlow 2022 Q2 Carlow-Kilkenny 48
Y25: Gorey 2022 Q2 Wexford 47
Y21: Enniscorthy 2022 Q2 Wexford 44
F91: Sligo 2022 Q2 Sligo-Leitrim 41
D04: Dublin 4 2022 Q2 Dublin Bay South 39
K67: Swords 2022 Q2 Dublin Fingal 38
H54: Tuam 2022 Q2 Galway East 37
A82: Kells 2022 Q2 Meath East 35
P25: Midleton 2022 Q2 Cork East 35
V35: Kilmallock 2022 Q2 Limerick County 34
D06: Dublin 6 2022 Q2 Dublin Bay South 33
P31: Ballincollig 2022 Q2 Cork North-West 33
P12: Macroom 2022 Q2 Cork North-West 32
A98: Bray 2022 Q2 Wicklow 31
N37: Athlone 2022 Q2 Longford-Westmeath 31
Y14: Arklow 2022 Q2 Wicklow 31
D15: Dublin 15 2022 Q2 Dublin West 30
F28: Westport 2022 Q2 Mayo 30
N39: Longford 2022 Q2 Longford-Westmeath 30
A81: Carrickmacross 2022 Q2 Cavan-Monaghan 29
F12: Claremorris 2022 Q2 Mayo 29
E45: Nenagh 2022 Q2 Tipperary 28
F26: Ballina 2022 Q2 Mayo 28
R56: Curragh 2022 Q2 Kildare South 28
H65: Athenry 2022 Q2 Galway East 27
P85: Clonakilty 2022 Q2 Cork South-West 27
A83: Enfield 2022 Q2 Meath West 26
D02: Dublin 2 2022 Q2 Dublin Bay South 26
H18: Monaghan 2022 Q2 Cavan-Monaghan 26
P17: Kinsale 2022 Q2 Cork South-West 25
F23: Castlebar 2022 Q2 Mayo 24
H53: Ballinasloe 2022 Q2 Roscommon-Galway 23
R51: Kildare 2022 Q2 Kildare South 23
A96: Glenageary 2022 Q2 Dun Laoghaire 22
H62: Loughrea 2022 Q2 Galway East 22
A75: Castleblaney 2022 Q2 Cavan-Monaghan 21
E91: Clonmel 2022 Q2 Tipperary 21
P72: Bandon 2022 Q2 Cork South-West 21
W34: Monasterevin 2022 Q2 Kildare South 20
E32: Carrick-on-Suir 2022 Q2 Tipperary 19
E41: Thurles 2022 Q2 Tipperary 19
P47: Dunmanway 2022 Q2 Cork South-West 19
P81: Skibbereen 2022 Q2 Cork South-West 19
D05: Dublin 5 2022 Q2 Dublin Bay North 18
H23: Clones 2022 Q2 Cavan-Monaghan 18
R42: Birr 2022 Q2 Laois-Offaly 18
V31: Listowel 2022 Q2 Kerry 18
D03: Dublin 3 2022 Q2 Dublin Bay North 16
P14: Crookstown 2022 Q2 Cork North-West 15
T34: Carrignavar 2022 Q2 Cork East 14
A86: Dunboyne 2022 Q2 Meath East 13
A94: Blackrock 2022 Q2 Dun Laoghaire 13
E34: Tipperary 2022 Q2 Tipperary 13
F45: Castlerea 2022 Q2 Roscommon-Galway 13
P24: Cobh 2022 Q2 Cork East 13
Y34: New Ross 2022 Q2 Wexford 13
D08: Dublin 8 2022 Q2 Dublin South Central 12
T56: Watergrasshill 2022 Q2 Cork North-Central 12
P61: Fermoy 2022 Q2 Cork East 11
R21: Mhuine Bheag 2022 Q2 Carlow-Kilkenny 11
R45: Edenderry 2022 Q2 Laois-Offaly 11
V14: Shannon 2022 Q2 Clare 11
F42: Roscommon 2022 Q2 Roscommon-Galway 10
V15: Kilrush 2022 Q2 Clare 10
H14: Belturbet 2022 Q2 Cavan-Monaghan 9
K34: Skerries 2022 Q2 Dublin Fingal 9
N41: Carrick-on-Shannon 2022 Q2 Sligo-Leitrim 9
E25: Cashel 2022 Q2 Tipperary 8
P36: Youghal 2022 Q2 Cork East 8
V42: Newcastle West 2022 Q2 Limerick County 8
X42: Kilmacthomas 2022 Q2 Waterford 8
X35: Dungarvan 2022 Q2 Waterford 7
D14: Dublin 14 2022 Q2 Dublin Bay South 6
P67: Mitchelstown 2022 Q2 Cork East 6
P75: Bantry 2022 Q2 Cork South-West 6
R14: Athy 2022 Q2 Kildare South 6
E21: Cahir 2022 Q2 Tipperary 5
A42: Garristown 2022 Q2 Dublin Fingal 4
D11: Dublin 11 2022 Q2 Dublin West 4
F31: Ballinrobe 2022 Q2 Mayo 4
F52: Boyle 2022 Q2 Sligo-Leitrim 4
H16: Cootehill 2022 Q2 Cavan-Monaghan 4
E53: Roscrea 2022 Q2 Tipperary 3
F35: Ballyhaunis 2022 Q2 Mayo 3
F56: Ballymote 2022 Q2 Sligo-Leitrim 3
P56: Charleville 2022 Q2 Cork North-West 3
A41: Ballyboughal 2022 Q2 Dublin Fingal 2
A45: Oldtown 2022 Q2 Dublin Fingal 2
A84: Ashbourne 2022 Q2 Meath East 2
D6W: Dublin 6W 2022 Q2 Dublin South Central 2
H71: Clifden 2022 Q2 Galway West 2
V23: Caherciveen 2022 Q2 Kerry 2
D10: Dublin 10 2022 Q2 Dublin South Central 1
D20: Dublin 20 2022 Q2 Dublin South Central 0
P32: Rylane 2022 Q2 Cork North-West 0