Modérateur : Groupe des modérateurs
Code : Tout sélectionner
install.packages("mapproj")
library(mapproj)
map(database= "world", col="white", fill=TRUE, projection="mercator")
Code : Tout sélectionner
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods
[7] base
other attached packages:
[1] mapproj_1.2.7 maps_3.3.0 ade4_1.7-13 sfsmisc_1.1-5
[5] shiny_1.1.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.18 digest_0.6.17 later_0.7.4 MASS_7.3-50
[5] mime_0.5 R6_2.2.2 jsonlite_1.7.1 xtable_1.8-3
[9] magrittr_1.5 evaluate_0.14 rlang_0.2.2 promises_1.0.1
[13] rmarkdown_1.16 tools_3.5.1 httpuv_1.4.5 xfun_0.10
[17] yaml_2.2.0 compiler_3.5.1 htmltools_0.3.6 knitr_1.25
Code : Tout sélectionner
> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] fr_FR.UTF-8/fr_FR.UTF-8/fr_FR.UTF-8/C/fr_FR.UTF-8/fr_FR.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] mapproj_1.2.7 maps_3.3.0 shiny_1.4.0.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 digest_0.6.25 later_1.0.0 mime_0.9 R6_2.4.1
[6] jsonlite_1.6.1 xtable_1.8-4 magrittr_1.5 evaluate_0.14 rlang_0.4.6
[11] promises_1.1.0 rticles_0.17 rmarkdown_2.5 tools_4.0.3 fastmap_1.0.1
[16] httpuv_1.5.2 xfun_0.19 yaml_2.2.1 compiler_4.0.3 htmltools_0.4.0
[21] knitr_1.30
Code : Tout sélectionner
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(rnaturalearth)
library(dplyr)
library(ggplot2)
# Creation d'une fonction pour faire le graphique pour différentes projections
plot_earth <- function(crs, lon, lat) {
# Transformation requires st_make_valid()
world_ne <- ne_countries(scale = 50, type = "countries", returnclass = "sf") %>%
select(iso_a3, iso_n3, admin, continent) %>%
st_transform(crs = crs) %>%
sf::st_make_valid()
# Grille
graticule <- st_graticule(ndiscr = 10000, margin = 10e-6,
lon = lon, lat = lat) %>%
st_transform(crs = crs)
# Sphere pour le fond bleu
sphere <- st_graticule(ndiscr = 10000, margin = 10e-6) %>%
st_transform(crs = crs) %>%
st_convex_hull() %>%
summarise(geometry = st_union(geometry))
# Graph
ggplot() +
geom_sf(data = sphere, fill = "cyan") +
geom_sf(data = world_ne) +
geom_sf(data = graticule, size = 0.1) +
theme_bw()
}
# Choix de la grille
# _Longitude
lon <- seq(-180, 180, by = 10)
# _Latitude
lat <- seq(-90, 90, by = 10)
# Choix de la projection
#_laea
crs <- "+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +datum=WGS84 +units=m +no_defs"
plot_earth(crs = crs, lon = lon, lat = lat)
Code : Tout sélectionner
# Sauver en png
ggsave(filename = "proj_laea.png", width = 8, height = 8, units = "cm")
#_moll
crs <- "+proj=moll"
plot_earth(crs = crs, lon = lon, lat = lat)
Code : Tout sélectionner
ggsave(filename = "proj_moll.png", width = 8, height = 8, units = "cm")
#_"+proj=eqearth +wktext"
crs <- "+proj=eqearth +wktext"
plot_earth(crs = crs, lon = lon, lat = lat)
Code : Tout sélectionner
#_Mercator
crs <- 3857
plot_earth(crs = crs, lon = lon, lat = lat)
Code : Tout sélectionner
ggsave(filename = "proj_mercator.png", width = 10, height = 20, units = "cm")
<sup>Created on 2020-12-06 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
Code : Tout sélectionner
ggplot() +
# geom_sf(data = sphere, fill = "cyan") +
geom_sf(data = world_ne) +
geom_sf(data = graticule, size = 0.1) +
theme_bw()
Retourner vers « Questions en cours »
Utilisateurs parcourant ce forum : Google [Bot] et 1 invité