Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping the world on ggplot2

I've been trying to plot a map of the world on ggplot2. I followed the threads of emails: ggplot map with l but I do run into the same error message and I don't understand the author comments on how to fix it.

library(rgdal)
library(ggplot2)
library(maptools)
library(sp)
gpclibPermit()

world.map <- readOGR(dsn="data", layer="TM_WORLD_BORDERS_SIMPL-0.3")
world.ggmap <- fortify(world.map, region = "NAME")

> world.ggmap <- fortify(world.map, region = "NAME")
Error in nchar(ID) : invalid multibyte string 1
like image 426
GodinA Avatar asked Mar 21 '12 13:03

GodinA


1 Answers

So, I followed the instructions here, more or less, to create this world map:

ggplot2 world

library(ggplot2)
library(cshapes)
world <- cshp(date=as.Date("2008-1-1"))
world.points <- fortify(world, region='COWCODE')
p <- ggplot(world.points, aes(long,lat,group=group)) + geom_polygon()
p

It looks like it takes some more work to combine this with data, e.g. for a thematic map, but the post above goes through this in detail.

Not sure if you still need an answer to this, but I hope it's helpful to someone in any case.

like image 189
andybega Avatar answered Sep 29 '22 22:09

andybega