R语言中的ggmap包

本文介绍了R语言中ggmap包的使用,包括get_map()、ggmap()和qmap()三个主要函数。get_map()用于获取地图,参数如location、zoom、maptype等可定制地图样式;ggmap()则用于在ggplot2环境中绘制地图;qmap()是前两者功能的结合。通过实例展示了如何获取并绘制北京地区的地图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

介绍

R语言中的ggmap包可以实现地图背景的绘制,里面的主要函数有get_map(),ggmap()以及ggmap()等。它们返回的是一个ggplot2对象,随后可以在此基础上绘制其他ggplot元素。

get_map()

get_map(location = c(lon = -95.3632715, lat = 29.7632836),
  zoom = "auto", scale = "auto", maptype = c("terrain",
  "terrain-background", "satellite", "roadmap", "hybrid", "toner",
  "watercolor", "terrain-labels", "terrain-lines", "toner-2010",
  "toner-2011", "toner-background", "toner-hybrid", "toner-labels",
  "toner-lines", "toner-lite"), source = c("google", "osm", "stamen"),
  force = ifelse(source == "google", TRUE, FALSE), messaging = FALSE,
  urlonly = FALSE, filename = NULL, crop = TRUE, color = c("color",
  "bw"), language = "en-EN", ...)

参数介绍

  • location
    an address, longitude/latitude pair (in that order), or left/bottom/right/top bounding box,经常使用box来取地图,这样也不需要API key.

  • zoom
    map zoom, an integer from 3 (continent) to 21 (building), default value 10 (city). openstreetmaps limits a zoom of 18, and the limit on stamen maps depends on the maptype. “auto” automatically determines the zoom for bounding box specifications, and is defaulted to 10 with center/zoom specifications. maps of the whole world currently not supported.

  • scale
    scale argument of get_googlemap or get_openstreetmap

  • maptype
    character string providing map theme. options available are “terrain”, “terrain-background”, “satellite”, “roadmap”, and “hybrid” (google maps), “terrain”, “watercolor”, and “toner” (stamen maps), or a positive integer for cloudmade maps (see ?get_cloudmademap)

  • source
    Google Maps (“google”), OpenStreetMap (“osm”), Stamen Maps (“stamen”)

  • force
    force new map (don’t use archived version)

  • messaging
    turn messaging on/off

  • urlonly
    return url only

  • filename
    destination file for download (file extension added according to format). Default NULL means a random tempfile.

  • crop
    (stamen and cloudmade maps) crop tiles to bounding box

  • == color==
    color (“color”) or black-and-white (“bw”)

  • language
    language for google maps

ggmap

ggmap()就是对get_map()获得的地图结果进行绘制,接收的也是一个get_map对象

ggmap(get_map对象)

qmap()

qmap()=get_map()+ggmap(), 它是后两个函数的封装。

实例

b=get_map(location = c(left = 115.7, bottom = 39.4, right = 117.4, top = 40.5))
ggmap(b)  

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值