summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2018-07-31 17:36:16 (GMT)
committerKen Kellner <ken@kenkellner.com>2018-07-31 17:36:16 (GMT)
commitca25228ccbfb1ef525c949f25d0eb12aa827e642 (patch)
treeb5a1d188a5b868bc9c5379a753549fa4d25d2853
parentfb5e94ca0967a7f107aceb93242f4c20acf5d640 (diff)
Example code for maps generated in R
-rw-r--r--hee_map.R85
1 files changed, 85 insertions, 0 deletions
diff --git a/hee_map.R b/hee_map.R
new file mode 100644
index 0000000..eb61651
--- /dev/null
+++ b/hee_map.R
@@ -0,0 +1,85 @@
+suppressMesssages(library(ggplot2))
+suppressMessages(library(sf))
+options(tidyverse.quiet=TRUE)
+library(tidyverse)
+suppressMessages(library(ggsn))
+
+setwd('~/research/gis/boundaries')
+
+mmyf_bounds = st_read('mmsf_ysf_boundaries.shp',quiet=T) %>%
+ mutate(is_forest = 'State Forest')
+hee_bounds = st_read('hee_cores.shp',quiet=T)[1:9,] %>%
+ mutate(Treatment = factor(Treatment, levels=c('Even-aged','Uneven-aged',
+ 'Control')))
+harvest_bounds = st_read('hee_harvests_2008.shp',quiet=T) %>%
+ mutate(HarvestTyp = factor(HarvestTyp,levels=c('clearcut','shelter',
+ 'patch','single-tree','no harvest')),
+ HarvestTyp = fct_recode(HarvestTyp,Clearcut='clearcut',
+ Shelterwood ='shelter',`Patch Cut` = 'patch',
+ `Single-tree` = 'single-tree',
+ `No Harvest` = 'no harvest'))
+
+bird_points = st_read('../experiments/hee_bird_points_all.shp',quiet=T) %>%
+ filter(Unit %in% 1:3) %>%
+ mutate(label = 'Bird Point')
+
+hee_coords = st_coordinates(hee_bounds)
+
+hee_map = mmyf_bounds %>% ggplot() +
+ geom_sf(aes(fill=is_forest)) +
+ geom_sf(data=hee_bounds,aes(fill=Treatment)) +
+ scale_fill_manual(name=NULL,
+ values=c('gray','firebrick1','gray95','dodgerblue'),
+ breaks=c('State Forest','Even-aged','Uneven-aged',
+ 'Control')) +
+ coord_sf(xlim=range(hee_coords[,'X']),
+ ylim=range(hee_coords[,'Y'])) +
+ theme_void() +
+ theme(axis.title.x=element_blank(),
+ axis.title.y=element_blank(),
+ axis.text.x=element_blank(),
+ axis.text.y=element_blank(),
+ legend.position=c(0.8,0.9),
+ legend.text=element_text(size=9),
+ legend.title=NULL,
+ panel.grid.major = element_line(color = 'transparent')) +
+ scalebar(hee_bounds,dist=2,dd2km=F,st.size=3,location='bottomleft')
+
+hee_map
+
+##
+
+hee_sub = hee_bounds %>%
+ filter(UnitNumber %in% 1:3)
+
+sub_coords = st_coordinates(hee_sub)
+
+sub_map = mmyf_bounds %>% ggplot() +
+ geom_sf(aes(fill=is_forest)) +
+ geom_sf(data=hee_sub) +
+ geom_sf(data=harvest_bounds,aes(fill=HarvestTyp)) +
+ geom_sf(data=bird_points,aes(color=label),show.legend='point') +
+ scale_color_manual(name=NULL, values=c('Bird Point' = 'black'),
+ guide = guide_legend(order=1)) +
+ scale_fill_manual(name=NULL,
+ values=c('firebrick1','gray','orange','dodgerblue',
+ 'forestgreen','gray95'),
+ breaks=c('State Forest','Clearcut','Shelterwood',
+ 'Patch Cut','Single-tree','No Harvest'),
+ guide = guide_legend(override.aes =
+ list(shape = NA),order=2,
+ title.position='bottom')) +
+ coord_sf(xlim=range(sub_coords[,'X']),
+ ylim=range(sub_coords[,'Y'])) +
+ theme_void() +
+ theme(axis.title.x=element_blank(),
+ axis.title.y=element_blank(),
+ axis.text.x=element_blank(),
+ axis.text.y=element_blank(),
+ legend.position=c(0.8,0.36),
+ legend.text=element_text(size=9),
+ legend.title=NULL,
+ panel.grid.major = element_line(color = 'transparent')) +
+ scalebar(hee_sub,dist=0.5,dd2km=F,st.size=3,location='topleft')
+
+sub_map