Difference between revisions of "Importing Google Maps to Plot Data- Kait Farrell"

From Gleon Fellowship
Jump to: navigation, search
(Set PropertyValue: Type = low)
Line 1: Line 1:
 
[[Category:Task]]
 
[[Category:Task]]
 +
== Skills Sharing: Importing Google Maps directly into R to visualize data ==
 +
 +
===Why use this skill?===
 +
* Visually show differences between sampling locations based on some other parameter of interest
 +
* Directly import maps from Google Maps or OpenStreet Map- ArcGIS not required (does require internet connection)
 +
* Minimal coding needed to execute
 +
 +
===R Package involed:===
 +
* ggmap (ggplot2)
 +
 +
===Challenges:===
 +
* Adjusting map parameters to show focal area most effectively: zoom ranges from 3 (continent) to 21 (building), default value 10 (city)
 +
* Obtaining code to fine-tune plot outputs (similar to ggplot)
 +
 +
===Example code:===
 +
<nowiki># Load relevant packages</nowiki><br />
 +
<code>library(ggplot2)<br />
 +
library(ggmap)</code>
 +
 +
<nowiki># Import dataset to superimpose over map</nowiki><br />
 +
<code>data <- read.csv("C:\\Users\\FarrellKJ\\Documents\\R\\mean_depth.csv", header = TRUE)</code>
 +
 +
<nowiki># Pull map from Google (e.g., location = c('Sunappe, NH') or specified lat/long (as below)</nowiki><br />
 +
<code>map <- get_map(location = c(lon = -83.44, lat = 35.05), zoom = 14, maptype = c('hybrid'))</code>
 +
 +
<nowiki># Plot map- 2013 Q</nowiki><br />
 +
<code>ggmap(map)<br /> + geom_point(aes(x = lat, y = long, colour=Q, size=Q), data = data)<br /> + scale_colour_continuous(name='Discharge (L/s)',limits=c(0,1000), low = "yellow", high = "red", space = "Lab", guide = "colorbar")<br /> + scale_size(guide='none', range= c(2,12), limits=c(0,1000), breaks=c(5, 50, 100, 400, 800))</code>
 +
 
<!-- Add any wiki Text above this Line -->
 
<!-- Add any wiki Text above this Line -->
 
<!-- Do NOT Edit below this Line -->
 
<!-- Do NOT Edit below this Line -->

Revision as of 09:04, 20 January 2015

Skills Sharing: Importing Google Maps directly into R to visualize data

Why use this skill?

  • Visually show differences between sampling locations based on some other parameter of interest
  • Directly import maps from Google Maps or OpenStreet Map- ArcGIS not required (does require internet connection)
  • Minimal coding needed to execute

R Package involed:

  • ggmap (ggplot2)

Challenges:

  • Adjusting map parameters to show focal area most effectively: zoom ranges from 3 (continent) to 21 (building), default value 10 (city)
  • Obtaining code to fine-tune plot outputs (similar to ggplot)

Example code:

# Load relevant packages
library(ggplot2)
library(ggmap)

# Import dataset to superimpose over map
data <- read.csv("C:\\Users\\FarrellKJ\\Documents\\R\\mean_depth.csv", header = TRUE)

# Pull map from Google (e.g., location = c('Sunappe, NH') or specified lat/long (as below)
map <- get_map(location = c(lon = -83.44, lat = 35.05), zoom = 14, maptype = c('hybrid'))

# Plot map- 2013 Q
ggmap(map)
+ geom_point(aes(x = lat, y = long, colour=Q, size=Q), data = data)
+ scale_colour_continuous(name='Discharge (L/s)',limits=c(0,1000), low = "yellow", high = "red", space = "Lab", guide = "colorbar")
+ scale_size(guide='none', range= c(2,12), limits=c(0,1000), breaks=c(5, 50, 100, 400, 800))


Yandex.Metrica