Browse Source

Rationalise colours

Petra Lamborn 3 years ago
parent
commit
7ba9ada2a1
3 changed files with 29 additions and 25 deletions
  1. 18
    18
      scratch.R
  2. 3
    3
      viz/app.R
  3. 8
    4
      viz/extras.R

+ 18
- 18
scratch.R View File

29
 sg <- decompose(locgraph, mode="weak")
29
 sg <- decompose(locgraph, mode="weak")
30
 
30
 
31
 
31
 
32
-work_travel %>% rename(
32
+work_travel %>% select(
33
   res_code = SA2_code_usual_residence_address,
33
   res_code = SA2_code_usual_residence_address,
34
   res_name = SA2_name_usual_residence_address,
34
   res_name = SA2_name_usual_residence_address,
35
   res_east = SA2_usual_residence_easting,
35
   res_east = SA2_usual_residence_easting,
38
   work_name = SA2_name_workplace_address,
38
   work_name = SA2_name_workplace_address,
39
   work_east = SA2_workplace_easting,
39
   work_east = SA2_workplace_easting,
40
   work_north = SA2_workplace_northing,
40
   work_north = SA2_workplace_northing,
41
-  home = Work_at_home,
42
   private = Drive_a_private_car_truck_or_van,
41
   private = Drive_a_private_car_truck_or_van,
43
-  company = Drive_a_company_car_truck_or_van,
44
   passenger = Passenger_in_a_car_truck_van_or_company_bus,
42
   passenger = Passenger_in_a_car_truck_van_or_company_bus,
43
+  walk = Walk_or_jog,
44
+  bicycle = Bicycle,
45
+  company = Drive_a_company_car_truck_or_van,
45
   bus = Public_bus,
46
   bus = Public_bus,
46
   train = Train,
47
   train = Train,
47
-  bicycle = Bicycle,
48
-  walk = Walk_or_jog,
49
   ferry = Ferry,
48
   ferry = Ferry,
49
+  home = Work_at_home,
50
   other = Other,
50
   other = Other,
51
   total = Total
51
   total = Total
52
 ) -> work_simp
52
 ) -> work_simp
57
                          res_east,
57
                          res_east,
58
                          res_north) %>%
58
                          res_north) %>%
59
   summarise(
59
   summarise(
60
-    home = sum(ifelse(home < 0, 0, home)),
61
     private = sum(ifelse(private < 0, 0, private)),
60
     private = sum(ifelse(private < 0, 0, private)),
62
-    company = sum(ifelse(company < 0, 0, company)),
63
     passenger = sum(ifelse(passenger < 0, 0, passenger)),
61
     passenger = sum(ifelse(passenger < 0, 0, passenger)),
62
+    walk = sum(ifelse(walk < 0, 0, walk)),
63
+    bicycle = sum(ifelse(bicycle < 0, 0, bicycle)),
64
+    company = sum(ifelse(company < 0, 0, company)),
64
     bus = sum(ifelse(bus < 0, 0, bus)),
65
     bus = sum(ifelse(bus < 0, 0, bus)),
65
     train = sum(ifelse(train < 0, 0, train)),
66
     train = sum(ifelse(train < 0, 0, train)),
66
-    bicycle = sum(ifelse(bicycle < 0, 0, bicycle)),
67
-    walk = sum(ifelse(walk < 0, 0, walk)),
68
     ferry = sum(ifelse(ferry < 0, 0, ferry)),
67
     ferry = sum(ifelse(ferry < 0, 0, ferry)),
68
+    home = sum(ifelse(home < 0, 0, home)),
69
     other = sum(ifelse(other < 0, 0, other)),
69
     other = sum(ifelse(other < 0, 0, other)),
70
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
70
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
71
   ) -> work_from
71
   ) -> work_from
77
                          work_east,
77
                          work_east,
78
                          work_north) %>%
78
                          work_north) %>%
79
   summarise(
79
   summarise(
80
-    home = sum(ifelse(home < 0, 0, home)),
81
     private = sum(ifelse(private < 0, 0, private)),
80
     private = sum(ifelse(private < 0, 0, private)),
82
-    company = sum(ifelse(company < 0, 0, company)),
83
     passenger = sum(ifelse(passenger < 0, 0, passenger)),
81
     passenger = sum(ifelse(passenger < 0, 0, passenger)),
82
+    walk = sum(ifelse(walk < 0, 0, walk)),
83
+    bicycle = sum(ifelse(bicycle < 0, 0, bicycle)),
84
+    company = sum(ifelse(company < 0, 0, company)),
84
     bus = sum(ifelse(bus < 0, 0, bus)),
85
     bus = sum(ifelse(bus < 0, 0, bus)),
85
     train = sum(ifelse(train < 0, 0, train)),
86
     train = sum(ifelse(train < 0, 0, train)),
86
-    bicycle = sum(ifelse(bicycle < 0, 0, bicycle)),
87
-    walk = sum(ifelse(walk < 0, 0, walk)),
88
     ferry = sum(ifelse(ferry < 0, 0, ferry)),
87
     ferry = sum(ifelse(ferry < 0, 0, ferry)),
88
+    home = sum(ifelse(home < 0, 0, home)),
89
     other = sum(ifelse(other < 0, 0, other)),
89
     other = sum(ifelse(other < 0, 0, other)),
90
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
90
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
91
   ) -> work_to
91
   ) -> work_to
142
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
142
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
143
   ) -> edu_to
143
   ) -> edu_to
144
 
144
 
