问题描述
我正在尝试制作与此类似的立体地图:
I am trying to produce a sterographic map similarly to this:
我要添加的内容是
- 坐标
- 纹线
这可以在基数R中或在ggplot2中使用.感谢您的帮助.
This can be in both base R or with ggplot2. Any help is appreciated.
到目前为止我的尝试
library(rgdal)
library(raster)
proj <- "+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +a=6378273 +b=6356889.449 +units=m +no_defs"
data("wrld_simpl", package = "maptools")
wm <- crop(wrld_simpl, extent(-180, 180, 45, 90))
plot(wm)
wm <- spTransform(wm, CRSobj = CRS(proj))
plot(wm)
推荐答案
要复制的地图非常复杂,并且使其工作所需的所有细节似乎都超出了单个问题的范围.但是,这是您需要的大多数东西.
This is quite a complex map to reproduce, and all the details required to make it work seem beyond the scope of a single question. However, this is most of the stuff you require.
在ggplot中执行此操作更容易使用使用基本图形进行操作.但是,这是一个非常复杂的图形.
Doing this in ggplot is easier to do that using the base graphics. However, it is quite a complex graph to make.
我不得不使用一些技巧来使其正常工作.特别是,从 coord_map
生成的轴并没有在绘图的边缘结束,因此我不得不手动删除轴,然后使用 geom_text
和 geom_segment 下面的行.
I have had to use a few hacks to get it to work. In particular, the axes produced from coord_map
did not end at the edge of the plot, so I had to manually delete the axes and then recreate them using the geom_text
and geom_segment
lines below.
library(rgdal)
library(raster)
library(ggplot2)
# Defines the x axes required
x_lines <- seq(-120,180, by = 60)
ggplot() +
geom_polygon(data = wm_ggplot, aes(x = long, y = lat, group = group), fill = "grey", colour = "black", alpha = 0.8) +
# Convert to polar coordinates
coord_map("ortho", orientation = c(90, 0, 0)) +
scale_y_continuous(breaks = seq(45, 90, by = 5), labels = NULL) +
# Removes Axes and labels
scale_x_continuous(breaks = NULL) +
xlab("") +
ylab("") +
# Adds labels
geom_text(aes(x = 180, y = seq(55, 85, by = 10), hjust = -0.2, label = paste0(seq(55, 85, by = 10), "°N"))) +
geom_text(aes(x = x_lines, y = 39, label = c("120°W", "60°W", "0°", "60°E", "120°E", "180°W"))) +
# Adds axes
geom_hline(aes(yintercept = 45), size = 1) +
geom_segment(aes(y = 45, yend = 90, x = x_lines, xend = x_lines), linetype = "dashed") +
# Change theme to remove axes and ticks
theme(panel.background = element_blank(),
panel.grid.major = element_line(size = 0.25, linetype = 'dashed',
colour = "black"),
axis.ticks=element_blank()) +
labs(caption = "Designed by Mikey Harper")
这篇关于R中的极地/地形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!