diff --git a/Data/Pop_1980s.xls b/Data/Pop_1980s.xls new file mode 100644 index 0000000..e1e14fc Binary files /dev/null and b/Data/Pop_1980s.xls differ diff --git a/Scripts/Data_Load.r b/Scripts/Data_Load.r index 88a4851..b9b33cf 100644 --- a/Scripts/Data_Load.r +++ b/Scripts/Data_Load.r @@ -1,7 +1,7 @@ library(rvest) library(tidyverse) library(readxl) - +#setwd("../") ########County, Death, Birth and Migration Data #Data found on the page http://eadiv.state.wy.us/pop/ PAGE <- read_html("http://eadiv.state.wy.us/pop/BirthDeathMig.htm") @@ -118,6 +118,37 @@ TEMP <- TEMP[1:which(TEMP[,1]=="Wind River Res."),] TEMP <- pivot_longer(TEMP,all_of(colnames(TEMP)[-1]),names_to="Year",values_to="Population") %>% mutate(Year=as.integer(Year),Population=as.numeric(Population)) TEMP_COUNTY <- TEMP[grepl("Cnty",TEMP %>% pull(County),ignore.case=TRUE),] -TEMP_CITY <- TEMP[grep("Cnty",TEMP %>% pull(County),ignore.case=TRUE,invert=TRUE),] -TEMP_CITY +TEMP_COUNTY$County <- gsub(" ","_",gsub(" "," ",gsub(" Cnty","",TEMP_COUNTY$County,ignore.case=TRUE))) + +TEMP_CITY <- TEMP[grep("Cnty",TEMP %>% pull(County),ignore.case=TRUE,invert=TRUE),] +TEMP_CITY$County <- gsub("E_Therm","East_Therm",gsub(" ","_",gsub(" ","",TEMP_CITY %>% pull(County)))) +TEMP_CITY <- TEMP_CITY %>% rename(City=County) +TEMP_CITY %>% pull(City) %>% unique %>% sort +CITY_POP <- rbind(TEMP_CITY,CITY_POP) +CITY_POP %>% pull(City) %>% unique %>% sort +COUNTY_POP <- rbind(TEMP_COUNTY,COUNTY_POP) +#ggplot(aes(x=Year,y=Population,group=County,color=County),data=COUNTY_POP)+geom_line() +try(rm(TEMP_CITY,TEMP_COUNTY,TEMP)) +####################County and City Population DAta for 1980-1990 +if(!file.exists("./Data/Pop_1980s.xls")){download.file('http://eadiv.state.wy.us/pop/C&SC8090.xls',"./Data/Pop_1980s.xls")} +TEMP <- read_xls("Data/Pop_1980s.xls",skip=2)[-1:-4,] +colnames(TEMP)[1] <- "County" +TEMP <- TEMP[2:which(TEMP[,1]=="Upton"),1:(min(which(is.na(TEMP[2,])))-1)] +TEMP <- pivot_longer(TEMP,all_of(colnames(TEMP)[-1]),names_to="Year",values_to="Population") %>% mutate(Year=as.integer(Year),Population=as.numeric(Population)) + +TEMP_COUNTY <- TEMP[grepl("Cty",TEMP %>% pull(County),ignore.case=TRUE),] +TEMP_COUNTY$County <- gsub(" ","_",gsub(" "," ",gsub(" Cty","",TEMP_COUNTY$County,ignore.case=TRUE))) + +TEMP_CITY <- TEMP[grep("Cty",TEMP %>% pull(County),ignore.case=TRUE,invert=TRUE),] +TEMP_CITY$County <-gsub("Frannie_","Frannie", gsub("Mtn._View","Mountain_View",gsub("E._Therm","East_Therm",gsub(" ","_",gsub(" ","",TEMP_CITY %>% pull(County)))))) +TEMP_CITY <- TEMP_CITY %>% rename(City=County) + +CITY_POP <- rbind(TEMP_CITY,CITY_POP) +COUNTY_POP <- rbind(TEMP_COUNTY,COUNTY_POP) +#ggplot(aes(x=Year,y=Population,group=County,color=County),data=COUNTY_POP)+geom_line() +try(rm(TEMP_CITY,TEMP_COUNTY,TEMP)) + + + +