@@ -20,7 +20,7 @@ library(viridis)
20
20
library(scatterpie )
21
21
library(ggrepel )
22
22
library(DescTools )
23
- options(scipen = 999 )
23
+ options(scipen = 9999 )
24
24
options(lifecycle_verbosity = " warning" )
25
25
26
26
# Load aggregation function
@@ -29,18 +29,18 @@ getwd()
29
29
source(' aggregation_func.R' ) # should be in the ~/kblock-analysis directory
30
30
31
31
# Read in data ------------------------------------------------------------
32
- dir.create(' complexity-analysis' )
33
- dir.create(' complexity-analysis/input-data' )
34
- wd_input = ' complexity-analysis/input-data'
35
32
# Download block level data from this URL: dsbprylw7ncuq.cloudfront.net/AF/africa_data.parquet
36
- curl :: multi_download(" dsbprylw7ncuq.cloudfront.net/AF/africa_data.parquet" , " complexity-analysis/input-data/africa_data.parquet" , resume = TRUE )
37
- df_combined <- read_parquet(paste0(wd_input ,' /africa_data.parquet' ))
38
-
33
+ if (! file.exists(paste0(" data/africa_data.parquet" ))) {
34
+ curl :: multi_download(" dsbprylw7ncuq.cloudfront.net/AF/africa_data.parquet" , " complexity-analysis/input-data/africa_data.parquet" , resume = TRUE )
35
+ } else {
36
+ df_combined <- read_parquet(paste0(' data/africa_data.parquet' ))
37
+ }
38
+
39
39
# Create output directories
40
- dir.create(' complexity-analysis/output-data ' )
41
- dir.create(' complexity-analysis/output-data /data' )
42
- dir.create(' complexity-analysis/output-data /viz' )
43
- wd_output = ' complexity-analysis/output-data '
40
+ dir.create(' data/ complexity-analysis' )
41
+ dir.create(' data/ complexity-analysis/data' )
42
+ dir.create(' data/ complexity-analysis/viz' )
43
+ wd_output = ' data/ complexity-analysis'
44
44
45
45
# K-complexity groupings --------------------------------------------------
46
46
@@ -954,7 +954,7 @@ rm(a, b, conurban_bars, conurban_bars_data)
954
954
955
955
# Inequality charts -------------------------------------------------------
956
956
957
- urban_ineq <- read_parquet(paste0(wd_input , ' /africa_data.parquet' )) %> %
957
+ urban_ineq <- read_parquet(paste0(' data /africa_data.parquet' )) %> %
958
958
filter(area_type == ' Urban' )
959
959
960
960
names(urban_ineq )
@@ -1039,9 +1039,13 @@ rm(conurban_sd, urban_sd, agglos_sd, scatter_gini, scatter_sd)
1039
1039
1040
1040
# -------------------------------------------------------------------------
1041
1041
# Download from this URL: dsbprylw7ncuq.cloudfront.net/AF/africa_geodata.parquet
1042
- curl :: multi_download(" dsbprylw7ncuq.cloudfront.net/AF/africa_geodata.parquet" , " complexity-analysis/input-data/africa_geodata.parquet" , resume = TRUE )
1042
+ if (! file.exists(paste0(" data/africa_geodata.parquet" ))) {
1043
+ curl :: multi_download(" dsbprylw7ncuq.cloudfront.net/AF/africa_geodata.parquet" , " data/africa_geodata.parquet" , resume = TRUE )
1044
+ } else {
1045
+ print(' africa_geodata.parquet already downloaded.' )
1046
+ }
1043
1047
1044
- area_data <- arrow :: open_dataset(paste0(wd_input , ' /africa_geodata.parquet' )) %> %
1048
+ area_data <- arrow :: open_dataset(paste0(' data /africa_geodata.parquet' )) %> %
1045
1049
filter(urban_id %in% c(' ghsl_3798' ,' periurban_925' )) %> %
1046
1050
read_sf_dataset() %> %
1047
1051
st_set_crs(4326 ) %> %
@@ -1257,7 +1261,7 @@ ggsave(plot = layers_viz, filename = paste0(wd_output,'/viz/zoom_maps.pdf'),
1257
1261
1258
1262
# Maps --------------------------------------------------------------------
1259
1263
1260
- area_data <- arrow :: open_dataset(paste0(wd_input , ' /africa_geodata.parquet' )) %> %
1264
+ area_data <- arrow :: open_dataset(paste0(' data /africa_geodata.parquet' )) %> %
1261
1265
filter(urban_id %in% c(' ghsl_2125' )) %> %
1262
1266
read_sf_dataset() %> %
1263
1267
st_set_crs(4326 ) %> %
0 commit comments