我有一个基于全球恐怖主义数据库的数据框架,叫做R.
我已经下载/需要地图包了
我想要做的是从我的gtd
数据框架中获取数据,并在美国地图上添加点。
我知道美国地图的代码是map("state")
在我的gtd
数据框架中,有一列表示纬度和经度。
我所要做的就是在美国地图上标出点,以显示美国发生恐怖袭击的地点
因此,从我的gtd数据库中只能得到一个需要美国经度/纬度的子集,我知道我会使用
subset(x=gtd, country_txt=="United States")
但是,从那里,我如何把攻击的地点绘制成美国地图上的点呢?
非常感谢!
发布于 2014-03-24 01:39:27
我将从你的帖子中的线索中做一个宽泛的假设,你使用的是来自全球恐怖主义数据库的数据。如果你从它中读到了巨大的CSV,你想要做的应该是有效的,而且你已经接近得到答案了。基本上,您只需要将points()
添加到map()
library(maps)
# assuming you have it in a CSV file
dat <- read.csv("gtd.csv")
# subset only points in the US
US <- dat[dat$country_txt == "United States",]
# plot the base US map
map('state')
# add points with really horrid default color, point type & size
# changing this is a good exercise for the poster :-)
points(x=US$longitude, y=US$latitude, col="red", cex=0.75)
不过,这与ggplot2
无关,因此请考虑删除该标记。它可以用ggplot
来完成,但是maps()
不使用它。
https://stackoverflow.com/questions/22599525
复制相似问题