Map draw +190 longitude

49 views
Skip to first unread message

Matthias Petri

unread,
Jul 28, 2016, 6:56:40 AM7/28/16
to ggplot2
Hello,

I was wondering why this "standard" way of drawing a world map shows data beyond +180 degrees longitude (top right corner):

library(maps)
library(ggplot2)
world <- map_data("world")
worldmap <- ggplot(world, aes(long, lat)) 
worldmap <- worldmap + geom_polygon(fill = "#ffeda0", colour = "black",aes(group = group)) 
worldmap <- worldmap + scale_x_continuous(name="Longitude",expand=c(0,0),breaks=seq(-180,190,10))  
worldmap <- worldmap + scale_y_continuous(name="Latitude",expand=c(0,0),breaks=seq(-90,90,10)) 
worldmap <- worldmap + theme_bw() + theme(panel.background = element_rect(fill="#A3CCFF"))
print(worldmap)

Is this a "feature" of the standard projection?

Thanks,
Matthias

Bob Rudis

unread,
Aug 2, 2016, 10:35:00 AM8/2/16
to ggplot2
It's really an artifact of the legacy maps in R. 

If you take a look at packages like `rworldmap` by Andy South and `rnaturalearth` (https://github.com/ropenscilabs/rnaturalearth & also by Andy + rOpenSci) you'll see that the bounding box for the shapefiles is:

##    min       max
## x -180 180.00000
## y  -90  83.64513

Unlike:

range(world$long)
## [1] -180.0000  190.2708

which really comes from:

maps::map("world", plot=FALSE)$range
## [1] -180.00000  190.27084  -85.19218   83.59961

in the built-in `maps` package.

Despite the new maps pkg having undergone an overhaul and being based on natural earth boundaries this wonky base 'projection'.

IMO if you're doing anything other than choropleths, you should use one of the separate maps shapefile packages.

Matthias Petri

unread,
Aug 2, 2016, 11:16:12 PM8/2/16
to ggplot2
Thanks Bob, this explains the problem very well. 

It's a bit unfortunate that the "maps" package is used throughout the ggplot docs instead of a more appropriate package.

Bob Rudis

unread,
Aug 3, 2016, 9:59:51 AM8/3/16
to Matthias Petri, ggplot2
Aye, but ggplot2 already has a significant # of Imports, Depends &
Suggests so adding one more pkg to Suggests (for the examples, which
do get run on CRAN) is somewhat burdensome for both pkg authors and
users. BUT, I can PR some \dontrun{} examples to geom_map(),
coord_map() (et al) that help illustrate this and also try to update
the mapping-oriented function docs to talk about this.
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
> https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "ggplot2" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/ggplot2/RcRWCEuiOno/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> ggplot2+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Matthias Petri

unread,
Aug 4, 2016, 10:17:57 PM8/4/16
to ggplot2, matthia...@gmail.com


On Wednesday, 3 August 2016 23:59:51 UTC+10, Bob Rudis wrote:
Aye, but ggplot2 already has a significant # of Imports, Depends &
Suggests so adding one more pkg to Suggests (for the examples, which
do get run on CRAN) is somewhat burdensome for both pkg authors and
users. BUT, I can PR some \dontrun{} examples to geom_map(),
coord_map() (et al) that help illustrate this and also try to update
the mapping-oriented function docs to talk about this.

For me personally I used the geom_map() docs as a starting point to do mapping related visualizations in R so it would be beneficial if it doesn't use "weird/outdated" polygons in the examples.
Reply all
Reply to author
Forward
0 new messages