Created
November 25, 2013 15:45
-
-
Save corynissen/7643380 to your computer and use it in GitHub Desktop.
Create a map from OpenStreetMaps package in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| library(ggplot2) | |
| library(OpenStreetMap) | |
| merc <- projectMercator(df2$lat, df2$lng) #OSM uses mercator | |
| # give openmap the upper right and lower left corners you want for your map | |
| mp <- openmap(c(42.05, -87.96), c(41.62, -87.5), type="osm", minNumTiles=16) | |
| p <- autoplot(mp) + geom_point(aes(x=merc[,1], y=merc[,2]), alpha=.7, size=10) + | |
| theme(line = element_blank(), | |
| text = element_blank(), | |
| line = element_blank(), | |
| title = element_blank(), | |
| plot.margin=unit(c(0,0,0,0), "cm")) | |
| gt <- ggplot_gtable(ggplot_build(p)) | |
| ge <- subset(gt$layout, name == "panel") | |
| png("foodborne_p1.png", width=1433, height=1800) | |
| grid.draw(gt[ge$t:ge$b, ge$l:ge$r]) | |
| dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment