Caspian sea disappears on world map plot

111 views
Skip to first unread message

Kristoffer Magnusson

unread,
Sep 8, 2012, 7:32:43 AM9/8/12
to ggp...@googlegroups.com
Hello,

I'm using this shape file from Natural Earth data to plot a world map with ggplot2, but for some reason the caspian sea is missing on the plot. It's there if I use plot(), but not in my ggplot.

Here's my code:

library(maptools)
library(ggplot2)

world.sp <- readShapePoly("50m-land/50m_land", proj4string=CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"))
world.sp <- fortify(world.sp)

ggplot(world.sp, aes(long, lat, group=group)) + geom_polygon()

Anyone know how to solve this problem? 

Best,
Kristoffer

Winston Chang

unread,
Sep 12, 2012, 1:29:08 PM9/12/12
to Kristoffer Magnusson, ggp...@googlegroups.com
This looks like a problem with holes in polygons - the great lakes in North America don't show up either. Could you file an issue about this on github?

Thanks!
-Winston

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

Mark Connolly

unread,
Sep 12, 2012, 5:17:59 PM9/12/12
to ggp...@googlegroups.com
You might take a look at https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles and see if it helps.  Look down at the Problems heading.

Kristoffer Magnusson

unread,
Sep 14, 2012, 3:15:09 AM9/14/12
to ggp...@googlegroups.com
Hi,

I figured out that my problem was caused by how ggplot handles holes in polygons, as Winston mentioned. I wasn't aware that ggplot plots holes as a separate polygon above the land polygon (in this case) and not as a true hole, I can get the caspian sea to show up if I set "fill = hole". However, It's not an ideal solutions as I want all water area to be transparent. 

Thanks!
Kristoffer
Reply all
Reply to author
Forward
0 new messages