# # # - - CARTOGRAPHY | Representation of each genus on the map by a photo and its associated name
# We will be satisfied with the Stammen format put under ggplot without more information on the relief otherwise it will be too heavy
# - - - - PACKAGES - - - -
library(ggplot2)
library(ggmap)
library(ggeasy)
library(mapdata)
library(maps)
library(marmap)
library(raster)
library(rasterVis)
library(cowplot)
library(prettymapr)
library(precrec)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 1] Load the global map of Latin America
# We set the desired coordinates
xlimsAmerica <- c(-100,-30)
ylimsAmerica <- c(30,-56)
# Retrieve the map in the desired mode
# -> (terrain-background i.e. nice google map without information)
Amerique_Centrale <- get_stamenmap(bbox = c(left = min(xlimsAmérique),
bottom = min(ylimsAmerica),
right = max(xlimsAmerica),
top = max(ylimsAmerica)),
maptype = "terrain-background",
zoom = 7) # important for detail (+ large number + detail)
Amerique_Centrale<-ggmap(Amerique_Centrale)
ggmap(Amerique_Centrale)
# save with save() in R.data format (will suffice to load() to get the file)
save(Amerique_Centrale, file = "donnees_Amérique_Latine.RData") # save directly in the current directory
# save with ggsave()
ggsave("Carte_Amerique_Latine.png", width = 12 , height = 20) # save by default the last plot made
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 2] Load map of Guadeloupe
xlimsGuadeloupe <- c(-61.85,-61)
ylimsGuadeloupe <- c(15.75,16.55)
# we get the map according to the desired mode
Guadeloupe <- get_stamenmap(bbox = c(left = min(xlimsGuadeloupe),
bottom = min(ylimsGuadeloupe),
right = max(xlimsGuadeloupe),
top = max(ylimsGuadeloupe)),
maptype = "terrain-background", # type of map to represent
zoom = 11) # important for detail (+ large number + detail)
Guadeloupe<-ggmap(Guadeloupe)
Guadeloupe
# Save with save() in R.data format (load() will suffice to retrieve the file)
save(Guadeloupe, file = "Guadeloupe.RData") # save directly in the current directory
# save with ggsave()
ggsave("Guadeloupe.png", width = 15 , height = 12) # save by default the last plot made
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 3] Load map of Madagascar
xlimsMadagascar <- c(40,55)
ylimsMadagascar <- c(-10,-27)
# get the map in the desired mode
Madagascar <- get_stamenmap(bbox = c(left = min(xlimsMadagascar),
bottom = min(ylimsMadagascar),
right = max(xlimsMadagascar),
top = max(ylimsMadagascar)),
maptype = "terrain-background", # type of map to represent
zoom = 8) # important for detail (+ large number + detail)
Madagascar<-ggmap(Madagascar)
ggmap(Madagascar)
save(Madagascar, file = "Madagascar.RData") # save directly to the current directory
# save with ggsave()
ggsave("Madagascar.png", width = 15 , height = 12) # save by default the last plot made
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 4] Plot everything in 1 (SOURCE: https://r-spatial.org/r/2018/10/25/ggplot2-sf-3.html )
# The final map can be created using ggplot2 only, using
# cowplot and the draw_plot function, in which case it is easier to first define
# the key figures for Guadeloupe and Madagascar:
# We transform the maps into a ggplot object (Package ggplotify function as.ggplot) (? Useful?)
library(ggplotify)
Guadeloupe<-as.grob(Guadeloupe)
Madagascar<-as.grob(Madagascar)
(ratioGuadeloupe <- (2500000 - 200000) / (1600000 - (-2400000))
## [1] 0.575
(ratioMadagascar <- (23 - 18) / (-154 - (-161))
## [1] 0.7142857
ggdraw(Amerique_Centrale) +
draw_plot(Guadeloupe,
width = 0.26,
height = 0.26 * 10/6 * ratioGuadeloupe,
x = 0.05,
y = 0.05)
# ..... Ask the question so you don't have to do it on Guimp either
#
Hello !
This is my very first question on a forum dedicated to R and I hope it will go well, I am a biology student in Master and I don't practice R regularly
Here is the background:
I am trying to map on R and so far it works following a internet guide (Drawing beautiful maps programmatically with R, sf and ggplot2 — Part 3: Layouts), my goal is to make the kind of map visible on this link where several maps are combined (example of USA, Alaska & Hawaii in small).
So I loaded all the maps I wanted to show: Latin America, Madagascar and Guadeloupe where the last two maps would come in small.
I tried the two methods proposed on the website which are
(1) - function annotation_custom
(2) - using cowplot and the function draw_plot
My R code is attached,
Please be indulgent, my code is probably not up to the expectations of an official programmer as I am self-taught.
It would be a great help to me, thank you in advance, Thibaud