R 使用ggplot绘制地图,并在地图中绘制点

R 使用ggplot绘制地图,并在地图中绘制点,r,coordinates,sf,R,Coordinates,Sf,我和苏格兰酿酒厂一起研究数据集,我想在地图上显示它们的位置。 因此,我使用以下代码绘制苏格兰及其周边地区,如下所示: library(SpatialEpi) library(tmap) library("sf") library("rnaturalearth") library("rnaturalearthdata") library("rgeos") library("ggspatial") l

我和苏格兰酿酒厂一起研究数据集,我想在地图上显示它们的位置。 因此,我使用以下代码绘制苏格兰及其周边地区,如下所示:

library(SpatialEpi)
library(tmap)
library("sf")
library("rnaturalearth")
library("rnaturalearthdata")
library("rgeos")
library("ggspatial")
library("ggrepel")

world <- ne_countries(scale = "medium", returnclass = "sf")
ggplot(data = world) +
  geom_sf() +
  coord_sf(xlim = c(-13.68, 0.72), ylim = c(54.63, 60.85), expand = FALSE)
库(SpatialEpi)
图书馆(tmap)
图书馆(“sf”)
图书馆(“rnaturalearth”)
图书馆(“RNaturalLearthData”)
图书馆(“rgeos”)
图书馆(“ggspatial”)
库(“ggrepel”)

世界你的酒很烈/威士忌,多可爱的词啊

考虑这一准则;它基于{sf}包和
ggplot2::geom_sf()
函数构建。有关更多信息,请参阅RStudio论坛上讨论绘制地图的其他选项的帖子

但无论如何,这段代码应该能让你开始

library(sf) # general spatial manipulation
library(giscoR) # for the shape of Scotland
library(dplyr) # general data frame manipulation
library(ggplot2) # because ggplot...

# Scotland as a spatial object
scotland <- giscoR::gisco_get_nuts(nuts_id = 'UKM',
                                   resolution = '01') 

# yer data
distilleries <- read.csv("whisky_data.csv") %>% 
  st_as_sf(coords = c("Latitude", "Longitude"), crs = 4326)

# a quick reality check - looks legit
mapview::mapView(distilleries)

# a ggplot object
ggplot() +
  geom_sf(data = scotland, fill = NA, color = "gray45") + # borders of Scotland
  geom_sf(data = distilleries, pch = 4, color = "red") + # the distilleries
  theme_void() +
  labs(title = "Distilleries of Scotland") +
  theme(plot.title = element_text(hjust = 1/2))
library(sf)#通用空间操作
图书馆(giscoR)#苏格兰的形状
库(dplyr)#通用数据帧操作
库(ggplot2)#因为ggplot。。。
#苏格兰作为一个空间物体

苏格兰你的酒很烈/威士忌,多可爱的词啊

考虑这一准则;它基于{sf}包和
ggplot2::geom_sf()
函数构建。有关更多信息,请参阅RStudio论坛上讨论绘制地图的其他选项的帖子

但无论如何,这段代码应该能让你开始

library(sf) # general spatial manipulation
library(giscoR) # for the shape of Scotland
library(dplyr) # general data frame manipulation
library(ggplot2) # because ggplot...

# Scotland as a spatial object
scotland <- giscoR::gisco_get_nuts(nuts_id = 'UKM',
                                   resolution = '01') 

# yer data
distilleries <- read.csv("whisky_data.csv") %>% 
  st_as_sf(coords = c("Latitude", "Longitude"), crs = 4326)

# a quick reality check - looks legit
mapview::mapView(distilleries)

# a ggplot object
ggplot() +
  geom_sf(data = scotland, fill = NA, color = "gray45") + # borders of Scotland
  geom_sf(data = distilleries, pch = 4, color = "red") + # the distilleries
  theme_void() +
  labs(title = "Distilleries of Scotland") +
  theme(plot.title = element_text(hjust = 1/2))
library(sf)#通用空间操作
图书馆(giscoR)#苏格兰的形状
库(dplyr)#通用数据帧操作
库(ggplot2)#因为ggplot。。。
#苏格兰作为一个空间物体
苏格兰