145
-tencols <-  c("#fb9a99", "#e31a1c", "#1f78b4", "#6a3d9a", "#b2df8a", 
146
-              "#33a02c", "#fdbf6f", "#ff7f00", "#cab2d6", "#a6cee3")
145
+tencols <-  c("#f85654", "#e31a1c", "#1f78b4", "#6a3d9a", "#b2df8a", 
146
+              "#33a02c", "#fdbf6f", "#ff7f00", "#af8ac1", "#cab2d6")
147
 tencols[which.max(work_from[1, 5:14])]
147
 tencols[which.max(work_from[1, 5:14])]
148
 
148
 
149
 
149
 
150
-work_from$MAX <- work_from %>% select(home:other) %>% as.matrix() %>% 
150
+work_from$MAX <- work_from %>% select(private:other) %>% as.matrix() %>% 
151
   apply(1, function(x) {
151
   apply(1, function(x) {
152
     ifelse(max(x) <= 0, NA, which.max(x))
152
     ifelse(max(x) <= 0, NA, which.max(x))
153
     })
153
     })
154
-work_to$MAX <- work_to %>% select(home:other) %>% as.matrix() %>% 
154
+work_to$MAX <- work_to %>% select(private:other) %>% as.matrix() %>% 
155
   apply(1, function(x) {
155
   apply(1, function(x) {
156
     ifelse(max(x) <= 0, NA, which.max(x))
156
     ifelse(max(x) <= 0, NA, which.max(x))
157
     })
157
     })
158
-work_simp$MAX <- work_simp %>% select(home:other) %>% as.matrix() %>% 
158
+work_simp$MAX <- work_simp %>% select(private:other) %>% as.matrix() %>% 
159
   apply(1, function(x) {
159
   apply(1, function(x) {
160
     ifelse(max(x) <= 0, NA, which.max(x))
160
     ifelse(max(x) <= 0, NA, which.max(x))
161
     })
161
     })

+ 3
- 3
viz/app.R View File

14
 shpf <- readOGR(dsn="sa20025WGSfilcth")
14
 shpf <- readOGR(dsn="sa20025WGSfilcth")
15
 sa.in.dest <- shpf@data$SA22018_V1 %in% work_to$work_code
15
 sa.in.dest <- shpf@data$SA22018_V1 %in% work_to$work_code
16
 sa.in.home <- shpf@data$SA22018_V1 %in% work_from$res_code
16
 sa.in.home <- shpf@data$SA22018_V1 %in% work_from$res_code
17
-transport.t <- c("Work at home", "Private car", "Company car", 
18
-                "Carpool", "Bus", "Train", "Bicycle", "Walk",
19
-                "Ferry", "Other", "None/Unknown")
17
+transport.t <- c("Private car", "Passenger in car",
18
+                 "Bicycle", "Walk", "Company car", "Bus", "Train",
19
+                 "Ferry", "Work at home", "Other", "None/Unknown")
20
 edu.t <- c("Drive self", "Passenger in car", "Walk", "Bicycle",
20
 edu.t <- c("Drive self", "Passenger in car", "Walk", "Bicycle",
21
            "School bus", "Public bus", "Train", "Ferry", "Study at home",
21
            "School bus", "Public bus", "Train", "Ferry", "Study at home",
22
            "Other", "None/Unknown")
22
            "Other", "None/Unknown")

+ 8
- 4
viz/extras.R View File

142
     a(href=
142
     a(href=
143
 "https://www.stats.govt.nz/2018-census/there-and-back-
143
 "https://www.stats.govt.nz/2018-census/there-and-back-
144
 again-data-visualisation-competition", "data visualisation competition",
144
 again-data-visualisation-competition", "data visualisation competition",
145
-    .noWS = "after"), ". The source data counts employed persons 15 years or ",
146
-    "older who gave an employment location in the 2018 census."),
145
+    .noWS = "after"), ". The employment data counts employed persons 15 years or ",
146
+    "older who gave an employment location in the 2018 census, while the ",
147
+    "education data counts people in education 15 years or older who gave an ",
148
+    "education location in the 2018 census—including older highschoolers and ",
149
+    "university students, but not e.g. primary school students."),
147
   h4("Options"),
150
   h4("Options"),
148
   p("The top right panel (toggleable via the blue switch) allows ",
151
   p("The top right panel (toggleable via the blue switch) allows ",
149
     "you to choose between visualising the people who commute from ",
152
     "you to choose between visualising the people who commute from ",
150
-    "and to each area, and between showing numbers of people or ",
153
+    "and to each area to both employment and education, and between ",
154
+    "showing numbers of people or ",
151
     "their primary mode of transportation."),
155
     "their primary mode of transportation."),
152
   p("Select an area by clicking on it; deselect by clicking it again ",
156
   p("Select an area by clicking on it; deselect by clicking it again ",
153
     "or clicking in the water. When an area is selected the map is ",
157
     "or clicking in the water. When an area is selected the map is ",
154
     "coloured according to the people who commute to or from that area ",
158
     "coloured according to the people who commute to or from that area ",
155
     "(including the people who commute within the area). When no area is ",
159
     "(including the people who commute within the area). When no area is ",
156
     "selected, colouring is according to commutes to or from all ",
160
     "selected, colouring is according to commutes to or from all ",
157
-    "localities."),
161
+    "localities. Hover over areas for a summary."),
158
   h4("FAQ"),
162
   h4("FAQ"),
159
   shiny::tags$blockquote("Why are so many areas marked as 'works at ",
163
   shiny::tags$blockquote("Why are so many areas marked as 'works at ",
160
                          "home'?"),
164
                          "home'?"),