---
title: "CDP Challenge: Climate Adaptation Index"
author: "Saif Shabou"
date: "25/11/2020"
output: 
  html_document:
    toc: true
    toc_depth: 3
    theme: spacelab
    highlight: tango
    number_sections: yes
    code_folding: hide
---

```{r warning=FALSE, message=FALSE, echo = TRUE}

library(rgeos)
library(tidyverse)
library(sp)
library(sf)
library(dplyr)
library(leaflet)
library(RColorBrewer)
library(knitr)
library(kableExtra)
library(plotly)
```

# Introduction

## The Carbon Disclosure Project

The Carbon Disclosure Project (CDP) is a global non-profit that drives companies and governments to reduce their greenhouse gas emissions, safeguard water resources, and protect forests. Each year CDP supports companies, cities, states and regions to measure and manage their risks and opportunities on climate change by implementing **disclosure** processes. The information supplied in the annual reporting responses are used for **scoring companies and cities** on their journey through disclosure. Hence, CDP houses the world’s largest, most comprehensive **dataset on environmental action**. 

## Data analytic challenge

This Kaggle analytic challenge consists of exploring and analyzing social and environmental information provided to CDP by disclosing companies and cities in order to help in identifying solutions to tackle climate change impacts.
The main questions defined by the challenge organizer are:

- **Helping cities adapt:** How do we help cities adapt to a rapidly changing climate in a way that is socially equitable?
- **Cities/corporation cooperation:** What are the practical and actionable points where city and corporate ambition join? Where do cities have problems that corporations affected by those problems could solve, and vice-versa?
- **Environmental risks & Social equity:** How can we measure the intersection between environmental risks and social equity?

In order to answer these question, two main goals are defined:

>Calculating KPIs that relate to the environmental and social issues and demonstrating whether city and corporate ambitions take these factors into account

>Leverage external data sources and discuss the intersection between environmental and social issues 

## Outline

The reminder of this article is organized as follows. **The next section** presents a literature review of previous studies and projects in relation with cities’ and governments' efforts in implementing climate adaptation solutions by highlighting social equity issues, city-business collaboration and methodologies for building indicators systems. 

In **section 3**, we describe our methodology for evaluating cities’ vulnerability and readiness for climate change impacts and we illustrate main findings and obtained KPIs. 

**Section 4** combines city advancement in implementing climate policies with the number of corporate responders to the CDP climate change questionnaire. 

**The last section** summarizes our methodological process and findings and lists methodological improvements and further analysis needed to reinforce the accuracy of obtained results.

# Domain knowledge


Cities are considered as the drivers of national economic development. With the fast increasing urbanization and resulting GHG emissions, important efforts are needed by cities to design and implement climate change adaptation policies.  In order to develop effective strategies, reliable and standardized data need to be collected. While various data collection programsare developed in national scale, more efforts are needed to collect data in city scale and address cities population disparities in their capacity to adapt to climate change.
Therefore, several initiatives are integrating city scale objectives and aiming at helping local organizations for tackling climate change by collecting data and building indicators and city scoring systems ([CDP](https://www.cdp.net/en), [C40 Cities](https://www.c40.org/), [United 4 Smart Sustainable Cities](https://www.itu.int/en/ITU-T/ssc/united/Pages/default.aspx)...)

Three issues are particularly highlighted by these programs: 

- Integrating **social equity** dimension when measuring cities’ vulnerability to climate impacts
- Increasing **city-companies collaboration** 
- Developing effective and reliable **indicators systems** for assessing and monitoring organizations' progress 

## Social equity & climate change

Countries that are least responsible for climate change are the most potentially vulnerable to negative impacts and possess least resources to adapt to its consequences. 
In order to promote environmental justice and social equity , we need to take into account population and countries’ **vulnerability and adaptation capacity** to climate change impacts and integrate it in public policies and environmental regulations procedures.

**Social equity** implies allocating resources to the population according to their level of need by prioritizing those whose level of need is considered to be greater. Social policies should then be designed in a way that improves the circumstances of the most vulnerable groups.

Numerous studies have highlighted the **multidimensional nature of vulnerability**, and hence social inequality face of climate impacts. Three dimensions are usually examined when studying soocial vulnerability:

- **Exposure** to negative impacts (for example exposure of cities to natural hazards)
- **Sensitivity** and susceptibility to damages and impacts (for example when a city is economically dependent on specific sector highly affected by climate change)
- **Adaptive capacity** and availability of social resources to cope with climate challenges

## City-Corporation collaboration

A city-Business collaboration in climate actions is important to maximize the assets of each actor to achieve a greater environmental adaptation actions. [City-Business Climate Alliance](https://www.city-businessclimatealliance.org/), for instance, is considered as a strategic initiative aiming at uniting the ambitions and efforts of city and business leaders. Intersections between cities and corporates strategies may have different facets:

- Identifying companies and sectors that are the largest contributors to cities’ emissions
- Identifying companies with major presence in the city and assessing their priorities for addressing climate change
- Increasing collaboration with companies that have already made commitments to sustainability (RE100, EV100…)
- Alignement of companies priorities to city strategy

## Indicators and indices

### Building indicators and indices 

Building indicator systems can be very helpful when studying and monitoring complex and multi-dimensional socio-environmental phenomena. With standardized indicators, countries, cities and organizations can evaluate their performance in implementing environmental policies and their capacity in conducting them.
However, this requires collecting complete, robust and precise data. Computing indicators over wide range of countries and over long time period enables performing various analysis:

- **Comparative analysis** for assessing progress compared to other similar entities
- **Temporal analysis** for identifying main trends and significant changes and measuring progress over time
- **Spatial analysis** for assessing spatial distribution and disparities of population vulnerability and adapting capacity to climate change impacts


In addition to indicators, **indices** are considered as a more concise alternative to summarize multi-dimensional information. They are built by combining  several metrics mathematically in order to generate a single summary indicator. It requiress the **normalization** of a subset of relevant metrics in a way that removes the impact of varying scales (by scaling, for example, data into similar ranges: 0 to 1; 0 to 100; -1 to +1), normalization to a common mean and standard deviation, or converting the data to ranked values.

### Examples

- **SDG indicators:** [The Sustainable Development Goals (SDGs)](https://unstats.un.org/sdgs/) are a collection of 17 goals designed to monitor progress to various sustainability targets defined by the United Nations 2030 agenda (No Poverty,  Clean water and sanitation, Sustainable cities and communities, Climate Action...). To achieve these goals, several data and indicators are collected, standardized and published. You can find [here](https://unstats.un.org/sdgs/indicators/indicators-list/) the complete lists of these goals. A [Kaggle dataset](https://www.kaggle.com/theworldbank/sustainable-development-goals) with SDGs indicators is provided and maintained by World Bank organization. The map below shows, for example, the geographical distribution of Gross National Product (GNP) index for the year of 2019.

```{r warning=FALSE, message=FALSE, echo = TRUE}

# load SDG from World Bank database (Kaggle dataset)
SDGData = read.csv("../input/sustainable-development-goals/sdg-csv-zip-7-mb-/SDGData.csv")

# reshape data (Kaggle)
SDGData_long = SDGData %>%
   pivot_longer(cols = -c("Country.Name","Country.Code","Indicator.Name","Indicator.Code","X"), 
                names_to = "Year", values_to = "Value") %>% 
   mutate(Year = gsub(pattern = "X", replacement = "",Year)) %>% 
   mutate_at("Year", as.numeric) %>% 
   select(Country.Code,Indicator.Name,Indicator.Code,Year,Value)


# select KPI og the last year
SDGData_long_KPI = SDGData_long %>%
  filter(Indicator.Code == "NY.GNP.PCAP.CD") %>% 
  drop_na(Value) %>% 
  group_by(Country.Code) %>%
  slice(which.max(Year)) %>% 
  select(Country.Code.3 = Country.Code, Country.KPI.GNP.PerCapita = Value) 

# Get countries geo-boundaries
world_geo <- rnaturalearth::ne_countries(scale = 50, returnclass = "sf")

# join geometry with data
SDGData_geo <- left_join(world_geo, SDGData_long_KPI, by = c("iso_a3" = "Country.Code.3"))


# plot map
qpal <- colorQuantile("RdYlBu", 
                      SDGData_geo$Country.KPI.GNP.PerCapita, 
                      n = 5,
                      reverse = FALSE)

labels <- sprintf("<strong>%s</strong><br/>%s: %s %s",
                  SDGData_geo$name, "GNP Per Capita",round(SDGData_geo$Country.KPI.GNP.PerCapita, 2), "") %>% 
  lapply(htmltools::HTML)

Map_SDG <- 
  leaflet(SDGData_geo, height = 400, width = "100%") %>%
  setView(20,25, zoom = 1) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~qpal(Country.KPI.GNP.PerCapita),
    weight = 1,
    opacity = 1,
    color = "grey",
    fillOpacity = 0.7,
    label = labels,
    highlightOptions = highlightOptions(color = "black", weight = 2,
                                        bringToFront = TRUE),
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 6px"),
      textsize = "15px",
      direction = "auto")) %>%
  addLegend(pal = qpal, values = ~Country.KPI.GNP.PerCapita, opacity = 0.9, 
            title = "GNP Per Capita (Quantile)",
            position = "bottomright",
            labFormat = labelFormat(suffix = "")) 

Map_SDG
```

- **United 4 smart Sustainable Cities (U4SSC):** [The U4SSC](https://www.itu.int/en/ITU-T/ssc/united/Pages/default.aspx) developed a set of international KPIs for Smart Sustainable Cities to establish the criteria to evaluate Information and communication technologies’s contributions in making cities smarter and more sustainable, and to provide cities with the means for self-assessments in order to achieve the sustainable development goals (SDGs).  The U4SSC KPIs consist of 91 indicators refering to three dimensions: Economy, Environment and Society. 


- **Human Development Index:** [The Human Development Index (HDI)](http://hdr.undp.org/en/countries) provides a single index measure to capture three dimensions of human development: long and healthy life, access to education and decent standard of living. The HDI data is regularly published by the United Nations Development Program providing measures starting in 1990: [HDI data exploration tool](http://hdr.undp.org/en/data).

- **ND-GAIN Country Index:** [Notre Dame Global Adaptation Index (ND-GAIN)](https://gain.nd.edu/our-work/country-index/) summarizes socio-environmental metrics to assist decision-makers for identifying and prioritizing adaptation measures in order to better allocate investment. 
It is based on a compilation of 45 indicators extracted directly from external data sources or computed by transforming underlying data. It proposed an aggregated index combining **two dimensions of adaptation: vulnerability and readiness**. A kaggle dataset containing the ND-GAIN data is provided [here](https://www.kaggle.com/shabou/ndgain-country-index). We used this data to produce the map below illustrating the geographical distribution of ND-GAIN index for the year of 2018.
 

```{r warning=FALSE, message=FALSE, echo = TRUE}

# read ND-GAIN data (Kaggle data)
NDGAIN_vulnerability = read.csv("../input/ndgain-country-index/vulnerability.csv")
NDGAIN_readiness = read.csv("../input/ndgain-country-index/readiness.csv")
NDGAIN_gain= read.csv("../input/ndgain-country-index/gain.csv")


# subset last year and join datasets

NDGAIN_readiness_2018 = NDGAIN_readiness %>% 
  select(ISO3, Name, Country.Readiness = X2018)

NDGAIN_vulnerability_2018 = NDGAIN_vulnerability %>% 
  select(ISO3, Name, Country.Vulnerability = X2018)

NDGAIN_gain_2018 = NDGAIN_gain %>% 
  select(ISO3, Name, Country.GAIN = X2018)

NDGAINs_2018 = NDGAIN_gain_2018 %>% 
  left_join(NDGAIN_readiness_2018[ ,c("ISO3","Country.Readiness")], by = "ISO3") %>% 
  left_join(NDGAIN_vulnerability_2018[ ,c("ISO3","Country.Vulnerability")], by = "ISO3") %>% 
  mutate_at("ISO3", as.character)

# join geometry with data
NDGAINs_2018_geo <- left_join(world_geo, NDGAINs_2018, by = c("iso_a3" = "ISO3"))

# build map of GAIN score

pal <- colorNumeric("RdYlBu", 
                    domain = NDGAINs_2018_geo$GAIN,
                    reverse = FALSE)

labels <- sprintf("<strong>%s</strong><br/>%s: %s %s",
                  NDGAINs_2018_geo$Name, "GAIN",round(NDGAINs_2018_geo$Country.GAIN, 2), "") %>% 
  lapply(htmltools::HTML)

Map_NDGAINs_2018_GAIN <- 
  leaflet(NDGAINs_2018_geo, height = 400, width = "100%") %>%
  setView(20,25, zoom = 1) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~pal(Country.GAIN),
    weight = 1,
    opacity = 1,
    color = "grey",
    fillOpacity = 0.7,
    label = labels,
    highlightOptions = highlightOptions(color = "black", weight = 2,
                                        bringToFront = TRUE),
    labelOptions = labelOptions(
      style = list("font-weight" = "normal", padding = "3px 6px"),
      textsize = "15px",
      direction = "auto")) %>%
  addLegend(pal = pal, values = ~Country.GAIN, opacity = 0.9, 
            title = "GAIN index",
            position = "bottomright",
            labFormat = labelFormat(suffix = ""))

Map_NDGAINs_2018_GAIN


```

# Building City Adaptation Index

## Method

The goal in this analysis consists of extracting insightful KPIs from disclosure data and providing indices to summarize cities performance in climate adaptation actions with respect to social equity issues. By consedring both vulnerability and readinss dimensions of adaptations metrics, the ND-GAIN methodology presents an appropriate framework for our study. Hence, we propose to perform an adaptation of ND-GAIN index in city scale, based on indictaors extracted from cities' responses.

![ ](https://raw.githubusercontent.com/S-AI-F/CDP-Kaggle/main/Method.png)

The diagram above presents the different steps implemented in this study:

1- **Generating cities KPI dataset:** In this part we extract multiple indicators by implementing systematic analysis of cities responses data.

2 - **Aggregating the different KPIs:** In this part we aggregate the multiple indicators into two main indices of vulnerability and readiness. For that, we will adapt the method used to compute ND-GAIN index to our city scale analysis.

3- **Multi-scale index**:Combining cities’ vulnerability and readiness index with their respective countries index by using ND-GAIN dataset.


## Cities KPI analysis

City questionnaire is composed of  11 sections addressing multiple dimensions of cities’ environmental and climate adaptation actions: 

- **Climate hazards and vulnerability:** Description of most significant climate hazards faced by cities and factors affecting adapting capacity
- **Adaptation:** Main adaptation actions undertaken to address climate change and reduce the risk and vulnerability to climate hazards.
- **Social risks:** Social risks resulting to climate change
- **City wide emissions:** Summary of city-wide GHG emissions by various sectors and scopes depending in selected inventories 
- **Emission reduction:** Description of emission reduction targets and mitigation actions and planning.
- **Opportunities:** Description of opportunities resulting from addressing climate change and collaborations with businesses.
- **Energy:** Description of source mix of electricity consumed in the city and renewable energy target
- **Transport:** Details of transport mode share and concentration of air pollutants gases within city wide.
- **Food:** Food consumption KPIs and description of sustainable food policies and actions.
- **Waste:** Amount’ of solid waste generation, collection and treatment.
- **Water:** Description source of water supply/security and water management actions and strategy.


```{r warning=FALSE, message=FALSE, echo = TRUE}

# get city responses data (Kaggle dataset)
Cities_Responses_2018 = read.csv("../input/cdp-unlocking-climate-solutions/Cities/Cities Responses/2018_Full_Cities_Dataset.csv",
                                  na.strings="")
Cities_Responses_2019 = read.csv("../input/cdp-unlocking-climate-solutions/Cities/Cities Responses/2019_Full_Cities_Dataset.csv",
                                  na.strings="")
Cities_Responses_2020 = read.csv("../input/cdp-unlocking-climate-solutions/Cities/Cities Responses/2020_Full_Cities_Dataset.csv",
                                  na.strings="")

# merge answers
Cities_Responses = rbind(Cities_Responses_2018,Cities_Responses_2019,Cities_Responses_2020)


```

We conducted in [this kernel](https://www.kaggle.com/shabou/exploratory-analysis-of-cities-responses) an exploratory analysis of cities answers by implementing systematic descriptive statistics of the different sections and focusing on the last disclosure year (2020).

This exploratory analysis has two main objectives:

- Identifying and discussing main trends and metrics to get insights and knowledge of city disclosure
- Building a complete and comprehensive dataset summarizing cities‘ responses on a finite number of standardized indicators that we called Cities-KPI-Dataset

The generated dataset is provided in [Kaggle public datasets](https://www.kaggle.com/shabou/cdpchallengecitieskpi) with corrsponding documentation.

```{r warning=FALSE, message=FALSE, echo = TRUE}

# get city KPI (Kaggle dataset)
CDP_Cities_KPI = read.csv("../input/cdpchallengecitieskpi/CDP-Cities-KPI.csv",fileEncoding = "UTF-8")

# remove duplicate rows
CDP_Cities_KPI = CDP_Cities_KPI %>% 
  distinct(Account.Number, .keep_all = TRUE)

# Show sample 
CDP_Cities_KPI %>% 
  top_n(10) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13) %>% 
  scroll_box(width = "100%", height = "400px")

```


Based on the ND-GAIN framework (described in section 2.3.2), we classify the resulting indicators into two categories: 

- **Vulnerability KPIs:** They measure overall city vulnerability to the negative impacts of climate change by considering three components: exposure, sensitivity and adapting capacity .
- **Readiness KPIs:** They measure city advancement on implementing climate adaptation policies and GHG emission reduction strategies by considering various sectors (risk assessment, ghg emissions, energy, transport, water, adaptation planning…)


The table below presents the categorization of cities indicators:

| Component | Sub component | Indicators  |
| --------- | --------- | ---------  |
| Vulnerability | Exposure | Hazards.Exposure.Level  |
|  | Sensitivity | Risk.Health.System \n Potable.Water.Supply.Percent  |
|  | Adapting challenge | Adaptation.Challenges.Level  |
| Readiness |  | Sustainability.Targets.Master.Planning \n Risk.Assessment.Actions \n Adaptation.Plan \n GHG.Emissions.Consumption \n GHG.Emissions.External.Verification \n Emissions.Reductions.Mitigation.Planning  Opportunities.Collaboration \n Renewable.Energy.Target \n Energy.Efficnecy.Target \n Water.Resource.Management.strategy \n Low.Zero.Emission.Zone \n GHG.Emissions.Evolution \n GHG.Emissions.Reductions.Targets \n Electricity.Source.Renewable \n Food.Consumption.Policies \n City.Wide.Emissions.Inventory |

### Vunerability KPIs

- **Exposure:**

To answer to the question 2.1 of the questionnaire, cities listed the most significant climate hazards to wich they are exposed by evaluating their severity in terms of probability and  magnitude. The figure belows presents answers' distribution showing that the majority of reported climate hazards are characterized by high probablity and magnitude.

```{r warning=FALSE, message=FALSE, echo = TRUE}
Year.Selected = 2020

Cities_Responses %>% 
  filter(Question.Number == "2.1",
         Year.Reported.to.CDP == Year.Selected,
         Column.Number %in% c(3,4)) %>% 
  select(Account.Number,Column.Name,Row.Number,Response.Answer) %>% 
  drop_na(Response.Answer) %>% 
  group_by(Column.Name, Response.Answer) %>% 
  summarise(nb = n()) %>% 
  mutate(Percent = round(nb/sum(nb) * 100,2)) %>% 
  mutate_at("Response.Answer", as.character) %>% 
  plot_ly() %>% 
  add_trace(x = ~Response.Answer, 
            y = ~Percent, 
            color = ~factor(Column.Name),
            colors = c("blue","grey"),
            type = "bar")  %>% 
  layout(title = "Probability & Magnitude of Hazards",
         yaxis = list(title = 'Percent of answers',range = c(0, 35)), 
         xaxis = list(categoryorder = "array",
                      categoryarray = c("High", 
                                        "Medium High",
                                        "Medium",
                                        "Medium Low",
                                        "Low",
                                        "Do not know",
                                        "Does not currently impact the city"), 
                      title = "Levels"),
         barmode = 'group')
```

We proposed the use of weighted sum method for combining hazards’ probabilities and magnitude in one exposure level indictor by following these steps:

  1- Recoding values by converting the categorical ordinal variables into numerical values: High (5), Medium High (4), Medium (3), Medium Low (2), Low (1), Does not currently impact the city (0).
  
  2- Applying a weighted sum of hazards magnitude $M_{i}$ and probability $P_{i}$ values. For example, if a city $C_1$ reports 3 hazards $H_{1}$, $H_{2}$, and $H_{3}$ with respectively $[M_{1}, P_{1}]$, $[M_{2}, P_{2}]$, and $[M_{3}, P_{3}]$, its  exposure level is calculated folowing this formula: 
  
$$Exposure_{city} =\sum_{x = i}^{nb_{hazards}} Magnitude_{i} * Probability_{i}$$
While the resulting exposure metric summarizes the reported data, this method is highly sensitive to **subjective city risk perception and knowledge bias** (for instance, no answers implies a null exposure level). Therefore, exposure assessement needs to be coupled with environmenatal and **ground truth data** such as hazrads impact observations.

- **Sensitivity :**

Sensitivity is defined here as a measure of **population susceptibility to climate change hazards**. Hence, cities with less efficient health system and water supply management are considered more sensitive to climate hazards. However, more sensitivy indicators should be explored by addresssing various sectors such as economic sensisitivy related to dependancy to one specific sector.

- **Adapting challenge:**

Adapting capacity is considered as an important component to better evaluate social vulnerabilty to climate hazards. In **section 2.2** of the questionnaire, cities are asked to identify and describe factors that affect their ability to adapt to climate change. We grouped these factors into 8 categories: Economic (poverty, unemployement...), health, education (access to education), habitat, infrastructure (infrastructure conditions and capacity), social (inequality, migration), environment (resource availability), and governance (political stability, community engagement ,access to relevant data, political engagement). The figure below shows the distribution of these adaptattion challenges and we observe that the main challenging factors are related to economic, infrastructure and governance sectors


```{r warning=FALSE, message=FALSE, echo = TRUE}
Cities_Responses_Cleaned = Cities_Responses %>% 
  filter(Question.Number == "2.2",
         Year.Reported.to.CDP == Year.Selected,
         Column.Number %in% c(1,2, 3)) %>% 
  select(Account.Number, Column.Name, Response.Answer, Row.Number)


# reshape data 
Cities_Responses_Cleaned = reshape(Cities_Responses_Cleaned, 
                                   idvar = c("Account.Number","Row.Number"), 
                                   timevar = "Column.Name", 
                                   direction = "wide")
# rename columns
names(Cities_Responses_Cleaned) = c("Account.Number","Row.Number","Adaptation.Factors.Impact","Level","Adaptation.Factors")

# Responses recoding
Cities_Responses_Cleaned = Cities_Responses_Cleaned %>% 
  filter(Adaptation.Factors.Impact == "Challenges",
         Level == "Significantly challenges") %>% 
  mutate(Adaptation.Factors.Grouped = fct_collapse(Adaptation.Factors,
                                                   "Adaptation.Challenges.Economic" = c("Access to basic service","Cost of living",
                                                                                        "Poverty","Unemployment","Economic health",
                                                                                        "Economic diversity","Budgetary capacity"),
                                                   "Adaptation.Challenges.Health" = c("Access to healthcare","Public health"),
                                                   "Adaptation.Challenges.Education" = c("Access to education"),
                                                   "Adaptation.Challenges.Habitat" = c("Housing"),
                                                   "Adaptation.Challenges.Infrastructure" = c("Rapid urbanization",
                                                                                              "Infrastructure conditions / maintenance","Infrastructure capacity"),
                                                   "Adaptation.Challenges.Social" = c("Inequality","Migration"),
                                                   "Adaptation.Challenges.Environment" = c("Resource availability","Environmental conditions"),
                                                   "Adaptation.Challenges.Governance" = c("Safety and security","Political stability",
                                                                                          "Political engagement / transparency", "Government capacity",
                                                                                          "Community engagement","Land use planning","Access to quality / relevant data"))) %>% 
  filter(Adaptation.Factors.Grouped %in% c("Adaptation.Challenges.Economic","Adaptation.Challenges.Health",
                                           "Adaptation.Challenges.Education","Adaptation.Challenges.Infrastructure",
                                           "Adaptation.Challenges.Social","Adaptation.Challenges.Environment",
                                           "Adaptation.Challenges.Governance")) %>% 
  # counring factors by city
  group_by(Account.Number,Adaptation.Factors.Grouped) %>% 
  summarise(Adaptation.Challenges.Nb=n()) %>% 
  select(Account.Number, Adaptation.Factors.Grouped, Adaptation.Challenges.Nb)

# plot most significant adaptation challenges

Cities_Responses_Cleaned %>% 
  group_by(Adaptation.Factors.Grouped)%>%
  summarise(Nb.Organizaton = sum(Adaptation.Challenges.Nb))  %>% 
  arrange(desc(Nb.Organizaton)) %>% 
  plot_ly() %>% 
  add_trace(y = ~factor(Adaptation.Factors.Grouped), 
            x = ~Nb.Organizaton, 
            marker = list(color = "gray"),
            type = "bar",
            orientation = "h")  %>% 
  layout(title = "Most Significant Adaptation challenges",
         yaxis = list(title = '', categoryorder = "array",categoryarray = ~Nb.Organizaton),
         xaxis = list(title = 'Number of cities faced to challenges')
  )
```

In order to build an indicator summarizing provided information on adpatation challenges, we calculated for each city the number of reported highly challenging factors. We assume here that *more reported challenging factors indicate less adpatation capacity*. However, our assumption is highly sensitive to reporting bias since selecting an important number of challenging factors may be due to a greater knoweldge and awareness of adaptive capacity.


### Readiness KPIs

The questionnaire conatins multiple questions atempting to collect information about cities' advancement in implementing climate adaptation policies. They concern various sectors such as risk assessment, renewale energy target definition, transport, food consumption policiesn GHG emission reduction targets... By converting answers into categorical ordinal indicators, we can obtain insights on cities' advancement in implementing climate chage policies.

```{r warning=FALSE, message=FALSE, echo = TRUE}
pal <- c("gray","blue","deepskyblue","orange","forestgreen", "red")

CDP_Cities_KPI %>% 
  select(Risk.Assessment.Actions,Adaptation.Plan,City.Wide.Emissions.Inventory,
         Opportunities.Collaboration,Renewable.Energy.Target,Food.Consumption.Policies) %>% 
  pivot_longer(cols = c("Risk.Assessment.Actions","Adaptation.Plan",
                        "City.Wide.Emissions.Inventory","Opportunities.Collaboration",
                        "Renewable.Energy.Target","Food.Consumption.Policies"),
               names_to = "KPI", values_to = "Answer") %>% 
  drop_na(Answer) %>%
  group_by(KPI, Answer) %>% 
  summarise(nb = n()) %>% 
  plot_ly() %>% 
  add_trace(x = ~KPI, 
            y = ~nb, 
            color = ~factor(Answer),
            colors = pal,
            type = "bar",
            text = ~paste("Answer: ", Answer, '<br>Number:', nb))  %>% 
  layout(yaxis = list(title = 'Count'), 
         xaxis = list(title = ''),
         barmode = 'stack',
         legend = list(orientation = 'h', x = 0.2, y = -0.5))

```

## Building city vulnerability and readiness index

### Vulnerability index

We consider that vulnerability metric is based on three main components: exposure, sensitivity and adapting challenges. We present in this section the method used for computing each component and combining them in one metric.

_______________________________________________________________________________

-**Exposure Index:** 

The Exposure index ($Exp_{city}$) is calculated by normalizing exposure level indicator using min-max method. 

$$Exp_{city} = \frac {ExposureLevel_{city} - min(ExposureLevel_{city})}{max(ExposureLevel_{city}) - min(ExposureLevel_{city})}$$

```{r warning=FALSE, message=FALSE, echo = TRUE}
range01 <- function(x){(x-min(x))/(max(x)-min(x))}

CDP_Cities_KPI = CDP_Cities_KPI %>% 
  
  # Compute Hazards.Exposure.Level
  mutate_at(c("Hazards.Exposure.Level"), ~replace_na(., 0)) %>% 
  # Normalize Hazards.Exposure.Level
  mutate(City.Exposure.Index = range01(Hazards.Exposure.Level))
```

The most exposed cities to climate hazards impacts in terms of both porbability of occurence and severity are: *City of Urbana (USA), KwaDukuza (South Africa), and Rio de Janiero (Brazil)*. However, we observe that 46 cities are assigned with null exposure index such as *Tokyo (Japan), San Diego (USA) and Montréal (Canada)*. Null exposure are mainly due to lack of reporting and absence of answers. External data is then needed to improve exposure index.

```{r warning=FALSE, message=FALSE, echo = TRUE}
# Print the most exposed cities
CDP_Cities_KPI %>% 
  select(Organization,Country,City.Exposure.Index) %>% 
  arrange(desc(City.Exposure.Index)) %>% 
  top_n(3, City.Exposure.Index) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13) 
```


_______________________________________________________________________________

-**Sensitivity Index:** 

Sensitivty index ($Sen_{city}$) is based on a combination of two indicators: 

- *"Risk.Health.System":* where cities are indicating if they face risks to public health systems associated with climate change. This variable is recoded and normalized in a way that a positive answer implies highest level of sensitivity (1) and negative answer implies the null lelvel of sensitivity. 
- *"Potable.Water.Supply.Percent":* It presents the percentage of city's population having potable water supply service. This variable is recoded and normalized linearly in way that lower percent of population having potable water suply services indicates higher sensitivity.

The sensitivity index ($Sen_{city}$) is then computed as the arithmetic mean of sentivities related to health system and potable water supply. Results show that the most sensitive cities are *Taoyuan City (Taiwan), Yeosu (Republic of Korea), and Lagos (Nigeria)*. 

```{r warning=FALSE, message=FALSE, echo = TRUE}
CDP_Cities_KPI = CDP_Cities_KPI %>% 
  
  #### Recode Risk.Health.System
  mutate_at(c("Risk.Health.System"), 
            ~as.numeric(recode(.,
                               "Yes"=1, 
                               "No"=0,
                               "Do not know"=0))) %>% 
  mutate_at("Risk.Health.System", ~replace_na(., 0)) %>% 
  
  #### Recode Potable.Water.Supply.Percent
  mutate_at("Potable.Water.Supply.Percent", ~replace_na(., 100)) %>% 
  mutate(Potable.Water.Supply.Vulnerability = 100 - Potable.Water.Supply.Percent) %>% 
  
  #### Normalize Risk.Health.System & Potable.Water.Supply.Percent
  mutate_at(vars(Risk.Health.System, Potable.Water.Supply.Vulnerability), range01) %>% 
  
  #### Compute City.Sensitivity.score
  mutate(City.Sensitivity.Index = select(., c("Risk.Health.System","Potable.Water.Supply.Vulnerability")) 
         %>% apply(1, mean, na.rm=TRUE))

# Print the most sensitive cities
CDP_Cities_KPI %>% 
  select(Organization,Country,City.Sensitivity.Index) %>% 
  arrange(desc(City.Sensitivity.Index)) %>% 
  top_n(3, City.Sensitivity.Index) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13) 

```


_______________________________________________________________________________

-**Adapting challenge Index:** 

Adapting challenge index ($Adp_{city}$) is based on the normalized sum of reported significant adaptation challenges. Although this index may give information about importance of challenges facing cities for adapting to climate change impacts, it is highlly sensitive to disclosure bias. Results show, for example, that Houston and Paris are facing highest number of adaptation challenges.


```{r warning=FALSE, message=FALSE, echo = TRUE}
CDP_Cities_KPI = CDP_Cities_KPI %>% 
  
  # Compute Adaptation.Challenges.Index
  mutate_at(c("Adaptation.Challenges.Level"), ~replace_na(., 0)) %>% 
  mutate(City.Adaptation.Challenges.Index = range01(Adaptation.Challenges.Level)) 
  
# Print the most sensitive cities
CDP_Cities_KPI %>% 
  select(Organization,Country,City.Adaptation.Challenges.Index) %>% 
  arrange(desc(City.Adaptation.Challenges.Index)) %>% 
  top_n(3, City.Adaptation.Challenges.Index) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13)   
```

_______________________________________________________________________________

-**Vulnerability Index:** 

City vulnerability index $(Vul_{city})$ is obtained by calculating the arithmetic mean of exposure $(Exp_{city})$, sensitivity $(Sen_{city})$ and adapting challenges index $(Adp_{city})$. 

In order to improve the index effectiveness, we combine it with countries' vulnerability index provided by ND-GAIN database. Although this method reduce within country variablity, it enables the use of rich information of social vunleability provided by indicators processed for computing ND-GAIN index.


$$Vul_{city}=\frac{Exp_{city}+Sen_{city}+Adp_{city}}{3} ; Vul_{city-coutry}= \frac{Vul_{city}+Vul_{country}}{2}$$

The results show that the most vulnerable cities are: *Kisumu (Kenya), Kampala (Uganda), Lagos (Nigeria)*. In the other side, cities located in Norway (Bærum , Arendal, Trondheim), Kemin (Finland) and Winchester (United Kingdom) are characterized by the lowest values of vulnerability.

```{r warning=FALSE, message=FALSE, echo = TRUE}
CDP_Cities_KPI = CDP_Cities_KPI %>% 
  # Compute City.Vulnerability.Index
  mutate(City.Vulnerability.Index = select(., c("City.Exposure.Index","City.Adaptation.Challenges.Index",
                                                "City.Sensitivity.Index")) 
         %>% apply(1, mean, na.rm=TRUE)) %>% 
  
  # Join Country vulnerability index
  mutate_at("Country.Code.3", as.character) %>% 
  left_join(NDGAINs_2018[,c("ISO3","Country.Vulnerability")], by = c("Country.Code.3" = "ISO3")) %>% 
  
  # Compute City.Country.Vulnerability
  mutate(City.Country.Vulnerability = select(., c("City.Vulnerability.Index","Country.Vulnerability")) 
         %>% apply(1, mean, na.rm=TRUE))

# plot map of vulnerability index

pal <- colorQuantile(palette = "RdYlBu", n = 5,
                domain = CDP_Cities_KPI$City.Country.Vulnerability,
                reverse = TRUE)

labels <- sprintf(
  "<strong>%s</strong><br/><strong>%s</strong><br/>",
  paste("Name", CDP_Cities_KPI$Organization, sep=": "), 
  paste("Vulnerability Index", round(CDP_Cities_KPI$City.Country.Vulnerability,2), sep =": ")
) %>% 
  lapply(htmltools::HTML)

leaflet(data = CDP_Cities_KPI, height = 400, width = "100%") %>% 
  addTiles() %>%
  addProviderTiles(providers$CartoDB.DarkMatter) %>% 
  addCircleMarkers(~long, ~lat, 
                   radius = 4,
                   color = ~pal(City.Country.Vulnerability),
                   stroke = FALSE,
                   fillOpacity = 0.7,
                   weight = 100,
                   popup = ~as.character(City), 
                   label = labels) %>% 
  addLegend(pal = pal, values = ~City.Country.Vulnerability, opacity = 0.9, 
            title = "Vulnerability index",
            position = "bottomright",
            labFormat = labelFormat(suffix = " "))

```

_______________________________________________________________________________

-**Method evaluation:**

In order to evaluate the relevance of the measured index, we computed the differences between city vulnerability index obtained from CDP indicators with country vulnerability index provided by ND-GAIN dataset (considered here as a reference point). Hence, we can evaluate over-estimation and under-estimation of cities' vunleraility. The table below shows cities with highest difference in vulnerability values compared to counry scale (Sydney, Rio de Janiero, Paris, Houston...). Our under-estimation is due to the high awareness of these cities of climate hazards and adaptation challenging factors.

```{r warning=FALSE, message=FALSE, echo = TRUE}

CDP_Cities_KPI = CDP_Cities_KPI %>% 
  mutate(Vulnerability.City.Country.Diff = City.Vulnerability.Index - Country.Vulnerability) 

# Print vulnerability over-estimation 
CDP_Cities_KPI %>% 
  select(Organization,Country,City.Vulnerability.Index,Country.Vulnerability,Vulnerability.City.Country.Diff ) %>% 
  arrange(desc(Vulnerability.City.Country.Diff)) %>% 
  top_n(3, Vulnerability.City.Country.Diff) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13)  

```

The table below presents cities where our index highly over-estimates vulnerability compared to country scale: Guanagazapa (Guatemala), Walvis Bay (Namibia), Banyuwangi (Indonesia)... This bias is clearly due to the incomplete disclosure and missing information reported by these cities. More efforts are then needed to help these cities build more detailed knowledge of their exposure and vulnerability to climate change impacts.


```{r warning=FALSE, message=FALSE, echo = TRUE}
# Print vulnerability under-estimation 
CDP_Cities_KPI %>% 
  select(Organization,Country,City.Vulnerability.Index,Country.Vulnerability,Vulnerability.City.Country.Diff ) %>% 
  arrange(desc(Vulnerability.City.Country.Diff)) %>% 
  top_n(-5, Vulnerability.City.Country.Diff) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13) 

```

### City readiness index

Indicators catagorized within readiness index participate to qualify cities' journey and actions through implementing climate change adaptation policies. In order to summarize these different indicators, we need to recode them and normalize their values. The recoding strategy consists of attributing higher values of readiness to cities that are more advanced in implementing adpatation policies and ghg emissions targets.

The results show that cities that are the most advanced in implementing cliamte change adaptation policies are Paris (France), Lund (Sweden), and Vancouver (Canda).

```{r warning=FALSE, message=FALSE, echo = TRUE}
CDP_Cities_KPI <- CDP_Cities_KPI %>% 
  
  # recode vars
  mutate_at(c("Sustainability.Targets.Master.Planning"), 
            ~as.numeric(recode(.,
                               "Yes"=3, 
                               "In progress"=2,
                               "Intending to incorporate in the next 2 years"=1,
                               "Not intending to undertake"=0,
                               "Do not know"=0))) %>% 
  # recode vars
  mutate_at(c("Risk.Assessment.Actions","Adaptation.Plan" ,"City.Wide.Emissions.Inventory","GHG.Emissions.Consumption",
              "GHG.Emissions.External.Verification","Emissions.Reductions.Mitigation.Planning",
              "Opportunities.Collaboration","Renewable.Energy.Target","Energy.Efficnecy.Target",
              "Water.Resource.Management.strategy"), 
            ~as.numeric(recode(.,
                               "Yes"=3, 
                               "In progress"=2,
                               "Intending to undertake in the next 2 years"=1,
                               "Not intending to undertake"=0,
                               "Do not know"=0))) %>% 
  # recode vars
  mutate_at(c("Low.Zero.Emission.Zone","Food.Consumption.Policies"), 
            ~as.numeric(recode(.,
                               "Yes"=1, 
                               "No"=0,
                               "Do not know"=0))) %>% 
  # recode vars
  mutate(GHG.Emissions.Evolution = as.numeric(as.character(fct_collapse(GHG.Emissions.Evolution,
                                                                        "2"="Decreased",
                                                                        "1"=  "Stayed the same",
                                                                        "0" = c("Do not know","This is our first year of calculation", 
                                                                                "Increased"))))) %>% 
  # recode vars
  mutate(GHG.Emissions.Reductions.Targets = as.numeric(as.character(fct_collapse(GHG.Emissions.Reductions.Targets,
                                                                                 "1"= c("Base year emissions (absolute) target",
                                                                                        "Base year intensity target",
                                                                                        "Baseline scenario (business as usual) target",
                                                                                        "Fixed level target"),
                                                                                 "0" = "No target")))) %>% 
  # replace NA by zero
  mutate_at(vars(Sustainability.Targets.Master.Planning, Risk.Assessment.Actions, Adaptation.Plan,
                 GHG.Emissions.Consumption, GHG.Emissions.External.Verification,
                 Emissions.Reductions.Mitigation.Planning,Opportunities.Collaboration,
                 Renewable.Energy.Target, Energy.Efficnecy.Target,
                 Water.Resource.Management.strategy,Low.Zero.Emission.Zone,GHG.Emissions.Evolution,
                 GHG.Emissions.Reductions.Targets,Electricity.Source.Renewable,Food.Consumption.Policies,
                 City.Wide.Emissions.Inventory), ~replace_na(., 0)) %>% 
  # Normalize values
  mutate_at(vars(Sustainability.Targets.Master.Planning, Risk.Assessment.Actions, Adaptation.Plan,
                 GHG.Emissions.Consumption, GHG.Emissions.External.Verification,
                 Emissions.Reductions.Mitigation.Planning,Opportunities.Collaboration,
                 Renewable.Energy.Target, Energy.Efficnecy.Target,
                 Water.Resource.Management.strategy,Low.Zero.Emission.Zone,GHG.Emissions.Evolution,
                 GHG.Emissions.Reductions.Targets,City.Wide.Emissions.Inventory,
                 Electricity.Source.Renewable, Food.Consumption.Policies), range01) %>% 
  # compute City.Readiness.Index
  mutate(City.Readiness.Index = select(., c("Sustainability.Targets.Master.Planning", "Risk.Assessment.Actions",
                                            "Adaptation.Plan","GHG.Emissions.Consumption","GHG.Emissions.External.Verification",
                                            "Emissions.Reductions.Mitigation.Planning", "Opportunities.Collaboration",
                                            "Renewable.Energy.Target","Energy.Efficnecy.Target",
                                            "Water.Resource.Management.strategy","Low.Zero.Emission.Zone",
                                            "GHG.Emissions.Evolution","GHG.Emissions.Reductions.Targets",
                                            "Electricity.Source.Renewable", "Food.Consumption.Policies",
                                            "City.Wide.Emissions.Inventory")) 
         %>% apply(1, mean, na.rm=TRUE))

# Print cities with highest readiness index
CDP_Cities_KPI %>% 
  select(Organization,Country,City.Readiness.Index) %>% 
  arrange(desc(City.Readiness.Index)) %>% 
  top_n(3, City.Readiness.Index) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13)   


```

However, some cities have a null score of readiness because of the absence of target definitions or missing values in disclosure repsonses: Seferihisar (Turkey), Guarulhos (Brazil), Apodaca (Mexico)...

```{r warning=FALSE, message=FALSE, echo = TRUE}
# Print cities with lowest readiness index
CDP_Cities_KPI %>% 
  select(Organization,Country,City.Readiness.Index) %>% 
  arrange(desc(City.Readiness.Index)) %>% 
  top_n(-3, City.Readiness.Index) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13) 
```

Similarly to vulnerability index, we combine obtained city readiness index with country readiness index extracted from ND-GAIN database. Readiness in ND-GAIN refer to country’s **ability to leverage investments and convert them to adaptation actions** by considering economic, governance and social dimensions.
As shown in the map below, the spatial distribution of readiness index outlines a high difference between cities located in occidental countries, particluarly in north Europe, and those located in Africa and Latin America.

$$Read_{city-coutry}= \frac{Read_{city}+Read_{country}}{2}$$

```{r warning=FALSE, message=FALSE, echo = TRUE}
# join with country readiness index
CDP_Cities_KPI <- CDP_Cities_KPI %>% 
  
  # Join Country readiness index
  left_join(NDGAINs_2018[,c("ISO3","Country.Readiness")], by = c("Country.Code.3" = "ISO3")) %>% 
  
  # Compute City.Country.Readiness
  mutate(City.Country.Readiness = select(., c("City.Readiness.Index","Country.Readiness")) 
         %>% apply(1, mean, na.rm=TRUE)) 

# plot map of readiness index

pal <- colorQuantile(palette = "RdYlBu", n = 5,
                     domain = CDP_Cities_KPI$City.Country.Readiness,
                     reverse = FALSE)

labels <- sprintf(
  "<strong>%s</strong><br/><strong>%s</strong><br/>",
  paste("Name", CDP_Cities_KPI$Organization, sep=": "), 
  paste("Readiness Index", round(CDP_Cities_KPI$City.Country.Readiness,2), sep =": ")
) %>% 
  lapply(htmltools::HTML)

leaflet(data = CDP_Cities_KPI, height = 400, width = "100%") %>% 
  addTiles() %>%
  addProviderTiles(providers$CartoDB.DarkMatter) %>% 
  addCircleMarkers(~long, ~lat, 
                   radius = 4,
                   color = ~pal(City.Country.Readiness),
                   stroke = FALSE,
                   fillOpacity = 0.7,
                   weight = 100,
                   popup = ~as.character(City), 
                   label = labels) %>% 
  addLegend(pal = pal, values = ~City.Country.Readiness, opacity = 0.9, 
            title = "Readiness index",
            position = "bottomright",
            labFormat = labelFormat(suffix = " "))


```

### Vulnerability/Readiness Matrix

The Vulnerability/Readiness matrix illstrates the comparative resilience of cities. The vertical axis shows the score of vulnerability and the horizontal axis shows the readiness score. Hence, we obtain 4 quadrant qualifying both city vulnerability and readiness to climate change impacts. In order to intersect our results with social equity issues, cities are presented with circles with sizes depending on GNP per capita index provided from SDG country indicators.

```{r warning=FALSE, message=FALSE, echo = TRUE}
# join city kpi with SDG indicators
CDP_Cities_KPI = CDP_Cities_KPI %>% 
  left_join(SDGData_long_KPI, by = "Country.Code.3" )

# plot matrix
fig <- plot_ly(CDP_Cities_KPI, 
               x = ~City.Country.Readiness,
               y = ~City.Country.Vulnerability, 
               text = ~paste('City:', City, 
                             '<br>Country:', Country, 
                             '<br>Readiness index:',round(City.Country.Readiness,2),
                             '<br>VUlnerability index:',round(City.Country.Vulnerability,2),
                             '<br>GNP per capita:', Country.KPI.GNP.PerCapita), 
               type = 'scatter', 
               mode = 'markers',
               size = ~Country.KPI.GNP.PerCapita,
               sizes = c(1, 25),
               color = "gray",
               colors = "black",
               marker = list(opacity = 0.4, sizemode = 'diameter')) %>% 
  layout(title = "Readiness/Vulnerability Matrix (by GNP index)",
         yaxis = list(title = 'City Vulnerability index',
                      range = c(0,max(CDP_Cities_KPI$City.Country.Vulnerability)+ 0.1)), 
         xaxis = list(title = 'City Readiness index',
                      range = c(0,max(CDP_Cities_KPI$City.Country.Readiness) + 0.1)),
         shapes = list(
           list(type = "rect",
                fillcolor = "green", line = list(color = "green"), opacity = 0.3,
                x0 = mean(CDP_Cities_KPI$City.Country.Readiness), 
                x1 = max(CDP_Cities_KPI$City.Country.Readiness) + 0.1, xref = "x",
                y0 = 0, y1 = mean(CDP_Cities_KPI$City.Country.Vulnerability), yref = "y"),
           list(type = "rect",
                fillcolor = "red", line = list(color = "red"), opacity = 0.3,
                x0 = 0, x1 = mean(CDP_Cities_KPI$City.Country.Readiness), xref = "x",
                y0 = mean(CDP_Cities_KPI$City.Country.Vulnerability), 
                y1 = max(CDP_Cities_KPI$City.Country.Vulnerability) +0.1, yref = "y"),
           list(type = "rect",
                fillcolor = "blue", line = list(color = "blue"), opacity = 0.3,
                x0 = mean(CDP_Cities_KPI$City.Country.Readiness),
                x1 = max(CDP_Cities_KPI$City.Country.Readiness) + 0.1, xref = "x",
                y0 = mean(CDP_Cities_KPI$City.Country.Vulnerability), 
                y1 = max(CDP_Cities_KPI$City.Country.Vulnerability) +0.1, yref = "y"),
         list(type = "rect",
              fillcolor = "yellow", line = list(color = "yellow"), opacity = 0.3,
              x0 = 0,
              x1 = mean(CDP_Cities_KPI$City.Country.Readiness), xref = "x",
              y0 = 0, 
              y1 = mean(CDP_Cities_KPI$City.Country.Vulnerability), yref = "y")))

fig

```

- <span style="color: red;">Upper left quadrant </span> contains cities with high level of vulnerabiliy and low level readiness to climate change. These cities need both **investment and collaboration** to improve readiness and **urgency** for implmenting adaptation actions. Examples include: Kisumu in Kenya $(Read_{Kisumu}= 0.33,Vul_{Kisumu}=0.60 )$, Kampala in Uganda $(Read_{Uganda}= 0.38,Vul_{Uganda}=0.53 )$, and Lagos in NIgeria $(Read_{Lagos}= 0.46,Vul_{Lagos}=0.71)$.
- <span style="color: green;">Lower right quadrant </span> contains cities with higher level of readiness and lower level of vulnerability to climate change. Wheras they may be considered as leaders, some of them remain vulnerable and need to continue their journey in reducing their vulnerability and GHG emissions reductions. Examples include: Lund in Sweedn $(Read_{Lund}= 0.84,Vul_{Lund}=0.26)$, Copenhagen in Danemark $(Read_{Copenhagen}=0.80,Vul_{Copenhagen}= 0.19)$, and Zurich in Switzerland $(Read_{Zurich}=0.78 ,Vul_{Zurich}=0.23)$.
- <span style="color: blue;">Upper left quadrant </span>contains cities with high level of both vulnerrabiliy and readiness to climate change. They present an **apropriate environment for implementing collaboration with coporates and private sector**. Examples include: Paris $(Read_{paris}= 0.80,Vul_{paris}=0.42)$, Syndey $(Read_{Syndey}=0.67,Vul_{Syndey}= 0.48)$, and Houston $(Read_{Houston}=0.71 ,Vul_{Houston}=0.46)$.
- <span style="color: orange;">Upper left quadrant </span> contains cities with lower level of both vulerability and readiness to climate change. Since the low level of vulnerability may be due to low awareness of climate hazards and resulting challenges, more efforts are needed to **help these cities collecting relevant data and disclosing their actions**. Examples include: Winchester $(Read_{Winchester}= 0.42,Vul_{Winchester}=0.15)$, Chiety in Italy $(Read_{Chiety}=0.34,Vul_{Chiety}= 0.16)$, and Guanulhos in Brazil $(Read_{Houston}=0.17 ,Vul_{Houston}=0.20)$.

> **Social Equity issues:** We observe a clear correlation between GNP per capita (representing economic wealth of cities) and cities' readiness to climate chage impacts and advancement in implementing climate adaptation policies: **Cities located in poor countries present lower readiness to climate change impacts.** However, we can distinguidh some **within countries variabilities**: Multiple cities in USA present low readines index, although a high GNP index (Natchez, Roanoke, South Bariington...). At the opposite, cites like Seoul (Korea) and Barga (Protugal) have a high score of readiness despite a low GNP index. 


```{r warning=FALSE, message=FALSE, echo = TRUE}
# define color palette

pal <- c("goldenrod","blue","red","green3","orange","black","turquoise3","deepskyblue")

# plot
fig <- plot_ly() %>% 
  add_trace(data = CDP_Cities_KPI, 
            x = ~City.Country.Readiness, 
            y = ~City.Country.Vulnerability, 
            color = ~CDP.Region,
            colors = pal,
            text = ~paste("City: ", City, '<br>Country:', Country),
            type = "scatter",
            mode = "markers",
            size = 1)  %>% 
  add_segments(x = mean(CDP_Cities_KPI$City.Country.Readiness), y=0, 
               xend=mean(CDP_Cities_KPI$City.Country.Readiness), yend=max(CDP_Cities_KPI$City.Country.Vulnerability)+ 0.1, 
               line=list(color="gray", width = 1, dash = 'dash'),
               name = "Median readiness") %>% 
  add_segments(y = mean(CDP_Cities_KPI$City.Country.Vulnerability), x=0, 
               yend=mean(CDP_Cities_KPI$City.Country.Vulnerability), xend=max(CDP_Cities_KPI$City.Country.Readiness)+ 0.1, 
               line=list(color="gray", width = 1, dash = 'dot'),
               name = "Median vulnerability") %>% 
  layout(title = "Rediness/Vulnerability Matrix (by CDP regions)",
         yaxis = list(title = 'City Vulnerability Index',
                      range = c(-0.1,max(CDP_Cities_KPI$City.Country.Vulnerability)+ 0.1)), 
         xaxis = list(title = 'City Readiness Index',
                      range = c(-0.1,max(CDP_Cities_KPI$City.Country.Readiness) + 0.1)),
         legend = list(orientation = 'h', x = 0.2, y = -0.3)) 


fig
```

The figure above illustrates vulnerability/readiness matrix with regard to CDP regions. We notice an important geographical disparities in vulnerability and readiness:

- Cities located in Africa and Latin America have lower readiness values 
- The majority of European cities have both high readiness scores and low vulnerability levels
- Cities located in East Asia have high readiness score


# City-Corporates collaboration

CDP provides data related to corporates' disclosures and responses to both climate change and water security issues. We propose in this section a mapping of the number of CDP climate change corporate responders by city with the calculated city readiness index. This mapping may help us comparing cities' advancement in implementing adptation policies and coporates' awareness by disclosing their climate actions.

The table below shows the top 5 american cities in term of number of coporates reponders to climate change questionnaire for the year of 2020.

```{r warning=FALSE, message=FALSE, echo = TRUE}

# get location of corporations (Kaggle dataset)
Corporations_Location = read.csv("../input/cdp-unlocking-climate-solutions/Supplementary Data/Locations of Corporations/NA_HQ_public_data.csv",na.strings="")



# process corporations locations data
Corporations_Location_2020 =Corporations_Location %>% 
  filter(survey_year == 2020,
         theme == "Climate Change",
         hq_country == "United States of America",
         address_city != "NA") %>% 
  mutate_at("address_state", as.character) %>% 
  mutate(address_state = recode(address_state,
                              "Georgia" = "GA",
                              "Maryland" = "MD" ,
                              "Massachusetts" = "MA" ,
                              "Washington" = "WA",
                              "Texas" = "TX",
                              "COLORADO" = "CO",
                              "Illinois" = "IL",
                              "Michigan" = "MI",
                              "Minnesota" = "MN",
                              "Arizona" = "AZ",
                              "Pennsylvania" = "PA",
                              "Rhode Island" = "RI",
                              "Virginia" = "VA",
                              "California" = "CA",
                              "Missouri" = "MO",
                              "District of Columbia" = "DC",
                              "Delaware" = "DE")) %>% 
  unite(City_State, address_city, address_state, sep = "-", remove = FALSE)
  
# count number of corporation disclosing by city-state
City_Corporation = Corporations_Location_2020 %>% 
  group_by(City_State) %>% 
  summarise(nb_corporation = n()) %>% 
  arrange(desc(nb_corporation))

# show table
City_Corporation %>% 
  arrange(desc(nb_corporation)) %>% 
  top_n(5) %>% 
  kable() %>%
  kable_styling(bootstrap_options = c("striped", "hover"), full_width = F, font_size = 13)
```

The map below presents the number of corporates responders by city (circle size), corresponding city readiness index (color level), and presence of corporates disclosing to CDP climate change questionnaire (symbol type). We notice that cities like New York, Boston and Houston are presenting suitable conditions for city-coporates collaboration through important level of bth readiness and paricipating coroporates. However, cities like Natchez, Gretna and Alton have a low readiness index and no coporates responding to CDP questionnaire.

While joining city disclosure data with coporates reponses may help us for analyzing potential collaboration, more accurate data is needed to facilitate this work. In order to join city disclosure data with coporates reponses we had to recode a few city names and states idenifiers that are encdoded differently in data source. In order to facilitate joining these data to produce consistent maps, more efforts are needed by disclosers to use a normalized city names and unique idenfiers.

```{r warning=FALSE, message=FALSE, echo = TRUE}
### join coporation with city coordinates

# load us cities data (Kaggle dataset)
uscities = read.csv("../input/cdp-unlocking-climate-solutions/Supplementary Data/Simple Maps US Cities Data/uscities.csv",na.strings="")


# process us cities data
uscities = uscities %>% 
  select(city,state_id,state_name,county_fips,county_name,lat,lng,population,density) %>% 
  unite(City_State, city, state_id, sep = "-", remove = FALSE)

# join city_corportaion dataset with city coordinates
City_Corporation_geo = City_Corporation %>% 
  left_join(uscities,by = "City_State") %>% 
  drop_na(lat) 

### join City kpi with number of coportations/city

# select city disclosing in USA

CDP_Cities_KPI_USA = CDP_Cities_KPI %>% 
  filter(Country == "United States of America") %>% 
  select(Account.Number, Organization,city = City,City.Country.Readiness,City.Country.Vulnerability,
         lat.kpi = lat, long.kpi = long) %>% 
  mutate_at("city", as.character) %>% 
  mutate(city = recode(city,
                        "New York City" = "New York",
                        "Richmond, VA" = "Richmond" ,
                        "Lexington, MA" = "Lexington" ,
                        "San José, CA" = "San Jose",
                        "Cambridge, MA" = "Cambridge",
                        "Columbia, MO" = "Columbia",
                        "Durham, NC" = "Durham"))

# merge city kpi with number of coporations
CDP_Cities_KPI_USA_geo = CDP_Cities_KPI_USA %>% 
  left_join(City_Corporation_geo, by = "city") %>% 
  mutate_at("nb_corporation", ~replace_na(., 0)) %>% 
  mutate(nb_corporation, Corporate.Reponders = ifelse(nb_corporation > 0, "Yes", "No"))

  
# plot map

g <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showland = TRUE,
  landcolor = toRGB("gray85"),
  subunitwidth = 1,
  countrywidth = 1,
  subunitcolor = toRGB("white"),
  countrycolor = toRGB("black")
)



plot_geo(CDP_Cities_KPI_USA_geo, locationmode = 'USA-states') %>%
  add_markers(y= ~lat.kpi, x= ~long.kpi,  #y= ~lat, x= ~lng, 
              color= ~City.Country.Readiness,
              colors = "RdYlBu", # "RdBu", # "RdYlBu",
              opacity = 0.8,
              symbol = ~Corporate.Reponders, 
              symbols = c('x','circle'), #c('triangle-up','circle'), # c(1,16),
              size= ~nb_corporation, 
              width = 5,
              marker=list(sizeref=0.2, sizemode="area",
                          line = list(color = "black",width = 1)),
              hoverinfo = "text",
              text = ~paste("City:", CDP_Cities_KPI_USA_geo$city, 
                            "<br />Nb Orgs:", CDP_Cities_KPI_USA_geo$nb_corporation, 
                            "<br />City readiness:",round(CDP_Cities_KPI_USA_geo$City.Country.Readiness,2),
                            "<br />City vulnerability:",round(CDP_Cities_KPI_USA_geo$City.Country.Vulnerability,2))) %>%
  layout(title = 'Disclosing Coporations vs City readiness<br>(2020)',
         geo=g,
         legend=list(title=list(text='Coroporate responders within city')))

```

# Conclusion and perspectives

## Conclusion 

- **Literature review:** 
  - **Theoretical framing:** Social equity issue may be addressed by integrating social dimension in measuring population vulnerablity and adaptaing capacity to climate change impacts. 
  - **Methodological approaches:** Building normalized indices enables the combination of multiple indicators and metrics related to various sectors. 
  - **External data:** The ND-GAIN methodology and datasets provides an appropriate framework and asset to our study.
  
- **Method**
  - **Data exploration:** The work presented in this report is based on two data exploration and processing kernels: 
    - [Cities responses Exploration kernel](https://www.kaggle.com/shabou/exploratory-analysis-of-cities-responses) to generate [Cities KPI dataset](https://www.kaggle.com/shabou/cdpchallengecitieskpi)
    - [Cities geoLocation data analysis](https://www.kaggle.com/shabou/cdp-cities-location-exploratory-analysis) to obtain [cleaned and verified cities' geographical coordinates](https://www.kaggle.com/shabou/cdp-challenge-cities-geolocation-data)  
  - **Building vulnerability/readiness indices:** We proposed a methodology to transform, normalize and aggregate the selected KPIs into cities vulnerability and readiness indices. We combined our results with ND-GAIN dataset in order to take into account country scale.
  
- **Findings**:
  - Ranking and classifying cities in terms of vulnerability and readiness
  - Identify cities presenting an encouraging environment for colaboration with coroporates through a combination of high level of readiness, awareness, and vulnerability to climate change imapacts.
  - Identify cities with urgent need for cooperation and assistance due to their high vulnerability and low readiness and advancement in implementing climate policies.
  - Social equity is investigated by integrating social vulnerability dimension in our KPIs, confonting our results with GNP index and highlighting socio-geographical disparities.  

## Perspectives

- **Temporal Analysis**: Only the last year reponses are examined in this study (2020 disclosure). Implementing the same methodology to previous years may inform us on city progress in reducing their vulnerability and increasing their readiness and advancement in climate policies. 

- **Methdological improvements**: 

  - Weighting the selected indictors depending on their importance for explaining vulnerability and readiness by conducting more advanced statistcial analysis such as Principal Component Analysis.
  - Our methodology is highly sensitive to subjective evaluation of reporters and disclosure bias (for example, no reported climate hazards induces null exposure level). Therefore, we need to use ground truth external datasets to increase the consitency of proposed indices.

- **Mapping CDP data with SDGs**: It is crucial to understand the interlinkages between CDP’s questionnaires and the insights it generates with respect to sustainable developemeent goals (SDGs). A mapping of CDP’s questionnaires against the SDGs targets and indicators may enhance the contribution of CDP's data to help governments, cities and corporates for achieving the ambitious Agenda 2030 for sustainable developement.



# References

- [Indicators for Sustainable Cities](https://ec.europa.eu/environment/integration/research/newsalert/pdf/indicators_for_sustainable_cities_IR12_en.pdf)
- [Visualization of a City Sustainability Index](https://www.researchgate.net/publication/281762160_Visualization_of_a_City_Sustainability_Index_CSI_Towards_Transdisciplinary_Approaches_Involving_Multiple_Stakeholders)
- [Humanity Divided: Confronting Inequality in Developing Countries](https://www.undp.org/content/undp/en/home/librarypage/poverty-reduction/humanity-divided--confronting-inequality-in-developing-countries.html)
- [Sustainable Developement Goals](https://unstats.un.org/sdgs/)
- [SDG Tracker](https://sdg-tracker.org/)
- [ND-GAIN Notre Dame Global Adaptation Initiative](https://gain.nd.edu/)
- [Why working with CDP means working towards the UN’s Sustainable Development Goals](https://www.cdp.net/en/policy-and-public-affairs/sustainable-development-goals)
- [Climate change and social justice: an evidence review](https://www.jrf.org.uk/report/climate-change-and-social-justice-evidence-review)
- [Addressing Social Vulnerability and Equity in Climate Change Adaptation Planning](https://www.researchgate.net/publication/280311985_Addressing_Social_Vulnerability_and_Equity_in_Climate_Change_Adaptation_Planning)
- [Gaps Matter: Environment, Health, and Social Equity](https://www.jstor.org/stable/26556357?seq=2#metadata_info_tab_contents)



