Skip to content

Commit

Permalink
mj
Browse files Browse the repository at this point in the history
  • Loading branch information
elin001 committed Jul 6, 2023
1 parent ed1a1a1 commit 8bd1874
Show file tree
Hide file tree
Showing 26 changed files with 513 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .Rproj.user/8CADE01B/sources/prop/171EFBF7
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "117,76",
"scrollLine": "0"
}
6 changes: 6 additions & 0 deletions .Rproj.user/8CADE01B/sources/prop/282E8E50
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "21,0",
"scrollLine": "0"
}
6 changes: 6 additions & 0 deletions .Rproj.user/8CADE01B/sources/prop/65227095
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "11,42",
"scrollLine": "6"
}
6 changes: 6 additions & 0 deletions .Rproj.user/8CADE01B/sources/prop/D9D85F80
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "17,147",
"scrollLine": "8"
}
6 changes: 6 additions & 0 deletions .Rproj.user/8CADE01B/sources/prop/DA89EDF8
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "56,7",
"scrollLine": "16"
}
6 changes: 6 additions & 0 deletions .Rproj.user/8CADE01B/sources/prop/EA7C7384
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "9,0",
"scrollLine": "0"
}
6 changes: 6 additions & 0 deletions .Rproj.user/8CADE01B/sources/prop/F92CFE2A
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"source_window_id": "",
"Source": "Source",
"cursorPosition": "21,10",
"scrollLine": "14"
}
28 changes: 28 additions & 0 deletions .Rproj.user/8CADE01B/sources/session-7f1d55ad/73C8D9BE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"id": "73C8D9BE",
"path": null,
"project_path": null,
"type": "object_explorer",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1688683077840.0,
"source_on_save": false,
"relative_order": 4,
"properties": {
"id": "d0a197b9ed8749e684d1852ccafbbc24",
"name": "uswithdata1",
"title": "uswithdata1",
"language": "R",
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 0,
"encoding": "",
"collab_server": "",
"source_window": "",
"last_content_update": 1688683077840,
"read_only": false,
"read_only_alternatives": []
}
Empty file.
26 changes: 26 additions & 0 deletions .Rproj.user/8CADE01B/sources/session-7f1d55ad/C8782AF5
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "C8782AF5",
"path": "~/Desktop/R/scripts/countyoutscleaner.Rmd",
"project_path": "scripts/countyoutscleaner.Rmd",
"type": "r_markdown",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1688680198801.0,
"source_on_save": false,
"relative_order": 9,
"properties": {
"source_window_id": "",
"Source": "Source",
"cursorPosition": "56,7",
"scrollLine": "15"
},
"folds": "",
"lastKnownWriteTime": 1688686479,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1688687094337,
"read_only": false,
"read_only_alternatives": []
}
73 changes: 73 additions & 0 deletions .Rproj.user/8CADE01B/sources/session-7f1d55ad/C8782AF5-contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@

a cleaner version of countyouts.rmd, for the sake of double checking my work

##loading packages
```{r}
library(tidyverse)
library(sf)
```

##read data
```{r}
countyoutflow <- read.csv("~/Desktop/R/data/countyoutflow2021.csv")

us <- st_read("/Users/elin/Downloads/cb_2018_us_county_500k")
```
##filter it down
```{r}
california <- countyoutflow %>% group_by(y2_countyname) %>% filter(y1_statefips == "6" & y2_statefips !=96 & y2_statefips !=97 & y2_statefips !=98)
```

##adding the full fips code
str_pad makes the fips codes into 3 digits (county) and 2 digits (state) so that they can be concated together into a real ~~boy~~ fips code
```{r}
california$y2_countyfips <- str_pad(california$y2_countyfips, 3, pad = 0)

california$y2_statefips <- str_pad(california$y2_statefips, 2, pad = 0)

california <- california %>% mutate(state2fullfips = str_c(y2_statefips, y2_countyfips))
```

