library(plotly)
library(dplyr)

ds <- read.csv2("logements_sociaux_finances_a_paris.csv",encoding = "UTF-8")

head(ds)
##                    adresse année.agrément  bailleur nombre.total.de.logements.financés dont.nombre.de.logements.PLUS dont.nombre.de.logements.PLUS.CD
## 1 6, PASSAGE DES TOURELLES           2015      RIVP                                 12                            NA                               NA
## 2            6, RUE COURAT           2002 LOGIS.TR.                                 35                            NA                               NA
## 3      6, RUE DE CHAMBIGES           2012 PARIS HAB                                  2                             2                               NA
## 4       6, RUE DE LORRAINE           2016  SABLIERE                                 42                            10                               NA
## 5      6, RUE DES PANOYAUX           2009     SIEMP                                 12                            10                               NA
## 6         6, RUE DESARGUES           2007     SIEMP                                  1                            NA                               NA
##   dont.nombre.de.logements.PLA.I dont.nombre.de.logements.PLS          mode.de.réalisation Commentaires arrondissement nature.de.programme
## 1                             NA                           12 acquisition conventionnement                       75020   logement familial
## 2                             NA                           35 acquisition conventionnement                       75020   logement familial
## 3                             NA                           NA acquisition conventionnement                       75008   logement familial
## 4                             NA                           32           construction neuve                       75019   logement familial
## 5                              2                           NA           construction neuve                       75020   logement familial
## 6                             NA                            1   acquisition réhabilitation                       75011   logement familial
##                    xy
## 1 48.875211, 2.404254
## 2  48.85674, 2.405643
## 3 48.866815, 2.303724
## 4   48.884291, 2.3844
## 5 48.866278, 2.384809
## 6 48.869594, 2.376285
ds <- ds %>% select(Year = année.agrément,
                    NumberOfAppartments = nombre.total.de.logements.financés,
                    TypeOfRealisation = mode.de.réalisation,
                    Area = arrondissement,
                    Program = nature.de.programme) %>%
             group_by(Year, TypeOfRealisation, Area, Program) %>%
             summarize(nbAppart = sum(NumberOfAppartments))

levels(ds$TypeOfRealisation) <- c("Conventional acquisition","Relocation","New construction")
levels(ds$Program) <- c("Emergency shelter",
                        "Shelter and social reintegration",
                        "Accommodation facility for dependent elderly people",
                        "Home of migrant workers",
                        "Home for young workers or residence for young people",
                        "Home for the disabled",
                        "Family housing",
                        "Relay house",
                        "Residence for students",
                        "Retirement home",
                        "Social residence for no one",
                        "Relocation site of migrant worker's home")

g <- ggplot(ds, aes(x=Year,y=nbAppart, group=Program)) + 
     geom_col(aes(fill=Program)) + 
     facet_wrap(.~TypeOfRealisation) + 
     theme_minimal() + 
     ggtitle(label = "Number of financed social apppartments in Paris",
             subtitle = "Week 3 course project by Grigory Sharkov. 29/08/2018") + 
     ylab("Number of appartments")

ggplotly(g)