#Loading required packages
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(httr)
library(jsonlite)
##
## Attaching package: 'jsonlite'
##
## The following object is masked from 'package:purrr':
##
## flatten
library(leaflet)
```r
#Downloading the bike point data
BorisBikesAPI <- 'https://api.tfl.gov.uk/BikePoint/'
get_BorisBikesAPI <- GET(BorisBikesAPI)
get_BorisBikes_text <- content(get_BorisBikesAPI, "text")
get_BorisBikesAPI_JSON <- fromJSON(get_BorisBikes_text, flatten = TRUE)
df_BorisBikes <- as.data.frame(get_BorisBikesAPI_JSON)
head(df_BorisBikes, 2)
## $type
## 1 Tfl.Api.Presentation.Entities.Place, Tfl.Api.Presentation.Entities
## 2 Tfl.Api.Presentation.Entities.Place, Tfl.Api.Presentation.Entities
## id url commonName placeType
## 1 BikePoints_84 /Place/BikePoints_84 Breams Buildings, Holborn BikePoint
## 2 BikePoints_85 /Place/BikePoints_85 Tanner Street, Bermondsey BikePoint
## additionalProperties
## 1 Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Description, Description, Description, Description, Description, Description, Description, Description, Description, Description, Description, TerminalName, Installed, Locked, InstallDate, RemovalDate, Temporary, NbBikes, NbEmptyDocks, NbDocks, NbStandardBikes, NbEBikes, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, 003449, true, false, 1279020240000, , false, 24, 1, 25, , , 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z, 2022-08-02T11:24:35.73Z
## 2 Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Tfl.Api.Presentation.Entities.AdditionalProperties, Tfl.Api.Presentation.Entities, Description, Description, Description, Description, Description, Description, Description, Description, Description, Description, Description, TerminalName, Installed, Locked, InstallDate, RemovalDate, Temporary, NbBikes, NbEmptyDocks, NbDocks, NbStandardBikes, NbEBikes, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, BikePoints, 000994, true, false, 1279026060000, , false, 33, 5, 41, , , 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z, 2022-08-02T10:53:18.247Z
## children childrenUrls lat lon
## 1 NULL NULL 51.51594 -0.111778
## 2 NULL NULL 51.50065 -0.078600
Below I use the package leaflet to plot the location of the bike points using the coordinates in the data frame.
#Subsetting the necessary data
df_key_BorisBikes <- df_BorisBikes[,c(2,4,5,9,10)]
head(df_key_BorisBikes)
## id commonName placeType lat
## 1 BikePoints_84 Breams Buildings, Holborn BikePoint 51.51594
## 2 BikePoints_85 Tanner Street, Bermondsey BikePoint 51.50065
## 3 BikePoints_86 Sancroft Street, Vauxhall BikePoint 51.48948
## 4 BikePoints_87 Devonshire Square, Liverpool Street BikePoint 51.51647
## 5 BikePoints_88 Bayley Street , Bloomsbury BikePoint 51.51859
## 6 BikePoints_89 Tavistock Place, Bloomsbury BikePoint 51.52625
## lon
## 1 -0.111778
## 2 -0.078600
## 3 -0.115156
## 4 -0.079684
## 5 -0.132053
## 6 -0.123509
#subsetting the data again to generate a dataframe of the coordinates
coordinates <- df_key_BorisBikes[, c(2,4,5)]
head(coordinates)
## commonName lat lon
## 1 Breams Buildings, Holborn 51.51594 -0.111778
## 2 Tanner Street, Bermondsey 51.50065 -0.078600
## 3 Sancroft Street, Vauxhall 51.48948 -0.115156
## 4 Devonshire Square, Liverpool Street 51.51647 -0.079684
## 5 Bayley Street , Bloomsbury 51.51859 -0.132053
## 6 Tavistock Place, Bloomsbury 51.52625 -0.123509
#plotting the coordinates on a map
map <- leaflet () %>%
addTiles() %>%
addMarkers(lng = coordinates[,'lon'], lat = coordinates[,'lat'], popup = coordinates[,'commonName'])
map
Below I extract the name of the bike point after the comma to try and determine where bike points are most frequent. This was not a perfect method as many of the locations overlap. If I had more time I would perform a more accurate measurement gathering.
In addition, I would have compared the number of bike points the population of the area to generate a per capita metric.
names <- sub(".*,", "", df_key_BorisBikes$commonName)
unique_names <- unique(names)
#Adding the area names to the dataframe
df_key_BorisBikes$area <- names
head(df_key_BorisBikes)
## id commonName placeType lat
## 1 BikePoints_84 Breams Buildings, Holborn BikePoint 51.51594
## 2 BikePoints_85 Tanner Street, Bermondsey BikePoint 51.50065
## 3 BikePoints_86 Sancroft Street, Vauxhall BikePoint 51.48948
## 4 BikePoints_87 Devonshire Square, Liverpool Street BikePoint 51.51647
## 5 BikePoints_88 Bayley Street , Bloomsbury BikePoint 51.51859
## 6 BikePoints_89 Tavistock Place, Bloomsbury BikePoint 51.52625
## lon area
## 1 -0.111778 Holborn
## 2 -0.078600 Bermondsey
## 3 -0.115156 Vauxhall
## 4 -0.079684 Liverpool Street
## 5 -0.132053 Bloomsbury
## 6 -0.123509 Bloomsbury
area_freq <- df_key_BorisBikes %>%
count(area, sort = TRUE)
head(area_freq)
## area n
## 1 Marylebone 26
## 2 Holborn 20
## 3 Mayfair 17
## 4 Westminster 16
## 5 Kensington 15
## 6 Vauxhall 15
#Areas the have the most bike points
top_10_areas <- area_freq[1:10,]
top_10_areas
## area n
## 1 Marylebone 26
## 2 Holborn 20
## 3 Mayfair 17
## 4 Westminster 16
## 5 Kensington 15
## 6 Vauxhall 15
## 7 Battersea 14
## 8 Bethnal Green 14
## 9 Bloomsbury 14
## 10 Hoxton 13
nrow(area_freq)
## [1] 123
#Areas with the least amount of bike points
lowest_10_areas <- area_freq[114:123,]
lowest_10_areas
## area n
## 114 Parson's Green 1
## 115 Shad Thames 1
## 116 Sloane Square 1
## 117 St Lukes 1
## 118 St Pauls 1
## 119 St.John's Wood 1
## 120 Stratford 1
## 121 Wandsworth Common 1
## 122 Hoxton 1
## 123 Shepherd's Bush 1
top_10_areas %>%
ggplot(aes(x = area, y = n)) +
geom_bar(stat = 'identity', fill = 'green') +
theme(axis.text.x = element_text(angle=45, hjust = 1))+
labs(x = "Area", y = "# of Bike Points by Area",
title = "Areas that have the Greatest # of Bike Points")
lowest_10_areas %>%
ggplot(aes(x = area, y = n)) +
geom_bar(stat = 'identity', fill = 'red') +
theme(axis.text.x = element_text(angle=45, hjust = 1))+
labs(x = "Area", y = "# of Bike Points by Area",
title = "Areas that have the Lowest # of Bike Points")
Areas where bike points are less frequent are a good target for new bike points as many of these locations have quite large populations. For example Stratford has a population of 36,666 yet only has 1 bike point.
I read data from https://www.trustforlondon.org.uk/data/poverty-borough/ detailing the poverty rates by London Borough After Housing Costs (AHC).
ldn_poverty <- read_csv("C:/Users/keren/Downloads/Poverty_ Ldn_bor_(2015_16-2019_20).csv")
## Rows: 32 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (4): London borough, Poverty rate (AHC), Poverty rate (AHC) CI Lower, Po...
## dbl (2): Number in poverty (AHC), Confidence Interval (+/-)
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
ldn_poverty <- as.data.frame(ldn_poverty)
head(ldn_poverty)
## London borough Number in poverty (AHC) Confidence Interval (+/-)
## 1 Barking and Dagenham 410000 5e+04
## 2 Barnet 500000 7e+04
## 3 Bexley 290000 5e+04
## 4 Brent 660000 1e+05
## 5 Bromley 320000 5e+04
## 6 Camden 320000 7e+04
## Poverty rate (AHC) Poverty rate (AHC) CI Lower Poverty rate (AHC) CI Upper
## 1 29% 24% 34.10%
## 2 25% 21.40% 29.50%
## 3 29% 23.10% 36.20%
## 4 36% 28.20% 43.70%
## 5 17% 14% 20.20%
## 6 34% 25% 45.30%
summary(ldn_poverty)
## London borough Number in poverty (AHC) Confidence Interval (+/-)
## Length:32 Min. :120000 Min. : 30000
## Class :character 1st Qu.:285000 1st Qu.: 50000
## Mode :character Median :380000 Median : 60000
## Mean :384194 Mean : 65806
## 3rd Qu.:490000 3rd Qu.: 80000
## Max. :690000 Max. :140000
## NA's :1 NA's :1
## Poverty rate (AHC) Poverty rate (AHC) CI Lower Poverty rate (AHC) CI Upper
## Length:32 Length:32 Length:32
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
#renaming the columns
names(ldn_poverty) <- c('LondonBorough', 'No_in_Poverty_AHC', 'CI',
'PovertyRate_AHC', 'PovertyRateAHC_LowerCI', 'PovertyRateAHC_UpperCI')
head(ldn_poverty)
## LondonBorough No_in_Poverty_AHC CI PovertyRate_AHC
## 1 Barking and Dagenham 410000 5e+04 29%
## 2 Barnet 500000 7e+04 25%
## 3 Bexley 290000 5e+04 29%
## 4 Brent 660000 1e+05 36%
## 5 Bromley 320000 5e+04 17%
## 6 Camden 320000 7e+04 34%
## PovertyRateAHC_LowerCI PovertyRateAHC_UpperCI
## 1 24% 34.10%
## 2 21.40% 29.50%
## 3 23.10% 36.20%
## 4 28.20% 43.70%
## 5 14% 20.20%
## 6 25% 45.30%
#order by poverty rates
ldn_poverty_ordered <- ldn_poverty[order(ldn_poverty$PovertyRate_AHC, decreasing = TRUE),]
#Boroughs with the highest poverty rate
top_10_poverty <- ldn_poverty_ordered[1:10,]
top_10_poverty
## LondonBorough No_in_Poverty_AHC CI PovertyRate_AHC
## 29 Tower Hamlets 600000 80000 39%
## 4 Brent 660000 100000 36%
## 24 Newham 490000 80000 36%
## 32 Westminster 250000 50000 36%
## 13 Haringey 660000 110000 35%
## 22 Lewisham 500000 90000 35%
## 6 Camden 320000 70000 34%
## 9 Enfield 690000 80000 34%
## 31 Wandsworth 460000 140000 34%
## 8 Ealing 300000 50000 30%
## PovertyRateAHC_LowerCI PovertyRateAHC_UpperCI
## 29 32.50% 45.90%
## 4 28.20% 43.70%
## 24 29.40% 44.50%
## 32 27% 46.90%
## 13 27.20% 42.80%
## 22 26.30% 44.40%
## 6 25% 45.30%
## 9 28.90% 39.50%
## 31 22.10% 49.20%
## 8 23.80% 36.80%
top_10_poverty %>%
ggplot(aes(x = LondonBorough, y = PovertyRate_AHC)) +
geom_bar(stat = 'identity', fill = 'blue') +
theme(axis.text.x = element_text(angle=45, hjust = 1))+
labs(x = "Borough (London)", y = "Poverty Rate (AHC)",
title = "London Boroughs with the Highest Poverty Rate (AHC)")
Economically deprived areas could benefit significantly from new bike points as lower income families may not be able to afford to use gym services or have the housing space to hold a bike.
I believe that the areas highlighted throughout my report would be the key areas to look at when building new bike points as these areas could stand to benefit the most from increased availablity of bike points.