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
So, I followed the instructions here, more or less, to create this world map:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With