knitr::opts_chunk$set(echo = T)

Load libraries

library(ggmap)
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.1.2
## Google's Terms of Service: https://cloud.google.com/maps-platform/terms/.
## Please cite ggmap if you use it! See citation("ggmap") for details.
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✔ tibble  3.2.1     ✔ dplyr   1.1.1
## ✔ tidyr   1.1.4     ✔ stringr 1.4.0
## ✔ readr   2.1.2     ✔ forcats 0.5.1
## ✔ purrr   1.0.1
## Warning: package 'tibble' was built under R version 4.1.2
## Warning: package 'readr' was built under R version 4.1.2
## Warning: package 'purrr' was built under R version 4.1.2
## Warning: package 'dplyr' was built under R version 4.1.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(ggplot2)

set working directory

wd <- list()
# commonly used paths in my working directory
wd$data   <- "//Users/rasmanns/Dropbox/Lavoro/Manuscripts/2023/Victoria_terpenes/data/processed/"
wd$output <- "/Users/rasmanns/Dropbox/Lavoro/Manuscripts/2023/Victoria_terpenes/data/output/"

World map download with ggmap

maptype = c(“terrain”, “terrain-background”, “terrain-labels”, “terrain-lines”, “toner”, “toner-2010”, “toner-2011”, “toner-background”, “toner-hybrid”, “toner-labels”, “toner-lines”, “toner-lite”, “watercolor”)

world <- get_stamenmap(
  bbox = c(left = -180, bottom = -57, right = 179, top = 82.1), 
  maptype = c( "terrain-background"),
  zoom = 2)
## Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.

import dataset

tab<-read.csv(paste0(wd$data, "data_victoria.csv"), h=T, na.strings= "NA", sep=",", row.names = 1,
              stringsAsFactors=FALSE)

names(tab)
##  [1] "Reference"        "Family"           "Genera"           "Species"         
##  [5] "Glands"           "Status"           "Domesticated"     "Onthogeny"       
##  [9] "Organ_type"       "Organ_position"   "Season"           "Lat"             
## [13] "Long"             "Elevation"        "MH"               "MO"              
## [17] "SH"               "SO"               "Monoterpenoids"   "Sesquiterpenoids"
## [21] "Diterpenoids"     "yield"            "method"
tab$Family <- as.factor(tab$Family)
tab$Genera <- as.factor(tab$Genera)
tab$Species <- as.factor(tab$Species)
tab$Glands <- as.factor(tab$Glands)
tab$Status <- as.factor(tab$Status)
tab$Domesticated <- as.factor(tab$Domesticated)
tab$Onthogeny <- as.factor(tab$Onthogeny)
tab$Organ_type <- as.factor(tab$Organ_type)
tab$Organ_position <- as.factor(tab$Organ_position)
tab$Season <- as.factor(tab$Season)
tab$method <- as.factor(tab$method)

select coordinates and altitude and remove NAs

names(tab)
##  [1] "Reference"        "Family"           "Genera"           "Species"         
##  [5] "Glands"           "Status"           "Domesticated"     "Onthogeny"       
##  [9] "Organ_type"       "Organ_position"   "Season"           "Lat"             
## [13] "Long"             "Elevation"        "MH"               "MO"              
## [17] "SH"               "SO"               "Monoterpenoids"   "Sesquiterpenoids"
## [21] "Diterpenoids"     "yield"            "method"
coord <-  tab %>% 
  select(Lat, Long, Elevation)

coord2 <- na.omit(coord)

Plot with datapoints

map <- ggmap(world) + # creates the map "background"
  geom_point(data = coord2, 
             aes(x = Long, y = Lat, color = Elevation), 
             alpha = .5, 
             size = .5) +
  scale_color_viridis_c(option = "magma")+
  xlab("Longitude") + ylab("Latitude")+
  theme(legend.background = element_blank())
map