-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathOutputMaps.Rmd
132 lines (87 loc) · 3.4 KB
/
OutputMaps.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
---
title: "OutpuMaps"
author: "Leon Danon"
date: "07/02/2020"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Spatial Analysis
```{r}
library(tidyverse)
library(sf)
library(rgdal)
library(viridis)
library(mapview)
WardsEW <- read_sf(dsn='~/GitHub/MetaWards/data/2011/shapefile/Wards_December_2011_Boundaries_EW_BFC',layer = 'Wards_December_2011_Boundaries_EW_BFC')
st_centroid(WardsEW)->wardCentroids
wardlookup<-read.csv('~/GitHub/MetaWards/data/2011/WardsProcessing/Ward_Lookup.csv')
wardCentroids %>%
inner_join(.,wardlookup,by=c('wd11cd'='WD11CD'))->wardslookup2
#mapview(wardslookup2,zcol='FID')
```
```{r}
allinfectionsShef=read.table(file='ForMattData.dat',sep = ' ')
allinfectionsShef %>% # make long data frame
mutate(Time=row_number()) %>% # count up time, as row number
pivot_longer(-Time) %>%
mutate(Ward=as.integer(str_remove(name,'V'))) %>%
select(-name)->inf_longShef # rename name to Ward integers for easier matching
inf_longShef %>%
group_by(Ward) %>% # by ward
filter(cumsum(value) < 1) %>% # cumulative sum > 1 means it's just arrived/first infection
mutate(Arrival=max(Time)) %>% # find the maximum before that
filter(row_number()==1) %>% # take the first row of group_by
select(Ward,Arrival) %>% # # select columns and rename and save in a data frame
ungroup() -> arrivals
wardslookup2 %>% inner_join(.,arrivals, by=c('FID'='Ward')) %>%
mutate(AltArrival=log(1/Arrival)*100)->wardslookuparrivalShef
mapview(wardslookuparrivalShef,zcol='AltArrival',cex = 'AltArrival')
# plotme %>%
# ggplot(aes(x=Time,y=value,colour=name))+
# geom_line()
```
```{r}
allinfectionsLon=read.table(file='OldRuns/London/0/ForMattData.dat',sep = ' ')
allinfectionsLon %>% # make long data frame
mutate(Time=row_number()) %>% # count up time, as row number
pivot_longer(-Time,values_to = 'Infected') %>%
mutate(Ward=as.integer(str_remove(name,'V'))) %>%
select(-name)->inf_longLon # rename name to Ward integers for easier matching
inf_longLon %>%
group_by(Ward) %>% # by ward
filter(cumsum(Infected) < 1) %>% # cumulative sum > 1 means it's just arrived/first infection
mutate(Arrival=max(Time)) %>% # find the maximum before that
filter(row_number()==1) %>% # take the first row of group_by
select(Ward,Arrival) %>% # # select columns and rename and save in a data frame
ungroup() -> arrivalsLon
inf_longLon %>%
group_by(Ward) %>%
slice(which.max(Infected))->TimeToPeak
```
```{r}
TimeToPeak %>%
ggplot(aes(x=Time))+
geom_histogram()
arrivalsLon %>%
ggplot(aes(x=Arrival))+
geom_histogram()
```
```{r}
wardslookup2 %>%
inner_join(.,arrivalsLon, by=c('FID'='Ward')) %>%
mutate(AltArrival=log(1/Arrival)*100)->wardslookuparrivalLon
wardslookuparrivalLon %>%
inner_join(.,TimeToPeak, by=c('FID'='Ward'))%>%
mutate(AltTime=Arrival/1000)->wardslookuparrivaltimetopeakL
mapview(wardslookuparrivaltimetopeakL,zcol='Arrival',cex = 'AltTime')
# TODO:
# Time to peak. DONE
# Time to 10 cases.
# Lookup from Postcode to Ward/OA.
```
```{r ccg map}
CCGEW <- read_sf(dsn='~/GitHub/MetaWards/data/2011/shapefile/Clinical_Commissioning_Groups_April_2018_Full_Clipped_Boundaries_in_England',layer = 'Clinical_Commissioning_Groups_April_2018_Full_Clipped_Boundaries_in_England')
mapview(CCGEW)+mapview(wardslookuparrivaltimetopeakL,zcol='Time',cex = 'AltTime')
```