Pregunta

I'm afraid I'm having some trouble doing what should be relatively easy. I'm trying to effectively duplicate the ggplot map from this question World Map - Plotting Circles, size of circle relevant to No of using output from the Google geocode API. I passed it a bunch of questionably-formatted, free-text location data (i.e. what it's good at), and got the following table.

> summary(userlocations)
       ID              lon                lat             lonmin        
 Min.   :   1.0   Min.   :-169.867   Min.   :-82.86   Min.   :-180.000  
 1st Qu.: 618.8   1st Qu.: -91.815   1st Qu.: 33.72   1st Qu.: -91.956  
 Median :1200.0   Median : -77.201   Median : 40.06   Median : -78.110  
 Mean   :1220.5   Mean   : -49.884   Mean   : 35.40   Mean   : -51.709  
 3rd Qu.:1804.2   3rd Qu.:  -2.248   3rd Qu.: 45.52   3rd Qu.:  -2.798  
 Max.   :2500.0   Max.   : 174.886   Max.   : 71.29   Max.   : 174.771  
                  NA's   :643        NA's   :643      NA's   :643       
     lonmax             latmin           latmax            location   
 Min.   :-169.774   Min.   :-90.00   Min.   :-61.00   London   :  65  
 1st Qu.: -89.013   1st Qu.: 33.07   1st Qu.: 33.95   Canada   :  31  
 Median : -75.891   Median : 39.74   Median : 40.59   Atlanta  :  25  
 Mean   : -47.521   Mean   : 34.01   Mean   : 36.86   England  :  22  
 3rd Qu.:  -1.521   3rd Qu.: 44.37   3rd Qu.: 47.08   New York :  22  
 Max.   : 180.000   Max.   : 71.23   Max.   : 85.41   Las Vegas:  21  
 NA's   :643        NA's   :643      NA's   :643      (Other)  :3286

while I know enough to just do something like:

map(database="worldHires")
points(userlocations$lon, userlocations$lat, pch=20)

that produces a fairly small, ugly map. in order to reproduce the ggplot example, I need to (at minimum) get a counter of duplicate lat/lon entires, so I know when there are e.g. 65 people in London, but it seems that I can't just use userlocations$location, because this field just contains the non-normalized free text that I passed to Google in the first place; only lon and lat appear to have useful data.

I apologize for the simplicity of this question, but if someone could help, I'd really appreciate it.

¿Fue útil?

Solución

if you can format the code neatly into two vectors x (longitude) and y (latitute), then you could use:

require(ggplot2)
ggplot(data.frame(x = x, y = y, circle_size = '\\add a vector'), aes(x, y, size = circle_size) + geom_point()

I didn't test the above function, but it should produce a very similar plot to the example you provided.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top