2

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.

no asia and australia

I would like to do something along the lines of this:

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

to get a map like this:

world map

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

convention

CephBirk
  • 6,422
  • 5
  • 56
  • 74

2 Answers2

1

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

enter image description here

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • 1
    Thanks for your suggestion. I updated my question specifying a need for the correct longitude values. – CephBirk Dec 11 '15 at 23:40
1

I've tried to zoom it a bit to match more closely what you posted (code below). Thanks to this answer by kohske

ggplot2 map pacific

# 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)) 
Community
  • 1
  • 1
Eric Fail
  • 8,191
  • 8
  • 72
  • 128
  • 1
    Thanks for your suggestion. I updated my question specifying a need for the correct longitude values. – CephBirk Dec 11 '15 at 23:40