Reputation: 19563
I want to plot a simple world map with gpplot, but when I do, antarctica gets cut off, because the coordinates don't wrap around, so the path goes back across the whole map, instead of going out the edges. For example:
world_data <- map_data("world")
ggplot() + scale_y_continuous(limits=c(-90,90), expand=c(0,0)) +
scale_x_continuous(expand=c(0,0)) +
theme(axis.ticks=element_blank(), axis.title=element_blank(),
axis.text=element_blank()) +
geom_polygon(data=world_data, mapping=aes(x=long, y=lat, group=group), fill='grey')
Produces:
But the sounthern most part of antarctica is missing - it should look like this:
Is there a simple way to fix this problem?
Upvotes: 2
Views: 3997
Reputation: 71
Hi @eipi10: your code does not work well when setting coord_map()
. Antarctica looks weird.
ggplot() +
geom_polygon(data=fortify(wrld_simpl),
aes(x=long, y=lat, group=group), fill='grey20') +
coord_map(xlim=c(-180, 180), ylim=c(-90, 90)) +
scale_x_continuous(breaks=seq(-180, 180, 20)) +
scale_y_continuous(breaks=seq(-90, 90, 10))
Actually I found that most built-in world maps in R packages such as mapdata
, maptools
and maps
don't work correctly with coord_map()
. Highly appreciate it if someone can figure it out.
Upvotes: 0
Reputation: 93881
The wrld_simpl
data file from the maptools
package seems to have more reliable map data, including data for Antarctica that goes all the way to -90 degrees latitude. For example:
library(maptools)
data(wrld_simpl)
ggplot() +
geom_polygon(data=wrld_simpl,
aes(x=long, y=lat, group=group), fill='grey20') +
coord_cartesian(xlim=c(-180,180), ylim=c(-90,90)) +
scale_x_continuous(breaks=seq(-180,180,20)) +
scale_y_continuous(breaks=seq(-90,90,10))
Upvotes: 2