### adding the full fips code to the us shapefile
```{r}
us <- us %>% mutate(fullfips = str_c(STATEFP, COUNTYFP))
```

##grouping
going to group by y2 county names so that i can
```{r}
california %>% group_by(y2_countyname, state2fullfips) %>% summarise(individuals = sum(n2))
```

### integrity check: hennepin county
```{r}
california %>% group_by(y2_countyname) %>% filter(y2_countyname == "Hennepin County") %>% summarise(individuals = sum(n2))
```
it looks right to me but will definitely need a second set of eyes

```{r}
simplified <- california %>% group_by(y2_countyname, state2fullfips) %>% summarise(individuals = sum(n2))
```

##merging
```{r}
uswithdata <- merge(simplified, us, by.x = "state2fullfips", by.y = "fullfips")
```

##print
```{r}
st_write(uswithdata, "uswithdata.shp")
```

okay so that printed well, everything worked the way I wanted to in order to animate in blender. however, the problem is that it contains exclusively the counties to which people migrated from california. (which is correct for its code). HOWEVER (again), it means that there are large swaths of the country that are just blank. so i need 0 values for every county in the country.

the goal: uswithdata1 has 3222 observations of 13 variables. there's a 0 for the counties that received no california migrants

###trying a different merge
```{r}
uswithdata1 <- merge(us, simplified, by.x = "fullfips", by.y = "state2fullfips", all.x = TRUE)

st_write(uswithdata1, "uswithdata.shp")
```

did not create a full country outlook?
34 changes: 34 additions & 0 deletions .Rproj.user/8CADE01B/sources/session-7f1d55ad/DEACC27B
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"id": "DEACC27B",
"path": null,
"project_path": null,
"type": "r_dataframe",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1688681840603.0,
"source_on_save": false,
"relative_order": 3,
"properties": {
"expression": "uswithdata",
"caption": "uswithdata",
"totalObservations": 633,
"displayedObservations": 633,
"variables": 13,
"cacheKey": "6868E546",
"object": "uswithdata",
"environment": "",
"contentUrl": "grid_resource/gridviewer.html?env=&obj=uswithdata&cache_key=6868E546&max_cols=50",
"preview": 0,
"source_window_id": "",
"Source": "Source"
},
"folds": "",
"lastKnownWriteTime": 0,
"encoding": "",
"collab_server": "",
"source_window": "",
"last_content_update": 1688681840603,
"read_only": false,
"read_only_alternatives": []
}
Empty file.
26 changes: 26 additions & 0 deletions .Rproj.user/8CADE01B/sources/session-7f1d55ad/F6062D21
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"id": "F6062D21",
"path": "~/Desktop/R/scripts/countyouts.Rmd",
"project_path": "scripts/countyouts.Rmd",
"type": "r_markdown",
"hash": "0",
"contents": "",
"dirty": false,
"created": 1688153055369.0,
"source_on_save": false,
"relative_order": 1,
"properties": {
"source_window_id": "",
"Source": "Source",
"cursorPosition": "117,76",
"scrollLine": "0"
},
"folds": "",
"lastKnownWriteTime": 1688680191,
"encoding": "UTF-8",
"collab_server": "",
"source_window": "",
"last_content_update": 1688680191047,
"read_only": false,
"read_only_alternatives": []
}
121 changes: 121 additions & 0 deletions .Rproj.user/8CADE01B/sources/session-7f1d55ad/F6062D21-contents
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@

```{r}
library(tidyverse)
library(readxl)
library(tigris)
```
## load the data
outs.xlsx is census data
```{r}
outs <- read_excel("~/Desktop/elliesacbeeR/data/outs.xlsx", sheet=1)

irsouts <- read.csv("~/Desktop/elliesacbeeR/data/countyoutflow2021.csv")

irsins <- read.csv("~/Desktop/elliesacbeeR/data/countyinflow2021.csv")

state2state <- read_excel("~/Desktop/elliesacbeeR/data/2021ca (1).xlsx")

latlongs <- read_csv("https://gist.github.com/russellsamora/12be4f9f574e92413ea3f92ce1bc58e6/raw/3f18230058afd7431a5d394dab7eeb0aafd29d81/us_county_latlng.csv")
```

