ggmap: Spatial Visualization with ggplot2

ggplot2パッケージによる空間情報の視覚化

> library(ggmap)
Warning: replacing previous import by 'grid::arrow' when loading 'ggmap'
Warning: replacing previous import by 'grid::unit' when loading 'ggmap'
Warning: replacing previous import by 'scales::alpha' when loading 'ggmap'
Google Maps API Terms of Service: http://developers.google.com/maps/terms.
Please cite ggmap if you use it: see citation('ggmap') for details.

Attaching package: 'ggmap'

The following object is masked from 'package:magrittr':

    inset
> data("crime")

バージョン: 2.5.2


関数名 概略
LonLat2XY Convert a lon/lat coordinate to a tile coordinate
OSM_scale_lookup Look up OpenStreetMap scale for a given zoom level.
XY2LonLat Convert a tile coordinate to a lon/lat coordinate
bb2bbox Convert a bb specification to a bbox specification
calc_zoom Calculate a zoom given a bounding box
crime Crime data
distQueryCheck Check Google Maps Distance Matrix API query limit
geocode Geocode
geom_leg Single line segments with rounded ends
get_cloudmademap Get a CloudMade map.
get_googlemap Get a Google Map.
get_map Grab a map.
get_navermap Get a Naver Map
get_openstreetmap Get an OpenStreetMap
get_stamenmap Get a Stamen Map
ggimage Plot an image using ggplot2
gglocator Locator for ggplots.
ggmap Plot a ggmap object
ggmapplot Don't use this function, use ggmap.
hadley Highly unofficial ggplot2 image
inset Add ggplot2 insets to a map
inset_raster Add a raster annotation to a map
legs2route Convert a leg-structured route to a route-structured route
make_bbox Compute a bounding box
mapdist Compute map distances using Google
mutate_geocode Geocode a dataset
print.ggmap Print a map
qmap Quick map plot
qmplot Quick map plot
revgeocode Reverse geocode
route Grab a route from Google
routeQueryCheck Check Google Maps Directions API query limit
theme_inset Make a ggplot2 inset theme.
theme_nothing Make a blank ggplot2 theme.
wind Wind data from Hurricane Ike
zips Zip code data for the Greater Houston Metropolitan Area from the 2000 census

crime

犯罪データ http://www.houstontx.gov/police/cs/stats2.htm

> data("crime")
> crime %>% {
+   print(class(.))
+   dplyr::glimpse(.)
+ }
[1] "data.frame"
Observations: 86,314
Variables: 17
$ time     (time) 2010-01-01 15:00:00, 2010-01-01 15:00:00, 2010-01-01...
$ date     (chr) "1/1/2010", "1/1/2010", "1/1/2010", "1/1/2010", "1/1/...
$ hour     (int) 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,...
$ premise  (chr) "18A", "13R", "20R", "20R", "20A", "20R", "20A", "20R...
$ offense  (fctr) murder, robbery, aggravated assault, aggravated assa...
$ beat     (chr) "15E30", "13D10", "16E20", "2A30", "14D20", "18F60", ...
$ block    (chr) "9600-9699", "4700-4799", "5000-5099", "1000-1099", "...
$ street   (chr) "marlive", "telephone", "wickview", "ashland", "canyo...
$ type     (chr) "ln", "rd", "ln", "st", "", "ln", "blvd", "cir", "ln"...
$ suffix   (chr) "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-"...
$ number   (int) 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,...
$ month    (fctr) january, january, january, january, january, january...
$ day      (fctr) friday, friday, friday, friday, friday, friday, frid...
$ location (chr) "apartment parking lot", "road / street / sidewalk", ...
$ address  (chr) "9650 marlive ln", "4750 telephone rd", "5050 wickvie...
$ lon      (dbl) -95.43739, -95.29888, -95.45586, -95.40334, -95.37791...
$ lat      (dbl) 29.67790, 29.69171, 29.59922, 29.79024, 29.67063, 29....

geocode

都市名から座標を返す

Arguments

  • location
  • output
  • source... "dsk" for Data Science Toolkit or "google" for Google
  • messaging
  • sensor
  • override_limit
  • client
  • signature
  • nameType
  • data
  • userType
> geocode(c("Tokyo, Japan", "Yokohama, Japan"),
+         source = "google")
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Tokyo,%20Japan&sensor=false
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Yokohama,%20Japan&sensor=false
      lon      lat
1 139.732 35.70903
2 139.638 35.44371

mutate_geocode

> data.frame(address = c("Tokyo, Japan", "Okayama, Japan", "Yokohama, Japan"),
+            stringsAsFactors = FALSE) %>% 
+   mutate_geocode(address)
Information from URL : http://www.datasciencetoolkit.org/maps/api/geocode/json?address=Tokyo,%20Japan&sensor=false
Information from URL : http://www.datasciencetoolkit.org/maps/api/geocode/json?address=Okayama,%20Japan&sensor=false
Information from URL : http://www.datasciencetoolkit.org/maps/api/geocode/json?address=Yokohama,%20Japan&sensor=false
          address      lon      lat
1    Tokyo, Japan 139.6917 35.68950
2  Okayama, Japan 133.9350 34.66167
3 Yokohama, Japan 139.6425 35.44778