简体   繁体   English

用ggplot2 :: borders()绘制太平洋和大洲

[英]Plot Pacific Ocean and continents with ggplot2::borders()

I would like to use ggplot::borders() showing the Pacific Ocean. 我想使用ggplot::borders()显示太平洋。 My issue is that I cannot figure out how to show Australia and Asia to the west and the Americas to the east. 我的问题是我不知道如何向西展示澳大利亚和亚洲,向东展示美洲。

ggplot() + borders() + coord_cartesian(xlim = c(-290, -70))

In the resulting figure, Asia and Australia should be shown but they're not. 在结果图中,应该显示亚洲和澳大利亚,但没有显示。

没有亚洲和澳大利亚

I would like to do something along the lines of this: 我想做一些类似的事情:

ggplot() + borders() + borders(x = long - 360)

to get a map like this: 得到这样的地图:

世界地图

Can anybody help me figure this out? 有人可以帮我解决这个问题吗? There are answers on SO for the maps and ggmap packages, but I could not find an answer using ggplot2::borders() . 关于mapsggmap包,有关于SO的答案,但是我无法使用ggplot2::borders()找到答案。

One important aspect of any answer is that the lat-lon values are correct. 任何答案的一个重要方面是,经纬度值是正确的。 The challenge is: with traditional longitude coordinates, a view of the Pacific will start with increasing positive values (E hemisphere) then switch to decreasing negative values at the antimeridian (W hemisphere). 面临的挑战是:使用传统的经度坐标,从正值(E半球)开始增加太平洋的视野,然后在反子午线(W半球)处切换为减小负值。 How can I plot this in R preferably borders() ? 如何在R中最好是borders()绘制此图?

惯例

Something like: 就像是:

library(sp)
library(maps)
library(maptools)
library(ggplot2)
library(ggthemes)

world <- map("world", fill=TRUE, col="transparent", plot=FALSE)
worldSpP <- map2SpatialPolygons(world, world$names, CRS("+proj=longlat +ellps=WGS84"))
worldSpP <- worldSpP[-grep("Antarctica", row.names(worldSpP)),]
worldSpP <- worldSpP[-grep("Ghana", row.names(worldSpP)),]
worldSpP <- worldSpP[-grep("UK:Great Britain", row.names(worldSpP)),]
worldSpPnr <- nowrapRecenter(worldSpP)

world_map <- fortify(worldSpPnr)

gg <- ggplot()
gg <- gg + geom_map(data=world_map, map=world_map,
                    aes(x=long, y=lat, map_id=id),
                    color="black", fill="white", size=0.25)
gg <- gg + coord_map()
gg <- gg + theme_map()
gg

在此处输入图片说明

I've tried to zoom it a bit to match more closely what you posted (code below). 我尝试将其放大一点,以使其更贴近您发布的内容(下面的代码)。 Thanks to this answer by kohske 感谢kohske的 回答

ggplot2地图太平洋

# install.packages("mapdata", dependencies = TRUE)
# install.packages("ggplot2", dependencies = TRUE)

library(ggplot2)
library(mapdata)

mp1 <- fortify(map(fill=TRUE, plot=FALSE))
mp2 <- mp1
mp2$long <- mp2$long + 360
mp2$group <- mp2$group + max(mp2$group) + 1
mp <- rbind(mp1, mp2)
ggplot(aes(x = long, y = lat, group = group), data = mp) + 
  geom_path()  + 
  scale_x_continuous(limits = c(110, 300)) + 
  scale_y_continuous(limits = c(-50, 70)) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM