【问题标题】:Plotting points over google map using R使用R在谷歌地图上绘制点
【发布时间】:2014-11-27 09:19:17
【问题描述】:

我正在尝试在 R 中的谷歌地图上绘制一些经度和纬度点,但是我收到错误消息:

不知道如何为 data.frame 类型的对象自动选择比例。默认为连续 错误:美学长度必须为 1,或与 dataProblems:sg 长度相同

这是我的 R 代码:

sg <- read.csv("sg.csv")
head(sg)

library(ggmap)
library(mapproj)
map <- get_map(location = 'Midway Point, Tasmania', zoom = 12)
ggmap(map)

mapPoints <- ggmap(map) +
geom_point(aes(x = lon, y = lat, data = sg, alpha = .5))
mapPoints

数据如下:

> head(sg)
   ref       lat      lon
1 Male -42.80429 147.4954
2 Male -42.80367 147.4951
3 Male -42.80521 147.4919
4 Male -42.80525 147.4925
5 Male -42.80501 147.4955
6 Male -42.80414 147.4959

谁能帮帮我??非常感谢。

【问题讨论】:

    标签: r google-maps


    【解决方案1】:

    阅读错误消息是值得的。我是一个非常缺乏经验的 ggplot 用户,同样适用于 ggmap。错误消息为:Error: Aesthetics must either be length one, or the same length as the dataProblems:sg。因此,我查看了 ?ggmap 中的示例并决定 1)数据参数不应该在 aes() 调用中和 2)您需要在 aes 中使用第三个参数,所以我选择颜色并且它“有效” .

     mapPoints <- ggmap(map) + 
        geom_point(aes(x = lon, y = lat, color=ref), data = sg, alpha = .5)
     mapPoints
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多