Details

This is an R Markdown document.

Dissertation Research: The purpose of this analysis is to assess how much of the climate space is captured by my samples.

Climate data from WorldClim. Citation: Fick, S.E. and R.J. Hijmans, 2017. Worldclim 2: New 1-km spatial resolution climate surfaces for global land areas. International Journal of Climatology.

Cedrela odorata observation data from GBIF Citation: GBIF (2012). Recommended practices for citation of the data published through the GBIF Network. Version 1.0 (Authored by Vishwas Chavan), Copenhagen: Global Biodiversity Information Facility. Pp.12, ISBN: 87-92020-36-4.

Load packages

library(raster)
library(sp)
library(ggplot2)
library(RColorBrewer)

Load Climate Data

r <- getData("worldclim",var="bio",res=10)
r <- r[[c(1,12)]]
names(r) <- c("Temp","Prec")

Load observations

#gbif data----
gbif<-read.csv("20170726_climate_space.csv",header=1)
names(gbif)
##  [1] "scientificname"   "countrycode"      "decimallatitude" 
##  [4] "decimallongitude" "elevation"        "google_ele"      
##  [7] "year"             "basisofrecord"    "institutioncode" 
## [10] "collectioncode"   "catalognumber"    "recordnumber"    
## [13] "identifiedby"     "license"          "rightsholder"    
## [16] "recordedby"       "lastinterpreted"
coords<-gbif[c(4,3)]
samps<-gbif[c(-3,-4)]

Connect locations to Climate

points <- SpatialPoints(coords, proj4string = r@crs)
values <- extract(r,points) #if this doesn't work, restart R and reload raster package. The error is a conflict with another package. 

clim.space<- cbind.data.frame(coordinates(points),values)
clim.space<-cbind.data.frame(samps, clim.space)
summary(clim.space)
##                                   scientificname  countrycode  
##  Cedrela odorata L.                      :2232   MX     :1299  
##  Cedrela dugesii S. Wats.                : 118   BR     : 264  
##  Cedrela mexicana M. Roemer              :  97   CO     : 222  
##  Cedrela angustifolia Moc. & Sesse ex DC.:  96   PE     : 140  
##  Cedrela occidentalis C. DC. & Rose      :  33   EC     : 109  
##  Cedrela longipetiolulata Harms          :   8   CR     : 102  
##  (Other)                                 :  36   (Other): 484  
##    elevation         google_ele            year     
##  Min.   :-4999.5   Min.   :-3779.30   Min.   :1829  
##  1st Qu.:   34.0   1st Qu.:   82.01   1st Qu.:1980  
##  Median :  250.0   Median :  294.80   Median :1988  
##  Mean   :  510.8   Mean   :  577.64   Mean   :1986  
##  3rd Qu.:  750.0   3rd Qu.:  843.59   3rd Qu.:1997  
##  Max.   : 9999.0   Max.   : 3394.00   Max.   :2017  
##  NA's   :880                          NA's   :331   
##             basisofrecord  institutioncode collectioncode
##  HUMAN_OBSERVATION :  69   MO      : 506   MO     : 505  
##  LITERATURE        :   2   INECOL  : 241   XAL    : 306  
##  LIVING_SPECIMEN   :   2   ENCB-IPN: 195   ENCB   : 212  
##  OBSERVATION       :   2   F       : 165   Botany : 205  
##  PRESERVED_SPECIMEN:2118   IE      : 141   MEXU   : 165  
##  UNKNOWN           : 427   IBUNAM  : 138   (Other):1226  
##                            (Other) :1234   NA's   :   1  
##        catalognumber   recordnumber               identifiedby 
##  NO DISPONIBLE: 291          :1551                      : 563  
##               :  52   s.n.   :  13   NO DISPONIBLE      : 229  
##  NO APLICA    :  33   1      :   8   ND                 : 121  
##  644523       :   4   1054   :   5   T.D. Pennington (K):  68  
##  110671       :   3   1740   :   5   T.D. Pennington    :  61  
##  120632       :   3   14046  :   4   J. Rzedowski       :  43  
##  (Other)      :2234   (Other):1034   (Other)            :1535  
##          license    
##  CC_BY_4_0   : 668  
##  CC_BY_NC_4_0:1515  
##  CC0_1_0     : 437  
##                     
##                     
##                     
##                     
##                                                                         rightsholder
##  Comisi<97>n Nacional para el Conocimiento y Uso de la Biodiversidad (CONABIO):869  
##                                                                               :754  
##  Missouri Botanical Garden                                                    :505  
##  The Field Museum of Natural History                                          :163  
##  The New York Botanical Garden                                                : 95  
##  Universidad Nacional de Colombia                                             : 36  
##  (Other)                                                                      :198  
##               recordedby            lastinterpreted decimallongitude 
##                    : 142   2017-02-17T06:48Z: 937   Min.   :-110.95  
##  NO DISPONIBLE     :  59   2017-03-24T12:57Z:  95   1st Qu.: -96.37  
##  J. Rzedowski      :  36   2017-03-26T12:44Z:  93   Median : -88.11  
##  J. Cuevas S.      :  28   2017-03-26T01:36Z:  87   Mean   : -82.84  
##  CJ                :  20   2017-03-25T11:14Z:  80   3rd Qu.: -74.14  
##  H. D<92>az-Barriga:  18   2017-03-26T00:41Z:  65   Max.   :  32.57  
##  (Other)           :2317   (Other)          :1263                    
##  decimallatitude        Temp            Prec     
##  Min.   :-35.387   Min.   : 78.0   Min.   : 232  
##  1st Qu.:  1.633   1st Qu.:219.0   1st Qu.:1114  
##  Median : 16.716   Median :244.0   Median :1506  
##  Mean   :  9.403   Mean   :232.5   Mean   :1731  
##  3rd Qu.: 19.578   3rd Qu.:257.0   3rd Qu.:2201  
##  Max.   : 26.817   Max.   :286.0   Max.   :7962  
##                    NA's   :11      NA's   :11
#write.csv(clim.space,"20170726_gbif_worldclim.csv",row.names = FALSE)
#removed NA's in EXCEL

clim.space<-read.csv("20170726_gbif_worldclim.csv",header=1)

Load my data and connect to climate data

#my data----
ceod.finch<-read.csv("20170615_mapping.csv",header=1)
names(ceod.finch)
##  [1] "Longitude" "Latitude"  "Spp"       "Tube"      "ID"       
##  [6] "remove"    "N_DATA"    "CAvsSA"    "Country"   "Peru.NvS" 
## [11] "NEcvP"     "CR"        "Elevation" "goog_elev"
coords<-ceod.finch[c(1,2)]
samps<-ceod.finch[c(-1,-2)]

points <- SpatialPoints(coords, proj4string = r@crs)
values <- extract(r,points) #if this doesn't work, restart R and reload raster package. The error is a conflict with another package. 

ceod.clim<- cbind.data.frame(coordinates(points),values)
ceod.clim<-cbind.data.frame(samps, ceod.clim)
summary(ceod.clim)
##    Spp          Tube              ID     remove      N_DATA       CAvsSA 
##  CEOD:82   Min.   :  2.00   ced101 : 1   No:82   Min.   :102721   CA:29  
##            1st Qu.: 82.75   ced103 : 1           1st Qu.:102721   SA:53  
##            Median :148.50   ced104 : 1           Median :102721          
##            Mean   :150.23   ced105 : 1           Mean   :102721          
##            3rd Qu.:227.25   ced109 : 1           3rd Qu.:102721          
##            Max.   :301.00   ced116 : 1           Max.   :102721          
##                             (Other):76                                   
##        Country   Peru.NvS NEcvP   CR       Elevation      
##  Peru      :24   N:16     E:10   NE: 2   Min.   :   8.96  
##  Ecuador   :20   S: 8     W:26   NW: 2   1st Qu.: 126.20  
##  Nicaragua :14   X:58     X:46   SJ: 3   Median : 347.50  
##  Costa Rica: 8                   X :75   Mean   : 549.19  
##  Panama    : 7                           3rd Qu.: 840.00  
##  Bolivia   : 5                           Max.   :2150.00  
##  (Other)   : 4                                            
##    goog_elev        Longitude         Latitude             Temp      
##  Min.   :   4.0   Min.   :-86.88   Min.   :-21.0378   Min.   : 89.0  
##  1st Qu.: 124.5   1st Qu.:-84.06   1st Qu.: -3.8333   1st Qu.:219.2  
##  Median : 350.5   Median :-77.66   Median : -0.7167   Median :247.5  
##  Mean   : 601.5   Mean   :-78.01   Mean   :  0.8934   Mean   :235.7  
##  3rd Qu.: 961.3   3rd Qu.:-73.52   3rd Qu.:  9.9150   3rd Qu.:259.0  
##  Max.   :2624.0   Max.   :-63.37   Max.   : 13.5055   Max.   :269.0  
##                                                                      
##       Prec     
##  Min.   : 749  
##  1st Qu.:1763  
##  Median :2373  
##  Mean   :2418  
##  3rd Qu.:2970  
##  Max.   :4315  
## 

Reload data, some analyses done in Excel (could have been done in R[Add columns for group])

clim.comp<-read.csv("20170726_clim.comp.csv",header=1)

summary(clim.comp)
##      origin          ele          decimallongitude  decimallatitude   
##  MX     :1295   Min.   :   0.00   Min.   :-110.95   Min.   :-35.3869  
##  BR     : 264   1st Qu.:  88.12   1st Qu.: -96.30   1st Qu.: -0.3683  
##  CO     : 220   Median : 300.00   Median : -87.59   Median : 16.0636  
##  PE     : 164   Mean   : 582.89   Mean   : -82.76   Mean   :  9.1224  
##  EC     : 129   3rd Qu.: 847.47   3rd Qu.: -74.14   3rd Qu.: 19.5388  
##  CR     : 110   Max.   :3394.00   Max.   :  32.57   Max.   : 26.8167  
##  (Other): 509                                                         
##       Temp            Prec             cat      
##  Min.   : 78.0   Min.   : 232   finch    :  33  
##  1st Qu.:219.0   1st Qu.:1125   finch.epb:  49  
##  Median :244.0   Median :1542   gbif     :2609  
##  Mean   :232.6   Mean   :1752                   
##  3rd Qu.:257.0   3rd Qu.:2249                   
##  Max.   :286.0   Max.   :7962                   
## 
finch <- clim.comp[ which(clim.comp$cat!='gbif'), ]
mytitle<-expression(paste(italic("Cedrela odorata"), " Climate Space A"))

clim.space.plot<-ggplot(data=clim.comp,aes(Temp,Prec))+geom_hex(bins=50)+theme_bw()+
  scale_fill_gradient(low = "grey", high = "black",
                      name="Sample\nDensity")+
  geom_point(data=finch, aes(Temp,Prec, color=cat))+
  scale_color_manual(values = c("blue","red"),
                     labels=c("All", "Candidate"),
                     name="Sample\nCategory")+
  labs(x="Mean Annual Temperature (Cº x 10)",y="Mean Annual Precipitation (mm)")+
  theme(panel.grid = element_blank())+
  ggtitle(mytitle)

#ggsave("20170726_clim.space.plot.pdf", clim.space.plot,width=7,height=6)

mytitle.2<-expression(paste(italic("Cedrela odorata"), " Climate Space B"))

clim.space.plot.2<-ggplot(data=clim.comp,aes(ele,Prec))+geom_hex(bins=50)+theme_bw()+
  scale_fill_gradient(low = "grey", high = "black",
                      name="Sample\nDensity")+
  geom_point(data=finch, aes(ele,Prec, color=cat))+
  scale_color_manual(values = c("blue","red"),
                     labels=c("All", "Candidate"),
                     name="Sample\nCategory")+
  labs(x="Elevation (m)",y="Mean Annual Precipitation (mm)")+
  theme(panel.grid = element_blank())+
  ggtitle(mytitle.2)

#ggsave("20170726_clim.space.plot.2.pdf", clim.space.plot.2,width=7,height=6)
clim.space.plot

clim.space.plot.2

Climate correlations

ec.p.bo<-read.csv("20170725_mapping_clim.csv",header=1)
names(ec.p.bo)
##  [1] "X"        "INDV"     "origin"   "elev"     "nvs"      "ec.p.evw"
##  [7] "elev.lvh" "long"     "lat"      "Temp"     "Prec"     "t.group" 
## [13] "p.group"
clim<-ec.p.bo[c(4,8,9,10,11)]

library(PerformanceAnalytics)
chart.Correlation(clim, histogram=TRUE, pch=19)