通过使用城市和州来绘制ggmap [英] Plot on ggmap by using city and state

查看:115
本文介绍了通过使用城市和州来绘制ggmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张美国地图,准备出发:

mygggmap< - get_map(location =United States,zoom = 4)
g < - ggmap(myggmap)



下一步是绘制一些主要城市。



我知道我可以创建一个图层来绘制我的主要城市的经度和纬度,如下所示:

g < - g + geom_density2d(data = citydata,aes(x = lon,y = lat))

但我想知道是否有办法按实际名称,城市和州来绘图?由于ggmap是通过Google Map API分层的,这应该是可能的,是正确的吗?

解决方案

我找到了答案。很简单。使用地理编码功能:

geocode(SEATTLE)



返回

  lon lat 
-122.3321 47.60621

感谢大家的支持。尽管我刚收到'风滚草'徽章。


I have a map of the USA, ready to go:

mygggmap <- get_map(location = "United States", zoom = 4) g <- ggmap(myggmap)

The next step is to plot some major cities.

I understand I can create a layer to plot my major cities by their longitude and latitude, something like:
g <- g + geom_density2d(data = citydata, aes(x = lon, y = lat))

but I am wondering if there is a way to plot by the actual name, city and state? Since ggmap is layered over the Google Map API, this should be possible, correct?

解决方案

I found the answer. It is simple. Use the geocode function:

geocode("SEATTLE")

returns

        lon        lat
     -122.3321   47.60621

Thanks for the support everyone. Even though I just got a 'tumbleweed' badge.

这篇关于通过使用城市和州来绘制ggmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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