Reputation: 6710
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()
?
Upvotes: 3
Views: 4646
Reputation: 7928
I've tried to zoom it a bit to match more closely what you posted (code below). Thanks to this answer by kohske
# 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))
Upvotes: 1
Reputation: 78792
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
Upvotes: 1