Created
June 26, 2017 17:08
-
-
Save robwschlegel/225acd5976431425b56271d10dc9b20f to your computer and use it in GitHub Desktop.
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
# Create a bounding box | |
# We want to slightly extend the edges so as to use all of our data | |
left <- ctd[ctd$date == min(ctd$date),] %>% | |
select(-temp) %>% | |
ungroup() %>% | |
mutate(date = date-0.01) | |
bottom <- ctd %>% | |
group_by(date) %>% | |
summarise(depth = min(depth)) %>% | |
mutate(depth = depth-0.01) | |
right <- ctd[ctd$date == max(ctd$date),] %>% | |
select(-temp) %>% | |
ungroup() %>% | |
mutate(date = date+0.01) | |
top <- ctd %>% | |
group_by(date) %>% | |
summarise(depth = max(depth)) %>% | |
mutate(depth = depth+0.01) | |
bounding_box <- rbind(data.frame(left[order(nrow(left):1),]), data.frame(bottom), | |
data.frame(right), data.frame(top[order(nrow(top):1),])) | |
# Now that we have a bounding box we need to | |
# screen out the pixels created outside of it | |
bounding_box_list <- list(bounding_box) | |
names(bounding_box_list[[1]]) <- c("v","w") | |
v <- ctd_mba$date | |
w <- ctd_mba$depth | |
ctd_mba_bound <- ctd_mba[inSide(bounding_box_list, v, w),] | |
# The screened data | |
ggplot(data = ctd_mba_bound, aes(x = date, y = depth)) + | |
geom_raster(aes(fill = temp)) + | |
scale_fill_gradientn(colours = rev(ODV_colours)) + | |
geom_contour(aes(z = temp), binwidth = 2, colour = "black", alpha = 0.2) + | |
geom_contour(aes(z = temp), breaks = 20, colour = "black") + | |
labs(y = "depth (m)", x = NULL, fill = "temp. (°C)") + | |
coord_cartesian(expand = 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment