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,7 +29,7 @@ locgraph <- graph(edges = elist)
29 29
 sg <- decompose(locgraph, mode="weak")
30 30
 
31 31
 
32
-work_travel %>% rename(
32
+work_travel %>% select(
33 33
   res_code = SA2_code_usual_residence_address,
34 34
   res_name = SA2_name_usual_residence_address,
35 35
   res_east = SA2_usual_residence_easting,
@@ -38,15 +38,15 @@ work_travel %>% rename(
38 38
   work_name = SA2_name_workplace_address,
39 39
   work_east = SA2_workplace_easting,
40 40
   work_north = SA2_workplace_northing,
41
-  home = Work_at_home,
42 41
   private = Drive_a_private_car_truck_or_van,
43
-  company = Drive_a_company_car_truck_or_van,
44 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 46
   bus = Public_bus,
46 47
   train = Train,
47
-  bicycle = Bicycle,
48
-  walk = Walk_or_jog,
49 48
   ferry = Ferry,
49
+  home = Work_at_home,
50 50
   other = Other,
51 51
   total = Total
52 52
 ) -> work_simp
@@ -57,15 +57,15 @@ work_simp %>%
57 57
                          res_east,
58 58
                          res_north) %>%
59 59
   summarise(
60
-    home = sum(ifelse(home < 0, 0, home)),
61 60
     private = sum(ifelse(private < 0, 0, private)),
62
-    company = sum(ifelse(company < 0, 0, company)),
63 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 65
     bus = sum(ifelse(bus < 0, 0, bus)),
65 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 67
     ferry = sum(ifelse(ferry < 0, 0, ferry)),
68
+    home = sum(ifelse(home < 0, 0, home)),
69 69
     other = sum(ifelse(other < 0, 0, other)),
70 70
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
71 71
   ) -> work_from
@@ -77,15 +77,15 @@ work_simp %>%
77 77
                          work_east,
78 78
                          work_north) %>%
79 79
   summarise(
80
-    home = sum(ifelse(home < 0, 0, home)),
81 80
     private = sum(ifelse(private < 0, 0, private)),
82
-    company = sum(ifelse(company < 0, 0, company)),
83 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 85
     bus = sum(ifelse(bus < 0, 0, bus)),
85 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 87
     ferry = sum(ifelse(ferry < 0, 0, ferry)),
88
+    home = sum(ifelse(home < 0, 0, home)),
89 89
     other = sum(ifelse(other < 0, 0, other)),
90 90
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
91 91
   ) -> work_to
@@ -142,20 +142,20 @@ edu_simp %>% group_by(edu_code, edu_name, edu_east, edu_north) %>%
142 142
     total = sum(ifelse(total < 0, 0, total)), .groups="drop"
143 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 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 151
   apply(1, function(x) {
152 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 155
   apply(1, function(x) {
156 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 159
   apply(1, function(x) {
160 160
     ifelse(max(x) <= 0, NA, which.max(x))
161 161
     })

+ 3
- 3
viz/app.R View File

@@ -14,9 +14,9 @@ load(file="datasets.RData")
14 14
 shpf <- readOGR(dsn="sa20025WGSfilcth")
15 15
 sa.in.dest <- shpf@data$SA22018_V1 %in% work_to$work_code
16 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 20
 edu.t <- c("Drive self", "Passenger in car", "Walk", "Bicycle",
21 21
            "School bus", "Public bus", "Train", "Ferry", "Study at home",
22 22
            "Other", "None/Unknown")

+ 8
- 4
viz/extras.R View File

@@ -142,19 +142,23 @@ infotext <- div(class="overflowable",
142 142
     a(href=
143 143
 "https://www.stats.govt.nz/2018-census/there-and-back-
144 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 150
   h4("Options"),
148 151
   p("The top right panel (toggleable via the blue switch) allows ",
149 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 155
     "their primary mode of transportation."),
152 156
   p("Select an area by clicking on it; deselect by clicking it again ",
153 157
     "or clicking in the water. When an area is selected the map is ",
154 158
     "coloured according to the people who commute to or from that area ",
155 159
     "(including the people who commute within the area). When no area is ",
156 160
     "selected, colouring is according to commutes to or from all ",
157
-    "localities."),
161
+    "localities. Hover over areas for a summary."),
158 162
   h4("FAQ"),
159 163
   shiny::tags$blockquote("Why are so many areas marked as 'works at ",
160 164
                          "home'?"),