R:在 x 和 y 轴上使用真实 lon/lat 值
R: Use real lon/lat values at x and y axis
我用 R 生成了以下图表:
library(rnaturalearth)
library(rnaturalearthdata)
library(ggplot2)
library(rworldmap)
library(scales)
library(sf)
library(mapdata)
library(maptools)
library(ggthemes)
data(wrld_simpl)
antarctica <- wrld_simpl[wrld_simpl$NAME == "Antarctica", ]
pr <- "+proj=laea +lat_0=-90 +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
antarctica.laea <- spTransform(antarctica, CRS(pr))
antarctica_plot <- ggplot() +
geom_polygon(data = antarctica.laea, aes(x=long, y=lat, group=group), fill = '#003f5c') +
labs( x = "Longitude", y = "Latitude") +
annotation_scale(location = "bl", width_hint = 0.5) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering) +
theme_wsj()
antarctica_plot
如何在轴上显示真实的纬度和经度值?
您可以通过将空间多边形 (sp)
转换为简单要素 class (sf)
并使用 geom_sf
代替 geom_polygon
来解决此问题。我在任何这些包中都找不到函数 annotation_scale
和 annotation_north_arrow
顺便说一句...
antarctica.laea <- st_as_sf(antarctica.laea)
ggplot(antarctica.laea) +
geom_sf(aes(), fill = '#003f5c')+
labs( x = "Longitude", y = "Latitude") +
theme_wsj()
我用 R 生成了以下图表:
library(rnaturalearth)
library(rnaturalearthdata)
library(ggplot2)
library(rworldmap)
library(scales)
library(sf)
library(mapdata)
library(maptools)
library(ggthemes)
data(wrld_simpl)
antarctica <- wrld_simpl[wrld_simpl$NAME == "Antarctica", ]
pr <- "+proj=laea +lat_0=-90 +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0"
antarctica.laea <- spTransform(antarctica, CRS(pr))
antarctica_plot <- ggplot() +
geom_polygon(data = antarctica.laea, aes(x=long, y=lat, group=group), fill = '#003f5c') +
labs( x = "Longitude", y = "Latitude") +
annotation_scale(location = "bl", width_hint = 0.5) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.75, "in"), pad_y = unit(0.5, "in"),
style = north_arrow_fancy_orienteering) +
theme_wsj()
antarctica_plot
如何在轴上显示真实的纬度和经度值?
您可以通过将空间多边形 (sp)
转换为简单要素 class (sf)
并使用 geom_sf
代替 geom_polygon
来解决此问题。我在任何这些包中都找不到函数 annotation_scale
和 annotation_north_arrow
顺便说一句...
antarctica.laea <- st_as_sf(antarctica.laea)
ggplot(antarctica.laea) +
geom_sf(aes(), fill = '#003f5c')+
labs( x = "Longitude", y = "Latitude") +
theme_wsj()