Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
## Get data from OpenPV. Open this URL:
## and export the results as a CSV file named "californiaOpenPV.csv"
caPV <- read.csv('californiaOpenPV.csv')
## Longitude and Latitude are the names of columns where the spatial information is stored.
## With the coordinates<- method caPV is now an SpatialPointsDataFrame
coordinates(caPV) <- ~ Longitude + Latitude
proj4string(caPV) <- CRS("+proj=longlat +datum=WGS84")
names(caPV)[3] <- 'Pdc.kW'
## Download stamen tiles using the bounding box of the SpatialPointsDataFrame object
bbPoints <- bbox(caPV)
gmap <- get_map(c(bbPoints), maptype='watercolor', source='stamen', crop=FALSE)
## Bounding box of the map to resize and position the image with grid.raster
bbMap <- attr(gmap, 'bb')
latCenter <- with(bbMap, +
lonCenter <- with(bbMap, ll.lon + ur.lon)/2
height <- with(bbMap, -
width <- with(bbMap, ur.lon - ll.lon)
## Use sp.layout of spplot: a list with the name of the function
## ('grid.raster') and its arguments
sp.raster <- list('grid.raster', gmap,
x=lonCenter, y=latCenter,
width=width, height=height,
## Define classes and sizes of the circle for each class
breaks <- c(100, 200, 500, 1e3, 25e3)
classes <- cut(caPV$Pdc.kW, breaks)
meds <- tapply(caPV$Pdc.kW, classes, FUN=median)
sizes <- (meds/max(meds))^0.57 * 1.8
## Finally, the spplot function
cuts = breaks,
col.regions=brewer.pal(n=5, 'Greens'),
edge.col='black', alpha=0.7,

This comment has been minimized.

Copy link
Owner Author

@oscarperpinan oscarperpinan commented Apr 2, 2014

Watercolor stamen maps are now in jpeg format. Version 2.4 of ggmap fixes this: dkahle/ggmap@d657e1c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment