1
votes

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?

2

2 Answers

6
votes

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.

1
votes

If you want to explore further, you could also supplement your original data with data from the zipcode package. It has zip codes for about 43K US cities. For more information, you can check out the link http://www.r-bloggers.com/my-first-r-package-zipcode