-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from erstearns/publish_app
Updating master with latest, published app code
- Loading branch information
Showing
31 changed files
with
1,571 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
############################################ | ||
# code author: erin stearns | ||
# script objective: create animations to use in Shiny app (non-interactive) | ||
# date: 15 May 2019 | ||
########################################### | ||
|
||
rm(list = ls()) | ||
|
||
###################################################################################################### | ||
# -------------------------------------- set up environment ---------------------------------------- # | ||
###################################################################################################### | ||
#load packages | ||
pacman::p_load(data.table, tidycensus, tidyr, tidyverse,dplyr, feather, sf, tmap, viridis, RColorBrewer) | ||
|
||
###################################################################################################### | ||
# -------------------------------------- load data ------------------------------------------------- | ||
###################################################################################################### | ||
#load spatial data | ||
geodata <- readRDS('mod_geo_mockup/data/sf_acs5_2007_2017_w2010counties_v.Rds') | ||
#transform spatial data to wgs84 | ||
geodata <- st_transform(geodata, crs = 4326) | ||
|
||
###################################################################################################### | ||
# -------------------------------------- make tmap --------------------------------------------------- | ||
###################################################################################################### | ||
# -- going to animate the black-white ratio | ||
# rename | ||
geo <- setnames(geodata, "blackwhite_ratio", "Black-White Ratio") | ||
|
||
#explore var | ||
summary(geo$`Black-White Ratio`) | ||
|
||
#subset to contiguous US for visualization purposes | ||
usa_contig <- geo[!geo$state_name %in% c("Alaska", "Hawaii", "Puerto Rico"),] | ||
#bounding box for plotting | ||
bb_contig <- st_bbox(usa_contig) | ||
#take a look | ||
plot(usa_contig["median_income"]) | ||
|
||
#create palette | ||
div.pal = viridis::viridis(n = 8, direction = -1) | ||
div.pal <- brewer.pal(9, "RdBu") | ||
|
||
#create breaks | ||
pb = c(0, .006, 0.02, 0.17, 1, 2, 4, 6, 7) | ||
|
||
#create map | ||
facet_anim <- tm_shape(geo, bbox = bb_contig) + | ||
tm_polygons("Black-White Ratio", colorNA = NULL, palette = div.pal, breaks = pb) + | ||
tm_facets(free.scales.fill = FALSE, ncol = 1, nrow = 1, along = "year") + | ||
tm_shape(usa_contig) + | ||
tm_borders(lwd = 2) + | ||
tm_layout(legend.position = c("left", "bottom")) | ||
|
||
#create animation | ||
tmap_animation(tm = facet_anim, filename = "animation/blackwhiteratio.gif") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
############################################## | ||
# Code author: erin r stearns | ||
# Code objective: create MoD shiny mock up - global script | ||
# Date: 1.8.2019 | ||
############################################# | ||
|
||
##################################################### | ||
# --------------- TO DO ITEMS ----------------------- | ||
# - Make auto-subsetting in response to map panning | ||
# - Make map plot 2 vals in -- base poly color and then centroid graduated symbols | ||
# - add Github link if open source | ||
# --------------------------------------------------- | ||
|
||
|
||
###################################################################################################### | ||
# -------------------------------------- set up ---------------------------------------------------- # | ||
###################################################################################################### | ||
library(shiny) | ||
library(leaflet) | ||
library(leaflet.extras) | ||
library(RColorBrewer) | ||
library(rgdal) | ||
library(sf) | ||
library(ggplot2) | ||
library(ggvis) | ||
library(shinydashboard) | ||
library(dplyr) | ||
library(fontawesome) | ||
require(raster) | ||
require(gstat) | ||
library(OneR) | ||
|
||
# -------------------------------------- load data ------------------------------------------------- | ||
#load spatial data | ||
geodata <- readRDS('mod_geo_mockup/data/sf_acs5_2007_2017_w2010counties_v.Rds') | ||
#transform spatial data to wgs84 | ||
geodata <- st_transform(geodata, crs = 4326) | ||
|
||
#load aspatial data | ||
adata <- readRDS('mod_geo_mockup/data/acs5_2007_2017_fin.Rds') | ||
|
||
#model data | ||
moddata <- readRDS('mod_geo_mockup/data/eb_rtg.Rds') | ||
|
||
#spatial model data | ||
geomod <- readRDS('mod_geo_mockup/data/eb_spatial_v.Rds') | ||
#transform spatial data to wgs84 | ||
geomod <- st_transform(geomod, crs = 4326) | ||
|
||
# -------------------------------------- app inputs defined ---------------------------------------- | ||
#state choices | ||
state_names <- as.character(unique(adata$state_name)) | ||
|
||
#state choices for modeled data | ||
mod_state_names <- as.character(unique(moddata$state_name)) |
Oops, something went wrong.