I'm trying to plot a map of France and then show where Paris is.
So with the code below, I can plot a map of France.
library(dplyr)
library(ggplot2)
library(ggsn)
library(here)
library(readr)
library(sf)
u_remote <- "https://biogeo.ucdavis.edu/"
p_remote <- "data/gadm3.6/Rsf/"
f_name <- "gadm36_FRA_1_sf.rds"
fr_rds <- file.path(tempdir(), "gadm36_FRA_1_sf.rds")
if (toupper(Sys.info()["sysname"]) == "WINDOWS") {
download.file(
url = paste0(u_remote, p_remote, f_name),
destfile = fr_rds,
method = "wininet",
mode = "wb"
)
} else {
download.file(
url = paste0(u_remote, p_remote, f_name),
destfile = fr_rds,
method = "auto"
)
}
fr_sf <- readRDS(fr_rds)
ggplot(fr_sf)
geom_sf(fill = "white")
I also got the coordinates of a point in Paris from Google Maps so I thought maybe this works
paris <- data.frame(longitude = c(48.86122650866868), latitude = c(2.341541835915652))
ggplot(fr_sf)
geom_sf(fill = "white")
geom_point(data = paris, aes(x = longitude, y = latitude), size = 4, shape = 23, fill = "darkred")
But I think ggplot converts axis to degrees.
Could someone help with this please?
CodePudding user response:
I think you have simply mixed up latitude and longitude:
paris <- data.frame(latitude = c(48.86122650866868),
longitude = c(2.341541835915652))
ggplot(fr_sf)
geom_sf(fill = "white")
geom_point(data = paris, aes(x = longitude, y = latitude), size = 4,
shape = 23, fill = "darkred")