"Globe"形俄罗斯地图
"Globe"-shaped map of Russia
我使用 GADM 数据绘制了俄罗斯地区的地图:
setwd("~/Desktop/Master thesis/")
library(sp)
library(RColorBrewer)
library(raster)
data <- getData('GADM', country='RUS', level=1)
#exclude columns I don't need
data <- data[,-c(2,3,4,5,7,8,9,10,11,12,13)]
data$region <- as.factor(iconv(as.character(data$NAME_1)))
png(file = "~/Desktop/myplot2.png", width = 1300, height = 700, units = "px")
spplot(data, "region", xlim=c(15,190), ylim=c(40,83), col.regions = colorRampPalette(brewer.pal(12, "Set3"))(85), col = "white")
dev.off()
我得到的地图:
我得到的地图太"flat",看起来不像地图f.e。来自维基百科。地图的左右部分应该稍微转动(因为它们是由于地球的形状)。
来自 Wiki 的地图:
有没有办法让它更"globe-shaped"?
如果您不介意使用 ggplot2,您可以使用 coord_map("azequalarea")
。
创建数据框:
library(ggplot2)
library(maptools)
data.f <- fortify(data, region = "region")
然后剧情:
ggplot(data.f) +
geom_polygon(aes(x = long, y = lat, fill = id, group = group), colour = "white") +
xlim(15,190) +
ylim(40,83) +
coord_map("azequalarea") +
scale_fill_manual(values = colorRampPalette(brewer.pal(12, "Set3"))(85)) +
theme(axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_blank())
我使用 GADM 数据绘制了俄罗斯地区的地图:
setwd("~/Desktop/Master thesis/")
library(sp)
library(RColorBrewer)
library(raster)
data <- getData('GADM', country='RUS', level=1)
#exclude columns I don't need
data <- data[,-c(2,3,4,5,7,8,9,10,11,12,13)]
data$region <- as.factor(iconv(as.character(data$NAME_1)))
png(file = "~/Desktop/myplot2.png", width = 1300, height = 700, units = "px")
spplot(data, "region", xlim=c(15,190), ylim=c(40,83), col.regions = colorRampPalette(brewer.pal(12, "Set3"))(85), col = "white")
dev.off()
我得到的地图:
我得到的地图太"flat",看起来不像地图f.e。来自维基百科。地图的左右部分应该稍微转动(因为它们是由于地球的形状)。
来自 Wiki 的地图:
有没有办法让它更"globe-shaped"?
如果您不介意使用 ggplot2,您可以使用 coord_map("azequalarea")
。
创建数据框:
library(ggplot2)
library(maptools)
data.f <- fortify(data, region = "region")
然后剧情:
ggplot(data.f) +
geom_polygon(aes(x = long, y = lat, fill = id, group = group), colour = "white") +
xlim(15,190) +
ylim(40,83) +
coord_map("azequalarea") +
scale_fill_manual(values = colorRampPalette(brewer.pal(12, "Set3"))(85)) +
theme(axis.line = element_blank(),
axis.text.x = element_blank(),
axis.text.y = element_blank(),
axis.ticks = element_blank(),
axis.title.x = element_blank(),
axis.title.y = element_blank(),
panel.background = element_blank(),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.background = element_blank())