Created
January 3, 2018 18:53
-
-
Save jebyrnes/8112e7eed4fb3af9dcf6b0bea30ce4b7 to your computer and use it in GitHub Desktop.
A contrast between sp plot and ggplot with thresholds producing different results
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
library(tidyverse) | |
library(broom) | |
library(sp) | |
library(spdplyr) | |
library(ggplot2) | |
library(rgdal) | |
library(raster) | |
library(rgeos) | |
library(lubridate) | |
#read in spatialPolygonsDataFrame (shapefile) | |
#from https://www.nceas.ucsb.edu/~byrnes/floating_forests/ff_polys_proj.rds | |
classifications <- readRDS("./ff_polys_proj.rds") | |
classifications <- classifications %>% | |
mutate(scene_timestamp = parse_date_time(scene_timestamp, orders="ymdHMS"), | |
quarter = quarter(scene_timestamp, with_year=TRUE, fiscal_start=11)) | |
#convert to data frame | |
classifications_df <- classifications %>% tidy | |
classifications@data$id <- rownames(classifications@data) | |
classifications_df <- left_join(classifications_df, classifications@data) | |
#plot the north coast at a threshold of 6 | |
plot(classifications %>% filter(threshold==6), | |
xlim=c(-124.001673, -122.772273), | |
ylim=c(38.115699,39.176660) ) | |
##ggplot the north coast | |
ggplot() + | |
geom_polygon(data=classifications_df %>% filter(threshold==6), | |
mapping=aes(x=long, y=lat, group=group, | |
frame = threshold)) + | |
theme_bw(base_size=14) + | |
xlab("") + ylab("") + | |
xlim(-124.001673, -122.772273) + | |
ylim(38.115699,39.176660) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment