Browse Source

Tidy up scratchwork

Petra Lamborn 3 years ago
parent
commit
59084ddc78
2 changed files with 7 additions and 30 deletions
  1. 6
    1
      maps.R
  2. 1
    29
      process.R

+ 6
- 1
maps.R View File

@@ -1,5 +1,8 @@
1
+# Map simplification
2
+# In future, might be better to do this online at https://mapshaper.org/
3
+# Save installing v8!
1 4
 library(rgdal)
2
-library(rmapshaper)
5
+library(rmapshaper) 
3 6
 
4 7
 # sf <- readOGR(dsn = "shapefiles/statsnzstatistical-area-2-2018-generalised-SHP/")
5 8
 sf <- readOGR(dsn = "shapefiles/SA2-2018-WGS/")
@@ -12,6 +15,7 @@ ssf1 <- ms_simplify(sf, keep_shapes=TRUE)
12 15
 plot(ssf1, xlim=c(1480000, 1510000), ylim=c(5150000, 5180000))
13 16
 nrow(ssf1@data)
14 17
 
18
+# Ended up going with this version
15 19
 ssf2.5 <- ms_simplify(sf, 0.025, keep_shapes=TRUE)
16 20
 plot(ssf2.5, xlim=c(1480000, 1510000), ylim=c(5150000, 5180000))
17 21
 nrow(ssf2.5@data)
@@ -34,5 +38,6 @@ ci <- sf@data$SA22018__1 != "Chatham Islands"
34 38
 head(ssf2.5@data)
35 39
 laper <- (sf@data$LAND_AREA_ / sf@data$AREA_SQ_KM)
36 40
 sf@data$SA22018__1[laper > 0.1 & laper < 0.4]
41
+# Filter out: chatham islands (due to meridian issues) + areas more than 10% water
37 42
 plot(ssf2.5[(laper > 0.1) & ci,])
38 43
 writeOGR(ssf2.5[(laper > 0.1) & ci,], dsn = "shapefiles/sa20025WGSfil/", layer = "SA2", driver="ESRI Shapefile")

scratch.R → process.R View File

@@ -1,33 +1,8 @@
1
+# Process csv data into an RData file to be loaded by the shiny application
1 2
 library(readr)
2
-library(ggplot2)
3 3
 library(dplyr)
4
-library(igraph)
5 4
 education_travel <- read_csv("travel-education.csv")
6 5
 work_travel <- read_csv("travel-work.csv")
7
-length(unique(education_travel$SA2_name_usual_residence_address))
8
-length(unique(education_travel$SA2_name_educational_address))
9
-length(unique(work_travel$SA2_name_usual_residence_address))
10
-length(unique(work_travel$SA2_name_workplace_address))
11
-
12
-ggplot(work_travel, aes(x = SA2_code_usual_residence_address, 
13
-                        y = SA2_code_workplace_address,
14
-                        fill = Total)) +
15
-  geom_tile()
16
-
17
-g2 <- graph( edges=c(4,9, 9,6, 6, 4, 1,2, 5,6, 9,5, 1,4, 1,5, 2,6, 3,3, 6,6), n=10 )
18
-plot(g2)
19
-
20
-tg <- make_empty_graph()
21
-
22
-work_travel %>% filter(Total > 100) %>% select(SA2_name_usual_residence_address, SA2_name_workplace_address) %>% 
23
-  as.matrix %>% t %>% as.vector -> elist
24
-
25
-locgraph <- graph(edges = elist)
26
-
27
-# plot(locgraph, label = NA)
28
-
29
-sg <- decompose(locgraph, mode="weak")
30
-
31 6
 
32 7
 work_travel %>% select(
33 8
   res_code = SA2_code_usual_residence_address,
@@ -144,8 +119,6 @@ edu_simp %>% group_by(edu_code, edu_name, edu_east, edu_north) %>%
144 119
 
145 120
 tencols <-  c("#f85654", "#e31a1c", "#1f78b4", "#6a3d9a", "#b2df8a", 
146 121
               "#33a02c", "#fdbf6f", "#ff7f00", "#cab2d6", "#af8ac1")
147
-tencols[which.max(work_from[1, 5:14])]
148
-
149 122
 
150 123
 work_from$MAX <- work_from %>% select(private:home) %>% as.matrix() %>% 
151 124
   apply(1, function(x) {
@@ -174,4 +147,3 @@ edu_simp$MAX <- edu_simp %>% select(drive:home) %>% as.matrix() %>%
174 147
     })
175 148
 
176 149
 save(work_simp, work_to, work_from, edu_simp, edu_to, edu_from, tencols, file="viz/datasets.RData")
177
-