Changes

Jump to navigation Jump to search
921 bytes added ,  13:34, 21 September 2020
no edit summary
== Quick Guide =={{Project *Make sure you have downloaded the RgoogleMaps package. ** code: library(Rgooglemaps)* Create a base map **find geocode for center of desired map, adjust zoom as needed**example code (for map of North America): newmap <- GetMap(center = c(39, -95), zoom = 3, destfile |Has project output= "NorthAmerica.png")*Transform addresses into geocode via http://www.geocodezip.com/v3_example_geo2.asp?addr1=United%20States%20of%20America&geocode|Has sponsor=1*Plot map, adjust variablesMcNair Center** example code: PlotOnStaticMap(newmap, lat |Has title= c(30.268606, 41.888519), lon = c(-97.740467, -87.63548), pch = 20, col = "red")Mapping on R**lat=latitude; lon=longitude, pch = point style, color|Has owner="color" Example Code:Chicago MSA w/ color by Industry library(RgoogleMaps)library(ggplot2)library(colorspace)library(RColorBrewer) merged.data<- merge(Chicago.Adresses.for.geocode.v2Albert Nabiullin, Chicago.Addresses.w.Industries, by="Name") newmap <- GetMap(center = c(41.92,-87.78), zoom = 11,GRAY = TRUE, destfile |Has keywords= "chicago_test.png")Tool col.list <- c("#EB6D2E","#EB6D2E", "#EB6D2E", "#00B2A9", "#516B66", "#00B2A9")palette(col.list) PlotOnStaticMap(newmap, lat=c(Chicago.Adresses.for.geocode.v2$Latitude),lon=c(Chicago.Adresses.for.geocode.v2$Longitude), pch=20, col|Has project status=c(Chicago.Addresses.w.Industries$Industry))Complete}}== Interactive Maps: ==
===Mapping with Leaflet===
[[Image:leaflet.png|200px|thumb|right|Interactive map on Leaflet]]
[[Image:marker.png|200px|thumb|right|Interactive map with Markers]]
Leaflet is one of the most popular open-source JavaScript libraries for interactive maps.
This R package makes it easy to integrate and control Leaflet maps in R.
Introduction: https://rstudio.github.io/leaflet/<br>Markers: https://rstudio.github.io/leaflet/markers.html<br>Github: https://github.com/rstudio/leaflet<br>
Features
*Use map bounds and mouse events to drive Shiny logic
*Sample Code:
SBDE <- read.csv("SBDE.csv") #Import the CSV file with your data set
library(leaflet) #Use the leaflet library
#data(SBDE)
m <- leaflet(data = SBDE) %>% #Define your map with the data you specified earlier
addTiles() %>% # Add default OpenStreetMap map tiles. Make sure to use the %>% symbol!
addMarkers(~longitude, ~latitude, popup = ~as.character(link)) %>% #Add points on your map
addLegend("bottomright", colors= "#1878cd", labels="Resources", title="Houston Small Biz Guide") #Add a legend
m # Print map
----
===Other R Packages===
Helpful links: http://www.r-bloggers.com/interactive-maps-for-the-web-in-r/<br>
To find HEX codes for RGB colors: http://www.javascripter.net/faq/rgbtohex.htm
map <- plotGoogleMaps(polygons.plot,zoom=2,fitBounds=F,filename="Map_GoogleMaps_small.html",layerName="Economic Data",map="GoogleMap",mapCanvas="Map",map.width="800px",map.height="600px",control.width="200px",control.height="600px")
 
=== Quick Guide to Leaflet Alternatives ===
 
*Make sure you have downloaded the RgoogleMaps package.
** code: library(Rgooglemaps)
* Create a base map
**find geocode for center of desired map, adjust zoom as needed
**example code (for map of North America): newmap <- GetMap(center = c(39, -95), zoom = 3, destfile = "NorthAmerica.png")
*Transform addresses into geocode via http://www.geocodezip.com/v3_example_geo2.asp?addr1=United%20States%20of%20America&geocode=1
*Plot map, adjust variables
** example code: PlotOnStaticMap(newmap, lat = c(30.268606, 41.888519), lon = c(-97.740467, -87.63548), pch = 20, col = "red")
**lat=latitude; lon=longitude, pch = point style, color="color"
 
Example Code:
Chicago MSA w/ color by Industry
 
library(RgoogleMaps)
library(ggplot2)
library(colorspace)
library(RColorBrewer)
 
merged.data<- merge(Chicago.Adresses.for.geocode.v2, Chicago.Addresses.w.Industries, by="Name")
 
newmap <- GetMap(center = c(41.92,-87.78), zoom = 11,GRAY = TRUE, destfile = "chicago_test.png")
 
col.list <- c("#EB6D2E","#EB6D2E", "#EB6D2E", "#00B2A9", "#516B66", "#00B2A9")
palette(col.list)
 
PlotOnStaticMap(newmap, lat=c(Chicago.Adresses.for.geocode.v2$Latitude),lon=c(Chicago.Adresses.for.geocode.v2$Longitude), pch=20, col=c(Chicago.Addresses.w.Industries$Industry))

Navigation menu