naught101
naught101

Reputation: 19563

Fix antarctica on a ggplot world map?

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:

Map without bottom part of antarctica

But the sounthern most part of antarctica is missing - it should look like this:

enter image description here

Is there a simple way to fix this problem?

Upvotes: 2

Views: 3997

Answers (2)

madlogos
madlogos

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

enter image description here

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

eipi10
eipi10

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

enter image description here

Upvotes: 2

Related Questions