问题
I have geocoded data points (.csv) and a shapefile (Tigerline) read into R and maps overlaying the points (locations) on the polygons (counties) all under the same projection using plot() and add=.
I am trying to find a way to map the number of points found in each polygon (county). I assume this would be a choropleth or some sort of thematic map. However associating the shapefile and the points is throwing me for a loop.
And if you can't tell, I am both an R and spatial analysis newbie
I have gotten this far:
count1<-table(epoints.spdf$county.NAME)
count1
count2<-as.data.frame(count1)
count2
county$COUNT<-count2
merge(count2$Freq, county$COUNT, by = c('Var1', 'county.NAME'))
Error in fix.by(by.x, x) : 'by' must specify uniquely valid columns
Var1 Freq
1 Amelia 7
2 Caroline 33
3 Charles City 1
4 Chesterfield 209
5 Colonial Heights 26
6 Dinwiddie 23
7 Goochland 15
8 Hanover 84
9 Henrico 241
10 Hopewell 24
11 King William 12
12 New Kent 23
13 Petersburg 38
14 Powhatan 20
15 Prince George 18
16 Richmond 194
17 Sussex 16
SOLVED:
count1<-table(epoints.spdf$county.NAME)
count1
count2<-as.data.frame(count1)
count2
merge(count2, county@data, by.x = 'Var1', by.y= 'NAME')
names(county)
data.frame(county)
来源:https://stackoverflow.com/questions/35259721/choropleth-or-thematic-map-creation-from-number-of-points-within-shapefile-polyg