在ggplot2上映射世界 [英] Mapping the world on ggplot2

查看:184
本文介绍了在ggplot2上映射世界的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在ggplot2上绘制一幅世界的地图。我遵循电子邮件的线索: ggplot map with l ,但我遇到同样的错误信息我不明白作者对如何解决这个问题的评论。

 库(rgdal)
库(ggplot2)
库(maptools)
库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)
nchar(ID)中的错误:无效的多字节字符串1


解决方案

所以,我按照说明这里,或多或少,创建这个世界地图:



  library(ggplot2)
库(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

它似乎需要一些更多的工作来与数据结合,例如对于专题地图,但上面的帖子详细介绍了这一点。



不知道如果你仍然需要一个答案,但我希望对任何人有帮助案例。


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.

这篇关于在ggplot2上映射世界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