R Create a Spatial Bubble Plot That Overlays A basemap of the US and other spatial layers as needed -


i'm trying produce nice bubble plot overlaid on top of basemap of (i import shapefile if preferred i've been using r basemaps.

library(ggplot2,sp,raster,maps,mapdata,maptools,ggmap,rgeos) mydata = data.frame(name=c("florida","colorado","california","harvard","yellowstone"),                 lat=c(28.1,39,37,42,44.6),                  long=c(-81.6,-105.5,-120,-71,-110),                 pop=c(280,156,128,118,202)) 

using code below, adapted stack overflow post (create bubble plot in r using satellite map), able overlay bubble plot on map of us. renders slowly, extent tight, bounded in box, i'm not able add other layers plot can tell, , base map thick , not visually clean.

xy <- mydata[,c("long", "lat")] nl <- getdata('gadm', country="usa", level=1) #raster data, format spatialpolygonsdataframe nl <- gsimplify(nl, tol=0.01, topologypreserve=true) # coercing polygon outlines spatiallines object spl <- list("sp.lines", as(nl, "spatiallines")) spdf <- spatialpointsdataframe(coords=xy, data=mydata) coordinates(mydata) <- c("lat", "long") projection(spdf)<- "+proj=longlat +ellps=wgs84 +datum=wgs84 +no_defs +towgs84=0,0,0" coordinates(spdf)[1:5,] #retrieves spatial coordinates form dataframe bubble(spdf, "pop", sp.layout=spl, main="this it!") 

i can draw nice basemap using code. add points map not sized pop column in data. , can add additional layers map. can control size of points , symbol can using bubble plot?

map(database= "world", ylim=c(45,90),      xlim=c(-160,-50), col="grey80",      fill=true, projection="gilbert",      orientation= c(90,0,225))  coord <- mapproject(mydata$lon, mydata$lat, proj="gilbert",orientation=c(90, 0, 225)) points(coord, pch=20, cex=1.2, col="red")  

can please guide me towards best way plot bubble map in r can adjust fill , outline of symbols in bubble map, , can add clean basemap, can a) control colors of (fill , lines) , b) add additional layers (for instance shapefile layer).

thank in advance advice.

this may helpful. approached question using own way. may simpler operation achieve trying do. maps, gadm great. but, packages got maps. here, can states map in following way. then, can draw map using ggplot2. geom_path draws us, , geom_point adds data points in mydata.if want control size of bubbles in ggplot2,you can use size in aes.

library(map) library(ggplot2)  # map usa <- map_data("state")  # draw map , add data points in mydata  ggplot() + geom_path(data = usa, aes(x = long, y = lat, group = group)) + geom_point(data = mydata, aes(x = long, y = lat, size = pop), color = "red")  

enter image description here


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -