Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Yankim
Last active September 19, 2016 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yankim/5ea82527b5f651681ed922fc2f17813b to your computer and use it in GitHub Desktop.
Save Yankim/5ea82527b5f651681ed922fc2f17813b to your computer and use it in GitHub Desktop.
library(shiny); library(maps); library(mapproj); library(dplyr); library(plotly); library(googleVis); library(car)
data("county.fips")
#Join data by county indentification numbe (fips) to the county data in the maps package
flipjoin = function(x) {
y = read.csv(x)
left_join(county.fips, y, by = c("fips" = "FIPS"))
}
#Data wrangling for map plot
health2 = flipjoin("data/health.csv")
socioeconomic2 = flipjoin("data/socioeconomic.csv")
socioeconomic2$POVRATE10 = as.numeric(as.character(socioeconomic2$POVRATE10))
##read data in for non map data
#Data can be found at http://www.ers.usda.gov/data-products/
#food-environment-atlas/data-access-and-documentation-downloads.aspx
socioeconomic = read.csv("data/socioeconomic.csv")
socioeconomic$POVRATE10 = as.numeric(as.character(socioeconomic$POVRATE10))
socioeconomic$MEDHHINC10 = as.numeric(as.character(socioeconomic$MEDHHINC10))
health = read.csv("data/health.csv")
access = read.csv("data/access.csv")
stores = read.csv("data/stores.csv")
restaurants = read.csv("data/restaurants.csv")
insecurity = read.csv("data/insecurity.csv")
local = read.csv("data/local.csv")
#Joining all the datatables together by the FIPS, id number of counties
fulldb = full_join(socioeconomic, health, by = "FIPS") %>%
full_join(., access, by = "FIPS") %>% full_join(., stores, by = "FIPS") %>%
full_join(., restaurants, by = "FIPS") %>% full_join(., insecurity, by = "FIPS") %>%
full_join(., local, by = "FIPS")
#Selecting just the columns of interest.
fulldb = fulldb[, c("FIPS", "State", "County", "PCT_LACCESS_POP10", "GROCPTH12",
"CONVSPTH12", "FFRPTH12", "FOODINSEC_10_12", "FSRPTH12",
"DIRSALES_FARMS07", "FMRKTPTH13", "VEG_FARMS07", "PCT_DIABETES_ADULTS10",
"PCT_OBESE_ADULTS10", "PCT_HSPA09", "RECFACPTH12", "MEDHHINC10",
"POVRATE10", "PCT_65OLDER10", "PCT_18YOUNGER10")]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment