# ----------
## ATTENTION
# ----------
# ---------------------------------------------------------------
## ALL Data needed for plotting this map is available at:
# <https://github.com/ricoperdiz/Tutorials/tree/master/R_map_2018_Farronayetal>
## Script author: Ricardo Perdiz <ricardoperdiz@yahoo.com>
## Any doubts or error, please leave an issue at <github.com/ricoperdiz/Tutorials/> or write an email.
# ---------------------------------------------------------------
# list of packages needed for this tutorial
package_list <- c('dplyr', 'stringr', 'readr', 'purrr', 'magrittr', 'broom', 'rgdal', 'measurements', 'GISTools', 'ggsn', 'cowplot', 'sf')
# Run command below to install all packages inside vector package_list
#install.packages(package_list, dependencies = TRUE)
# Run command below to install GitHub version of ggmap package
# Install ggmap package from GitHub version - this is needed in order to be able to download Google Maps nowadays
#if(!requireNamespace("devtools")) {
# install.packages("devtools")
# devtools::install_github("dkahle/ggmap")
# }
# Load packages
libs <- c(package_list, "ggmap")
sapply(libs, library, character.only = TRUE, logical.return = TRUE, quietly = TRUE, warn.conflicts = FALSE)
# If any of the messages below points FALSE, it means that you do not have that package installed. So, please install it before proceeding with the tutorial.
# if you do not remember how to install a package, use the command below
# install.packages("PackageName", dependencies = TRUE)
rgdal: version: 1.3-6, (SVN revision 773) Geospatial Data Abstraction Library extensions to R successfully loaded Loaded GDAL runtime: GDAL 2.1.3, released 2017/20/01 Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rgdal/gdal GDAL binary built with GEOS: FALSE Loaded PROJ.4 runtime: Rel. 4.9.3, 15 August 2016, [PJ_VERSION: 493] Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rgdal/proj Linking to sp version: 1.3-1 Checking rgeos availability: TRUE Attaching package: ‘MASS’ The following object is masked from ‘package:dplyr’: select rgeos version: 0.4-2, (SVN revision 581) GEOS runtime version: 3.6.1-CAPI-1.10.1 Linking to sp version: 1.3-1 Polygon checking: TRUE Linking to GEOS 3.6.1, GDAL 2.1.3, PROJ 4.9.3 Google Maps API Terms of Service: http://developers.google.com/maps/terms. Please cite ggmap if you use it: see citation("ggmap") for details.
# Macrolobium longipes
nybg <- read_delim('nybg.csv', delim = ',')
splink <- read_delim('splink.csv', delim = ';')
inpa <- read_delim('inpa.csv', delim = ',')
Parsed with column specification: cols( .default = col_character(), DarCatalogNumber = col_double(), DarCollector = col_double(), DarYearCollected = col_double(), DarMinimumElevation = col_logical(), DarMaximumElevation = col_logical(), DarDecimalLatitude = col_double(), DarDecimalLongitude = col_double(), DarGeorefMethod = col_logical(), DarCoordinateUncertaintyInMeter = col_double(), DarSubspecies = col_logical(), DarInfraspecificEpithet = col_logical() ) See spec(...) for full column specifications. Warning message: “4 parsing failures. row col expected actual file 1 -- 33 columns 31 columns 'nybg.csv' 2 -- 33 columns 31 columns 'nybg.csv' 3 -- 33 columns 31 columns 'nybg.csv' 4 -- 33 columns 31 columns 'nybg.csv' ”Parsed with column specification: cols( .default = col_logical(), datelastmodified = col_date(format = ""), institutioncode = col_character(), kingdom = col_character(), descrindividuo = col_character(), codcolbot = col_double(), aux_nomecompunidgeo_invertido = col_character(), codespecime = col_double(), numtombo = col_double(), familia = col_character(), genero = col_character(), sp = col_character(), autorsp = col_character(), nat_typus = col_character(), taxoncompleto = col_character(), pais = col_character(), descrlocal = col_character(), coletor = col_character(), numcoleta = col_double(), diacoleta = col_double(), mescoleta = col_double() # ... with 13 more columns ) See spec(...) for full column specifications. Parsed with column specification: cols( COORD_ = col_character(), HERBARIA = col_character(), COLETOR = col_character(), NUMERO_COL = col_double(), ESPECIE = col_character() )
# Macrolobium aracaense
araca <- read_delim('Maracaense.csv', delim = '\t')
Parsed with column specification: cols( COLETOR = col_character(), NUMERO = col_double(), SP1 = col_logical(), COLDD = col_double(), COLM = col_double(), COLY = col_double(), ADDCOLL = col_character(), COUNTRY = col_character(), MINORAREA = col_character(), MAJORAREA = col_character(), GAZETTER = col_character(), COORDENADAS = col_character(), LATITUDE = col_double(), LONGITUDE = col_double(), HERBARIA = col_character(), DESC_PLANT = col_character(), DESC_HABITAT = col_character() )
# South and Central America shape
area_mapa <- rgdal::readOGR(dsn = 'SAm_CAm_shape.shp')
OGR data source with driver: ESRI Shapefile Source: "/Users/ricoperdiz/Documents/Tutorials/R_map_2018_Farronayetal/SAm_CAm_shape.shp", layer: "SAm_CAm_shape" with 37 features It has 65 fields
# Brazilian states shapefile
estados <- st_read('BRASIL.shp')
Reading layer `BRASIL' from data source `/Users/ricoperdiz/Documents/Tutorials/R_map_2018_Farronayetal/BRASIL.shp' using driver `ESRI Shapefile' Simple feature collection with 27 features and 3 fields geometry type: MULTIPOLYGON dimension: XY bbox: xmin: -73.83943 ymin: -33.77086 xmax: -34.8581 ymax: 5.38289 epsg (SRID): NA proj4string: NA
# Retrive only the state of Amazonas from object `estados`
br_amazonas <- estados %>% filter(ESTADO == 'Amazonas')
br_amazonas
UF | ESTADO | REGIAO | geometry |
---|---|---|---|
AM | Amazonas | NO | MULTIPOLYGON (((-63.47887 2... |
br_amazonas_tidy <- st_geometry(br_amazonas)
br_amazonas_tidy
MULTIPOLYGON (((-63.47887 2.198446, -63.43955 2...
Geometry set for 1 feature geometry type: MULTIPOLYGON dimension: XY bbox: xmin: -73.68224 ymin: -9.847688 xmax: -55.99345 ymax: 2.198446 epsg (SRID): NA proj4string: NA
area_mapa_tidy <- tidy(area_mapa)
area_mapa_tidy
Warning message in bind_rows_(x, .id): “Unequal factor levels: coercing to character”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “Unequal factor levels: coercing to character”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Warning message in bind_rows_(x, .id): “binding character and factor vector, coercing into character vector”Regions defined for each Polygons
long | lat | order | hole | piece | group | id |
---|---|---|---|---|---|---|
-69.99694 | 12.57758 | 1 | FALSE | 1 | 0.1 | 0 |
-69.93639 | 12.53172 | 2 | FALSE | 1 | 0.1 | 0 |
-69.92467 | 12.51923 | 3 | FALSE | 1 | 0.1 | 0 |
-69.91576 | 12.49702 | 4 | FALSE | 1 | 0.1 | 0 |
-69.88020 | 12.45356 | 5 | FALSE | 1 | 0.1 | 0 |
-69.87682 | 12.42739 | 6 | FALSE | 1 | 0.1 | 0 |
-69.88809 | 12.41767 | 7 | FALSE | 1 | 0.1 | 0 |
-69.90880 | 12.41779 | 8 | FALSE | 1 | 0.1 | 0 |
-69.93053 | 12.42597 | 9 | FALSE | 1 | 0.1 | 0 |
-69.94514 | 12.44038 | 10 | FALSE | 1 | 0.1 | 0 |
-69.92467 | 12.44038 | 11 | FALSE | 1 | 0.1 | 0 |
-69.92467 | 12.44721 | 12 | FALSE | 1 | 0.1 | 0 |
-69.95857 | 12.46320 | 13 | FALSE | 1 | 0.1 | 0 |
-70.02766 | 12.52294 | 14 | FALSE | 1 | 0.1 | 0 |
-70.04809 | 12.53115 | 15 | FALSE | 1 | 0.1 | 0 |
-70.05809 | 12.53718 | 16 | FALSE | 1 | 0.1 | 0 |
-70.06241 | 12.54682 | 17 | FALSE | 1 | 0.1 | 0 |
-70.06037 | 12.55695 | 18 | FALSE | 1 | 0.1 | 0 |
-70.05110 | 12.57404 | 19 | FALSE | 1 | 0.1 | 0 |
-70.04874 | 12.58373 | 20 | FALSE | 1 | 0.1 | 0 |
-70.05264 | 12.60000 | 21 | FALSE | 1 | 0.1 | 0 |
-70.05964 | 12.61424 | 22 | FALSE | 1 | 0.1 | 0 |
-70.06111 | 12.62539 | 23 | FALSE | 1 | 0.1 | 0 |
-70.04874 | 12.63215 | 24 | FALSE | 1 | 0.1 | 0 |
-70.00715 | 12.58552 | 25 | FALSE | 1 | 0.1 | 0 |
-69.99694 | 12.57758 | 26 | FALSE | 1 | 0.1 | 0 |
-63.03767 | 18.21296 | 1 | FALSE | 1 | 1.1 | 1 |
-63.09952 | 18.17617 | 2 | FALSE | 1 | 1.1 | 1 |
-63.10237 | 18.18041 | 3 | FALSE | 1 | 1.1 | 1 |
-63.10912 | 18.18504 | 4 | FALSE | 1 | 1.1 | 1 |
⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ | ⋮ |
-64.99362 | 18.34802 | 42 | FALSE | 2 | 36.2 | 36 |
-65.02531 | 18.33893 | 43 | FALSE | 2 | 36.2 | 36 |
-65.04149 | 18.35366 | 44 | FALSE | 2 | 36.2 | 36 |
-65.01187 | 18.36860 | 45 | FALSE | 2 | 36.2 | 36 |
-64.98664 | 18.37482 | 46 | FALSE | 2 | 36.2 | 36 |
-64.95000 | 18.37355 | 47 | FALSE | 2 | 36.2 | 36 |
-64.93498 | 18.36332 | 48 | FALSE | 2 | 36.2 | 36 |
-64.92602 | 18.36615 | 49 | FALSE | 2 | 36.2 | 36 |
-64.94225 | 18.37810 | 50 | FALSE | 2 | 36.2 | 36 |
-64.95003 | 18.38660 | 51 | FALSE | 2 | 36.2 | 36 |
-64.92850 | 18.38037 | 52 | FALSE | 2 | 36.2 | 36 |
-64.66456 | 18.34693 | 53 | FALSE | 3 | 36.3 | 36 |
-64.66039 | 18.33672 | 54 | FALSE | 3 | 36.3 | 36 |
-64.67413 | 18.33446 | 55 | FALSE | 3 | 36.3 | 36 |
-64.70099 | 18.34298 | 56 | FALSE | 3 | 36.3 | 36 |
-64.70816 | 18.34015 | 57 | FALSE | 3 | 36.3 | 36 |
-64.69742 | 18.32654 | 58 | FALSE | 3 | 36.3 | 36 |
-64.70401 | 18.30331 | 59 | FALSE | 3 | 36.3 | 36 |
-64.73623 | 18.31975 | 60 | FALSE | 3 | 36.3 | 36 |
-64.78637 | 18.31522 | 61 | FALSE | 3 | 36.3 | 36 |
-64.80129 | 18.32825 | 62 | FALSE | 3 | 36.3 | 36 |
-64.78637 | 18.34977 | 63 | FALSE | 3 | 36.3 | 36 |
-64.76965 | 18.35659 | 64 | FALSE | 3 | 36.3 | 36 |
-64.75174 | 18.36169 | 65 | FALSE | 3 | 36.3 | 36 |
-64.75591 | 18.36906 | 66 | FALSE | 3 | 36.3 | 36 |
-64.74696 | 18.37359 | 67 | FALSE | 3 | 36.3 | 36 |
-64.71352 | 18.36508 | 68 | FALSE | 3 | 36.3 | 36 |
-64.69740 | 18.36224 | 69 | FALSE | 3 | 36.3 | 36 |
-64.68247 | 18.35600 | 70 | FALSE | 3 | 36.3 | 36 |
-64.66456 | 18.34693 | 71 | FALSE | 3 | 36.3 | 36 |
First, let's clean data for the species Macrolobium longipes
# Macrolobium longipes
# first data from inpa
inpa_modif <- inpa %>%
mutate(
lat = str_split(COORD_, 'N') %>%
sapply('[[', 1 ) %>%
gsub('°' , ' ', .) %>%
gsub("’", " ", .) %>%
paste0(., ' 0') %>%
gsub(" | ", " ", .) %>%
str_trim('both') %>%
measurements::conv_unit(., from = 'deg_min_sec', to = 'dec_deg'),
long = str_split(COORD_, 'N') %>%
sapply('[[', 2) %>%
gsub('°' , ' ', .) %>%
gsub("’", " ", .) %>%
gsub('W', '0', .) %>%
str_trim('both') %>%
gsub(" ", " ", .) %>%
measurements::conv_unit(., from = 'deg_min_sec', to = 'dec_deg')
) %>%
dplyr::select(-COORD_)
inpa_modif
inpa_modif %>% glimpse
HERBARIA | COLETOR | NUMERO_COL | ESPECIE | lat | long |
---|---|---|---|---|---|
INPA | Huber | 5849 | Macrolobium longipes | 1.58333333333333 | 66.55 |
INPA | Rodrigues | 10875 | Macrolobium longipes | 0.333333333333333 | 67.3166666666667 |
Observations: 2 Variables: 6 $ HERBARIA <chr> "INPA", "INPA" $ COLETOR <chr> "Huber", "Rodrigues" $ NUMERO_COL <dbl> 5849, 10875 $ ESPECIE <chr> "Macrolobium longipes", "Macrolobium longipes" $ lat <chr> "1.58333333333333", "0.333333333333333" $ long <chr> "66.55", "67.3166666666667"
names(inpa_modif) <- tolower(names(inpa_modif)) # turn all column names as lower case
names(inpa_modif)
# then we get speciesLink data and select only columns we want to keep
longipes <- splink %>%
dplyr::select(herbaria = institutioncode,
coletor, numero_col = numcoleta,
especie = taxoncompleto,
pais, estado = estado_prov,
local = descrlocal) %>%
# then join them with data from INPA
full_join(inpa_modif, .) %>%
dplyr::select(-estado) %>%
# turn lat and long columns as numeric
mutate_at(
.vars = c('lat', 'long'),
.funs = as.numeric
)
longipes
longipes %>% glimpse
Joining, by = c("herbaria", "coletor", "numero_col", "especie")
herbaria | coletor | numero_col | especie | lat | long | pais | local |
---|---|---|---|---|---|---|---|
INPA | Huber | 5849 | Macrolobium longipes | 1.5833333 | 66.55000 | NA | NA |
INPA | Rodrigues | 10875 | Macrolobium longipes | 0.3333333 | 67.31667 | NA | NA |
JBRJ | Maguire, B. | 37590 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37572 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37643 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37590 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
Observations: 6 Variables: 8 $ herbaria <chr> "INPA", "INPA", "JBRJ", "JBRJ", "JBRJ", "JBRJ" $ coletor <chr> "Huber", "Rodrigues", "Maguire, B.", "Maguire, B.", "Magui… $ numero_col <dbl> 5849, 10875, 37590, 37572, 37643, 37590 $ especie <chr> "Macrolobium longipes", "Macrolobium longipes", "Macrolobi… $ lat <dbl> 1.5833333, 0.3333333, NA, NA, NA, NA $ long <dbl> 66.55000, 67.31667, NA, NA, NA, NA $ pais <chr> NA, NA, "Venezuela", "Venezuela", "Venezuela", "Venezuela" $ local <chr> NA, NA, "Rio Siapa, Casiquiare, Territorio Amazonas. ", "R…
# at last, we get nybg data and select and rename columns that we want to keep
nybg_modif <- nybg %>%
dplyr::select(herbaria = DarInstitutionCode,
coletor = DarCollectorNumber,
numero_col = DarCollector,
local = DarLocality,
lat = DarDecimalLatitude,
long = DarDecimalLongitude,
pais = DarCountry)
nybg_modif
herbaria | coletor | numero_col | local | lat | long | pais |
---|---|---|---|---|---|---|
NY | H. C. de Lima | 3279 | Alto Rio Negro, Rio Uaupés, Igarapé Tibuarí, acima do Seringal Pago | -0.130278 | -67.0892 | Brazil |
NY | B. Maguire | 37590 | On right bank of Río Pacimoni, 50 km above mouth. Alt. 100-140 m. | NA | NA | Venezuela |
NY | B. Maguire | 37590 | On right bank of Río Pacimoni, 50 km above mouth. Alt. 100-140 m. | NA | NA | Venezuela |
NY | W. A. Rodrigues | 10875 | Alto Rio Negro. Igarapé Tuari, do lado oposto à ilha de Aparecida. | 0.333333 | -67.3167 | Brazil |
It is always good to take a look at our data, see column data types, how many observations and variables etc.
longipes
longipes %>% glimpse
herbaria | coletor | numero_col | especie | lat | long | pais | local |
---|---|---|---|---|---|---|---|
INPA | Huber | 5849 | Macrolobium longipes | 1.5833333 | 66.55000 | NA | NA |
INPA | Rodrigues | 10875 | Macrolobium longipes | 0.3333333 | 67.31667 | NA | NA |
JBRJ | Maguire, B. | 37590 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37572 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37643 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37590 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
Observations: 6 Variables: 8 $ herbaria <chr> "INPA", "INPA", "JBRJ", "JBRJ", "JBRJ", "JBRJ" $ coletor <chr> "Huber", "Rodrigues", "Maguire, B.", "Maguire, B.", "Magui… $ numero_col <dbl> 5849, 10875, 37590, 37572, 37643, 37590 $ especie <chr> "Macrolobium longipes", "Macrolobium longipes", "Macrolobi… $ lat <dbl> 1.5833333, 0.3333333, NA, NA, NA, NA $ long <dbl> 66.55000, 67.31667, NA, NA, NA, NA $ pais <chr> NA, NA, "Venezuela", "Venezuela", "Venezuela", "Venezuela" $ local <chr> NA, NA, "Rio Siapa, Casiquiare, Territorio Amazonas. ", "R…
nybg_modif
herbaria | coletor | numero_col | local | lat | long | pais |
---|---|---|---|---|---|---|
NY | H. C. de Lima | 3279 | Alto Rio Negro, Rio Uaupés, Igarapé Tibuarí, acima do Seringal Pago | -0.130278 | -67.0892 | Brazil |
NY | B. Maguire | 37590 | On right bank of Río Pacimoni, 50 km above mouth. Alt. 100-140 m. | NA | NA | Venezuela |
NY | B. Maguire | 37590 | On right bank of Río Pacimoni, 50 km above mouth. Alt. 100-140 m. | NA | NA | Venezuela |
NY | W. A. Rodrigues | 10875 | Alto Rio Negro. Igarapé Tuari, do lado oposto à ilha de Aparecida. | 0.333333 | -67.3167 | Brazil |
longipes <-
longipes %>%
full_join(., nybg_modif)
longipes # now with data from INPA and NY herbaria
Joining, by = c("herbaria", "coletor", "numero_col", "lat", "long", "pais", "local")
herbaria | coletor | numero_col | especie | lat | long | pais | local |
---|---|---|---|---|---|---|---|
INPA | Huber | 5849 | Macrolobium longipes | 1.5833333 | 66.55000 | NA | NA |
INPA | Rodrigues | 10875 | Macrolobium longipes | 0.3333333 | 67.31667 | NA | NA |
JBRJ | Maguire, B. | 37590 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37572 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37643 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
JBRJ | Maguire, B. | 37590 | Macrolobium longipes Cowan | NA | NA | Venezuela | Rio Siapa, Casiquiare, Territorio Amazonas. |
NY | H. C. de Lima | 3279 | NA | -0.1302780 | -67.08920 | Brazil | Alto Rio Negro, Rio Uaupés, Igarapé Tibuarí, acima do Seringal Pago |
NY | B. Maguire | 37590 | NA | NA | NA | Venezuela | On right bank of Río Pacimoni, 50 km above mouth. Alt. 100-140 m. |
NY | B. Maguire | 37590 | NA | NA | NA | Venezuela | On right bank of Río Pacimoni, 50 km above mouth. Alt. 100-140 m. |
NY | W. A. Rodrigues | 10875 | NA | 0.3333330 | -67.31670 | Brazil | Alto Rio Negro. Igarapé Tuari, do lado oposto à ilha de Aparecida. |
longipes <-
longipes %>%
filter(!is.na(lat), coletor != 'Rodrigues') %>%
# add species name in a separate column
mutate(
especie = 'M. longipes'
)
longipes %>% glimpse
Observations: 3 Variables: 8 $ herbaria <chr> "INPA", "NY", "NY" $ coletor <chr> "Huber", "H. C. de Lima", "W. A. Rodrigues" $ numero_col <dbl> 5849, 3279, 10875 $ especie <chr> "M. longipes", "M. longipes", "M. longipes" $ lat <dbl> 1.583333, -0.130278, 0.333333 $ long <dbl> 66.5500, -67.0892, -67.3167 $ pais <chr> NA, "Brazil", "Brazil" $ local <chr> NA, "Alto Rio Negro, Rio Uaupés, Igarapé Tibuarí, acima do…
Now let's clean data that refers to the new species described in Farronay et al. (2018), called Macrolobium aracaense Farroñay.
# Macrolobium aracaense
## Clean data
# turn column names to lower case
names(araca) <- tolower(names(araca))
araca_md <- araca %>%
mutate(
# clean coordinate columns to extract and convert degrees min sec to decimal degrees
lat = str_split(coordenadas, 'N') %>%
sapply('[[', 1 ) %>%
gsub('°' , ' ', .) %>%
gsub("\'|\'\'|\"", " ", .) %>%
gsub(" | ", " ", .) %>%
str_trim('both') %>%
measurements::conv_unit(., from = 'deg_min_sec', to = 'dec_deg'),
# do the same done for long data
long = str_split(coordenadas, 'N') %>%
sapply('[[', 2 ) %>%
gsub('W', '', .) %>%
gsub('°' , ' ', .) %>%
gsub("\'|\'\'|\"", " ", .) %>%
gsub(" | ", " ", .) %>%
str_trim('both') %>%
measurements::conv_unit(., from = 'deg_min_sec', to = 'dec_deg'),
especie = 'M. aracaense'
) %>%
dplyr::select(coletor, numero_col = numero,
pais = country,
lat, long, estado = majorarea, herbaria, especie) %>%
# turn lat and long columns as numeric
mutate_at(
.vars = c('lat', 'long'),
.funs = as.numeric
)
araca_md %>% glimpse
Observations: 2 Variables: 8 $ coletor <chr> "Vicentini, A.", "Farroñay, F." $ numero_col <dbl> 1886, 178 $ pais <chr> "Brasil", "Brasil" $ lat <dbl> 0.9483333, 0.8633333 $ long <dbl> 63.39167, 63.33167 $ estado <chr> "Amazonas", "Amazonas" $ herbaria <chr> "INPA", "INPA" $ especie <chr> "M. aracaense", "M. aracaense"
# join data for Macrolobium longipes and M. aracaense
dados <-
full_join(longipes, araca_md) %>%
dplyr::select(herbaria, coletor, numero_col, especie, lat, long)
dados %>% glimpse
Joining, by = c("herbaria", "coletor", "numero_col", "especie", "lat", "long", "pais")
Observations: 5 Variables: 6 $ herbaria <chr> "INPA", "NY", "NY", "INPA", "INPA" $ coletor <chr> "Huber", "H. C. de Lima", "W. A. Rodrigues", "Vicentini, A… $ numero_col <dbl> 5849, 3279, 10875, 1886, 178 $ especie <chr> "M. longipes", "M. longipes", "M. longipes", "M. aracaense… $ lat <dbl> 1.5833333, -0.1302780, 0.3333330, 0.9483333, 0.8633333 $ long <dbl> 66.55000, -67.08920, -67.31670, 63.39167, 63.33167
dados$long <- ifelse(dados$long > 0, dados$long * -1, dados$long)
longipes <- dados %>%
filter(especie == 'M. longipes')
aracaense <- dados %>%
filter(especie == 'M. aracaense')
Now we have two objects containing desired data for each species, Macrolobium longipes and M. aracaense.
longipes
herbaria | coletor | numero_col | especie | lat | long |
---|---|---|---|---|---|
INPA | Huber | 5849 | M. longipes | 1.583333 | -66.5500 |
NY | H. C. de Lima | 3279 | M. longipes | -0.130278 | -67.0892 |
NY | W. A. Rodrigues | 10875 | M. longipes | 0.333333 | -67.3167 |
aracaense
herbaria | coletor | numero_col | especie | lat | long |
---|---|---|---|---|---|
INPA | Vicentini, A. | 1886 | M. aracaense | 0.9483333 | -63.39167 |
INPA | Farroñay, F. | 178 | M. aracaense | 0.8633333 | -63.33167 |
# longitude range - main map
x1 <- st_bbox(br_amazonas)[c(1,3)]
x1
y1 <- st_bbox(br_amazonas)[c(2,4)]
y1
# longitude and latitude range - for ggmap
lat_long <- dados
y_geral <- range(lat_long$lat) + c(-0.01,0.01)
y_geral
x_geral <- range(lat_long$long) + c(-0.01,0.01)
x_geral
Recently, there was a change in the way of downloading Google maps through ggmap. Now you need to obtain a Google Key and set it with the function displayed in the cell below. After that, you'll be able to download Google maps using the function ggmap::get_map.
For more information, please visit this webpage.
# Place your google KEY here - without it, you WILL NOT be able to download a google map
register_google(key = 'PlaceYourKeyRightHERE!')
#loadfonts()
#local_mp <- c(lon = sum(x_geral)/2, lat = sum(y_geral)/2)
#local_mp
#mapa <- get_map(location = local_mp,
# source = "google",
# maptype = "terrain", crop = FALSE,
# zoom = 7,
# color = 'bw',
# language = 'en-EN')
To see if it worked, try to plot it:
If you had no success in downloading this ggmap, please use RDS file available in this folder and load it to the workspace, using the command below. Remember to remove the comment before executing this cell.
mapa <- readRDS("Farronayetal2017_ggmap.RDS")
ggmap(mapa, extent = 'panel')
# Main map - species distribution
x_escala = -65.1
araca_map1 <-
ggmap(mapa, extent = 'panel') +
xlab('Longitude (WGS84)') +
ylab('Latitude')
# plot the map with X and Y Label on it
# take a first look to see if everything is all right
araca_map1
# Main map
araca_map <- araca_map1 +
geom_point(aes(x = long, y = lat, shape = especie), data = dados, alpha = .8, color ="black", size = 4) +
# add scale bar on topleft
scalebar(x.min = attr(mapa, "bb")[[2]],
y.min = attr(mapa, "bb")[[1]],
x.max = attr(mapa, "bb")[[4]],
y.max = attr(mapa, "bb")[[3]],
dist = 100, anchor = c(x=-66, y=-2.2),
dd2km = T, model = 'WGS84', location = "topleft", st.size = 4, st.dist = 0.02) +
# add North arrow
geom_segment(arrow = arrow(length = unit(4,"mm"), type="closed", angle = 40),
aes(x = x_escala, xend = x_escala,y = -1.7 , yend = -1.3), colour= 'black', size = 2) +
annotate(x = x_escala, y = -1.85, label = 'N', color = 'black', geom = 'text', size = 6,
fontface = 'bold') +
# change ggplot2 theme to Black and White
theme_bw() +
# change few details:
# color contour of panel border, legend position, plot margin etc
theme(panel.border = element_rect(colour = "black", fill=NA, size=1),
legend.title = element_blank(),legend.text = element_text(size = 12, face = 'bold.italic'),
legend.position = 'bottom',
plot.margin = unit(x=c(0.1,0.1,0,0.1),units="in"))
araca_map
# plot the overview map
overviewmap1 <-
ggplot() +
geom_polygon(data = as_tibble(st_coordinates(br_amazonas_tidy)),
aes(x = X, y = Y, group = L1),
color = 'gray70', fill = 'gray70', linetype = 3)
overviewmap1
overviewmap2 <- overviewmap1 +
geom_polygon(data = area_mapa_tidy,
aes(x = long, y = lat, group = group),
color="black", fill=NA) +
geom_point(data = subset(dados, especie %in% 'M. aracaense'),
aes(x = long, y = lat), size = 2,
pch = 19, col = "black")
overviewmap2
overviewmap3 <- overviewmap2 +
coord_equal() +
coord_cartesian(
xlim = x1 - c(2,-2), ylim = y1 - c(2,-2)
)
overviewmap3
Coordinate system already present. Adding new coordinate system, which will replace the existing one.
overviewmap <- overviewmap3 +
theme(plot.background =
element_rect(fill = "white", linetype = 1,
size = 0.3, colour = "black"),
axis.line=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title.x=element_blank(),
axis.title.y=element_blank(),
legend.position="none") +
annotate(x = -63,y = -5,label = 'BRAZIL\nAmazonas',
color = 'black', geom = 'text',
size = 3,fontface = 'bold')
overviewmap
final_map <- ggdraw() +
draw_plot(araca_map, 0, 0, 1, 1) +
draw_plot(overviewmap, 0.15, 0.72, 0.225, 0.225)
final_map
cowplot::ggsave(
plot = final_map,
filename = 'final_map_Macrolobium_aracaense_ggmap.pdf', dpi = 600, width = 6, height = 6, units = 'in')