California state fips code = 06

##filter down
```{r}
nosummaryrows <-irsouts %>% group_by(y2_countyname) %>% filter(y1_statefips == "6" & y2_statefips !=96 & y2_statefips !=97 & y2_statefips !=98)
```

Just four-county area
```{r}
nosummaryrows %>% filter(y1_countyfips == 34 | y1_countyfips == 31 | y1_countyfips == 9 | y1_countyfips == 57)
```
## getting prepped to geocode
using str_pad to make both the county fips code columns and the state fips code columns have leading zeroes so they're like actual fips codes. then, im gonna concatenate the columns.
```{r}
irsins$y1_countyfips <- str_pad(irsins$y1_countyfips, 3, pad = 0)

irsins$y1_statefips <- str_pad(irsins$y1_statefips, 2, pad = 0)

irsins$y2_countyfips <- str_pad(irsins$y2_countyfips, 3, pad = 0)

irsins$y2_statefips <- str_pad(irsins$y2_statefips, 2, pad = 0)

irsins <- irsins %>% mutate(state1fullfips = str_c(y1_statefips, y1_countyfips))

irsins <- irsins %>% mutate(state2fullfips = str_c(y2_statefips, y2_countyfips))
```

formatting both.
```{r}
irsouts$y1_countyfips <- str_pad(irsouts$y1_countyfips, 3, pad = 0)

irsouts$y1_statefips <- str_pad(irsouts$y1_statefips, 2, pad = 0)

irsouts$y2_countyfips <- str_pad(irsouts$y2_countyfips, 3, pad = 0)

irsouts$y2_statefips <- str_pad(irsouts$y2_statefips, 2, pad = 0)

irsouts <- irsouts %>% mutate(state1fullfips = str_c(y1_statefips, y1_countyfips))

irsouts <- irsouts %>% mutate(state2fullfips = str_c(y2_statefips, y2_countyfips))
```

## making a table for outmigration from just california
```{r}
justca <- irsouts %>% group_by(y2_countyname) %>% filter(y1_statefips == "06")

justca <- justca %>% filter(y2_statefips !=96 & y2_statefips !=97 & y2_statefips !=98)

supersimplified <- justca %>% group_by(y2_countyname, state2fullfips) %>% summarise(sum(n2))
```


## to merge with lat long data
```{r}
justcawithlatlong <- merge(justca, latlongs, by.x = "state2fullfips", by.y = "fips_code")
```

##print
```{r}
write.csv(justcawithlatlong, "californiaoutmigration.csv")

justca <- justca[complete.cases(justca), ]

write.csv(justca, "californiaoutmigrationnolatlong.csv")
```

```{r}
mergeddata <- read_csv("~/Desktop/elliesacbeeR/data/merge__california__georef-uni.csv")
```


```{r}
mergeddata <- mergeddata[complete.cases(mergeddata), ]
```


```{r}
write.csv(supersimplified, "supersimplified.csv")
```

Ellie EOD note 6/30:

I need to find the totals for each county's migrants from California. Then, I need to somehow merge that data into a JSON format so that mapbox can read it OR I can open it in After Effects.


## binding data to shp
```{r}
library(sf)
```

```{r}
us <- st_read("/Users/elin/Downloads/cb_2018_us_county_500k")

us <- us %>% mutate(fullfips = str_c(STATEFP, COUNTYFP))

irsouts <- irsouts %>% group_by(y2_countyname) %>% filter(y1_statefips == "6" & y2_statefips !=96 & y2_statefips !=97 & y2_statefips !=98)

uswithdata <- merge(irsouts, us, by.x = "state2fullfips", by.y = "fullfips")

st_write(uswithdata, "uswithdata.shp")
```
Empty file.
Loading

0 comments on commit 8bd1874

Please sign in to comment.