0

I am trying to use R googleway to analyze crime records from NY Open Data. I want to add precinct polygon and crime circle to NY city map. However, even when I reduce the total crime points to 19k, I still cannot load the created map. Please see the code below.

map_key = "api_key
ggmap = google_map(location = c(mean(40.730610), mean(-73.935242)), zoom = 
11, key = map_key)
ggmap %>% add_polygons(data = nypp_df_gg, lat = "lat", lon = "lon", id = 
"ID", pathId = "pathID") %>% add_circles(lat = "Latitude", lon = 
"Longitude", data = data.frame(NYPD_complaint_bf2006))

It does work if I limit the rows to 500. May I know if there is a way to visualize large observations>1MM? I tried to use add_heatmap but without any luck too.

The code that works is

    ggmap %>% add_polygons(data = nypp_df_gg, lat = "lat", lon = "lon", id = 
"ID", pathId = "pathID") %>% add_circles(lat = "Latitude", lon = 
"Longitude", data = data.frame(NYPD_complaint_bf2006[1:500,]))
L.Yang
  • 553
  • 1
  • 6
  • 12
  • Do you have links to the data you're using? – SymbolixAU Sep 26 '17 at 20:15
  • Crime data -- https://data.cityofnewyork.us/Public-Safety/Historical-New-York-City-Crime-Data/hqhv-9zeg – L.Yang Sep 26 '17 at 20:42
  • Are you sure; there's about 10 row of data in that zip file – SymbolixAU Sep 26 '17 at 21:37
  • It should be https://data.cityofnewyork.us/Public-Safety/NYPD_Complaint_Data_Historic/4ax6-n4rg. That is crime data I used too. But the bigger data is the complaint data. Sorry about the confusion. I look forward for your insight to this googleway package. – L.Yang Sep 27 '17 at 13:57
  • The problem is that browsers will likely have a hard time rendering tens-of-thousands of data points, no matter which mapping library you use. As you've alluded to you'll need a way to reduce the amount of data you want to plot, either by aggregating it in some way, or filtering by a specific region/date/location/other variable. – SymbolixAU Sep 27 '17 at 21:46
  • Okay thanks. If I only do a static map with those points, do you have any suggestions as of which package can be used? – L.Yang Sep 28 '17 at 20:36
  • 1
    `ggmap` provides a static google map – SymbolixAU Oct 02 '17 at 21:56

1 Answers1

1

I can plot 22k circles using add_circles() if you play around with the load interval.

add_circles(lat = "Y", lon = "X", info_window = "SPECIES", update_map_view = FALSE,
 focus_layer = FALSE, load_interval = 25, radius = 5, ...)

I sorted my data so it would start filling in the center of the map using a distance calculation to where I defined the center lat, lon.

Buddy
  • 10,874
  • 5
  • 41
  • 58
  • Good use of `load_interval`. Note that since this question was asked I have since developed the [mapdeck](https://symbolixau.github.io/mapdeck/articles/layers.html) library, which can easily handle millions of points – SymbolixAU Feb 10 '19 at 21:30