Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.