我有一个代表旧金山邮政编码区的情节。
# Download San Francisco zip codes polygons
path="http://moshetoronto.free.fr/blog/sfreal/geo_export_f72cfa08-0728-4a0b-bbcc-1fafc25de0f5.shp"
filename="geo_export_f72cfa08-0728-4a0b-bbcc-1fafc25de0f5.shp"
download.file(path,filename, mode = "wb")
pathfile=paste0(getwd(),"/",filename)
# load the file
getwd()
sfn = readOGR(dsn =pathfile ) %>% spTransform(CRS("+proj=longlat +datum=WGS84"))
sfn.f<- sfn %>% fortify
# build the map
mysfn <- ggplot(data = sfn.f, aes(x=long, y=lat, group = id)) +
geom_polygon(fill="white",alpha=1) +
geom_path(color = "black",size=0.05,alpha=0.15)
我得到了假点的数据框:
# build the dataframe
myds=data.frame("long"=sample(seq(-122.35,-122.5,0.01),size = 10,replace=FALSE),
"lat"=sample(seq(37.7,37.80,0.01),size = 10,replace=FALSE))
我只想在地图上映射这些点:
# try to draw a contour plot
mysfn + geom_point( data=myds, aes(x=long,y=lat),colour="red")
但它不起作用,我收到此错误消息:
eval(expr,envir,enclos)中的错误:找不到对象'id'