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 workkind 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_feb_2023.csv"), h=T, na.strings= "NA", sep=",", row.names = 1,
              stringsAsFactors=FALSE)

tab$Latitude <- as.numeric(tab$Latitude)
## Warning: NAs introduced by coercion
tab$Long <- as.numeric(tab$Long)
## Warning: NAs introduced by coercion

select coordinates and altitude and remove NAs

test <- 
  tab %>% 
  filter(is.na(Long))

names(tab)
##  [1] "Reference"        "family"           "Genera"           "Species"         
##  [5] "gland"            "status"           "domesticated"     "onthogeny"       
##  [9] "organ_type"       "position"         "season"           "Latitude"        
## [13] "Long"             "Altitude"         "MH"               "MO"              
## [17] "SH"               "SO"               "Monoterpenoids"   "Sesquiterpenoids"
## [21] "Diterpenoids"     "yield"            "method"
coord <-  tab %>% 
  select(Latitude, Long, Altitude)

coord2 <- na.omit(coord)

Plot with datapoints

ggmap(world) + # creates the map "background"
  geom_point(data = coord2, 
             aes(x = Long, y = Latitude, color = Altitude), 
             alpha = .5, 
             size = .7) +
  scale_color_viridis_c(option = "magma")+
  theme(legend.background = element_blank())