1

I'm trying to plot a EIA shapefile onto Google Map. I have a code working with the map function but can't get it to work with the ggmap function. Where am I going wrong?

Working code:

library(maps)
map("state")
shapLocation<- "C:/shapfile/shalegasbasin/"
pcontorta <- readShapePoly(paste(shapLocation,"US_ShaleBasins_EIA_May2011.shp",sep=""))
plot(pcontorta, add=TRUE,  col=adjustcolor("black", alpha.f = 0.6),  border=FALSE) 

shapefile from: http://www.eia.gov/maps/layer_info-m.cfm

Changed code to:

map <-get_map(location = "united states",zoom = 4,  filename=outFiles)
ggmap(map)

WGS84 <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs +towgs84=0,0,0")
shapLocation<- "C:/Users/jecrosbie/Documents/Oil Weekly/shapfile/shalegasbasin"
data.shape<-readOGR(shapLocation,, layer= "US_ShaleBasins_EIA_May2011")
data.shape<- spTransform(data.shape, CRS("+proj=longlat +datum=WGS84"))
data.shape<-fortify(data.shape)

map <- map + geom_polygon(aes(x=long, y=lat, group=group), fill='grey',     size=.2,color='green', data=data.shape, alpha=0)
map 

output error: ............. [68,] "#A7C8FD" "#A7C8FD" "#A2C4FC" "#A2C4FC" "#A2C4FC" "#A2C4FC" "#8CA488" [69,] "#A7C8FD" "#A7C8FD" "#A2C4FC" "#A2C4FC" "#A2C4FC" "#A2C4FC" "#8CA488" .............

1 Answer 1

1

Change

geom_polygon(aes(x=long, y=lat, group=group), fill='grey',     size=.2,color='green', data=data.shape, alpha=0)

to

geom_polygon(aes(long, lat, group=group, fill='grey',     size=.2,color='green', data=data.shape, alpha=0))


m = map + geom_polygon(data=data.shape, aes(long,lat,group=group,fill="grey", size=2, color='green',alpha=0)) 
m

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.