Last active
April 8, 2016 13:01
-
-
Save jebyrnes/bd680f9ecafb7c6d2839523586d83ee0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(dplyr) | |
| library(ggplot2) | |
| library(meowR); data(regions) | |
| library(sp) | |
| kelp <- read.csv("../01_clean_raw_data/temporal_data_REBENT_Brittany_NW_France.csv") | |
| #Create a spatial Points Data Frame | |
| pts <- with(kelp, SpatialPoints(cbind(Longitude, Latitude), | |
| proj4string=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"))) | |
| pts <- SpatialPointsDataFrame(pts, kelp) | |
| #plot(pts) | |
| #extract regional info | |
| dataRegions <- over(pts, regions) %>% | |
| select(ECOREGION, PROVINCE, REALM) | |
| kelp <- cbind(kelp, dataRegions) | |
| #filter data down | |
| kelpPlot <- kelp %>% | |
| filter(Depth.m > 3) %>% | |
| group_by(Site, Sample.Year, ECOREGION, Sample.ID) %>% | |
| dplyr::summarise(kelp_dens = sum(Stipe.Density.num.per.sq.m)) %>% | |
| ungroup() %>% | |
| group_by(Site, Sample.Year, ECOREGION) %>% | |
| dplyr::summarise(kelp_dens = mean(kelp_dens)) %>% | |
| ungroup() %>% | |
| group_by(Site) %>% | |
| dplyr::mutate(npoints = length(Site), | |
| nYears = length(unique(Sample.Year))) %>% | |
| ungroup() %>% | |
| filter(npoints>2)%>% | |
| filter(nyears>2) | |
| #plot | |
| ggplot(kelpPlot, aes(x=Sample.Year, y = log(kelp_dens+1))) + | |
| geom_line(mapping=aes(group=Site), color="grey") + | |
| geom_point(mapping=aes(group=Site), color="grey") + | |
| stat_smooth(method="lm") + | |
| theme_bw() + | |
| facet_wrap(~ECOREGION) | |
| #plot | |
| ggplot(kelpPlot, aes(x=Sample.Year, y = log(kelp_dens+1), color=Site)) + | |
| geom_line(mapping=aes(group=Site)) + | |
| geom_point(mapping=aes(group=Site)) + | |
| stat_smooth(method="lm", fill=NA) + | |
| theme_bw() + | |
| facet_wrap(~ECOREGION) + | |
| ylim(c(0,5)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment