简体   繁体   中英

Plot Pacific Ocean and continents with ggplot2::borders()

I would like to use ggplot::borders() showing the Pacific Ocean. 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() .

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). How can I plot this in R preferably 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

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)) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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