mathguy86
mathguy86

Reputation: 21

Interactive zoom maps on R

So I am doing a project where I am looking to create a US map with counties. I currently have a map successfully created but am looking to refine it. I am interested in generating a map in which it will show the US with states and if I clicked on a state it would zoom in and show the state with counties listed. Then I want to be able to click on the county to get corresponding information that is in a data set in R. Is this possible to do in R and if so any help would be greatly appreciated.

This is the code I am currently using:

library(devtools)
find_rtools()
devtools::install_github("hafen/housingData")
library(housingData);library(devtools)

head(geoCounty)
geo <- divide(geoCounty, by = c("state", "county"))
geo[[1]]

install.packages(maps)
install.packages(maptools)
library(maps)
library(maptools)

US <- map("state",fill=TRUE, plot=FALSE)
US.names <- US$names
US.IDs <- sapply(strsplit(US.names,":"),function(x) x[1])
US_poly_sp <- map2SpatialPolygons(US,IDs=US.IDs,proj4string=CRS("+proj=longlat 
+ datum=wgs84"))
plot(US_poly_sp,col="white",axes=TRUE)
points(geoCounty$lon, geoCounty$lat)

Thanks, Joey

Upvotes: 2

Views: 1109

Answers (1)

TimSalabim
TimSalabim

Reputation: 5834

Joey, how about this?

library(mapview)
library(raster)

counties <- getData("GADM", country = "USA", level = 2)

mapview(counties)

Best Tim

Upvotes: 2

Related Questions