Skip to content

Instantly share code, notes, and snippets.

@jebyrnes
Created January 3, 2018 18:53
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 jebyrnes/8112e7eed4fb3af9dcf6b0bea30ce4b7 to your computer and use it in GitHub Desktop.
Save jebyrnes/8112e7eed4fb3af9dcf6b0bea30ce4b7 to your computer and use it in GitHub Desktop.
A contrast between sp plot and ggplot with thresholds producing different results
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