【问题标题】:R geom_point and ggmap, locationsR geom_point 和 ggmap,位置
【发布时间】:2015-01-28 08:23:34
【问题描述】:

我的目标是制作一张地图并将位置放在该地图上。它与R geom_point and ggmap 类似,但我可以得到地图,但连点显示都很难。

这是我正在使用的代码。

require(ggmap)
library(ggmap)
pp<- data.frame(lat=c(48.8535, 48.85418333, 48.86253333, 48.86373333, 48.86698333, 48.87033333,                 48.87281667, 48.86993333, 48.87718333, 48.86251667, 
48.85313333, 48.89153333, 48.88231667, 48.84368333, 48.84221667, 48.84473333, 48.8335,   48.86961667, >48.84681667), lon=c(-122.5735333, -122.54085, -122.5142667,
-122.4969667, -122.4857333, -122.4646, -122.44245, -122.4372167, -122.4128167, -122.4298,     -122.48205, -122.40875, -122.4423833, -122.55515, -122.5196667, -122.52105
, -122.5086333, -122.4067667, -122.4358833))
tenmile <- get_map(location = c(lon = -122.486328, lat = 48.862813),
    color = "color",
    source = "google",
    maptype = "roadmap",
    zoom = 12)
ggmap(tenmile,
extent = "device",
ylab = "Latitude",
xlab = "Longitude")
p<- ggmap(tenmile) + geom_point(data=pp, aes(x=lon, y=lat), color="red", size=30, alpha=0.5)  

【问题讨论】:

    标签: r ggmap


    【解决方案1】:

    我认为您唯一的问题是您没有将初始地图分配给对象。试试这个:

    # Assign to variable
    tenmile.map <- ggmap(tenmile,
          extent = "device",
          ylab = "Latitude",
          xlab = "Longitude")
    # Then add the points to the base map you created.
    p <- tenmile.map + geom_point(data=pp, aes(x=lon, y=lat),
                                  color="red", size=30, alpha=0.5)  
    p
    

    如果您愿意,您可以将这些组合起来,但您仍然需要完成所有地图规范:

    all.in.one <- ggmap(tenmile,
          extent = "device",
          ylab = "Latitude",
          xlab = "Longitude") + 
      geom_point(data=pp, aes(x=lon, y=lat),
                              color="red", size=30, alpha=0.5)  
    all.in.one
    

    最后一条评论:library()require() 之间有非常小的区别,但它们都加载了包,你只需要使用其中一个。很多细节in this question如果你有兴趣。

    【讨论】:

    • @DanielleLove:既然 Gregor 的解决方案有效,您应该接受他的回答并投票(这是礼貌的做法......)。
    猜你喜欢
    • 2013-10-16
    • 2015-05-30
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    • 1970-01-01
    相关资源
    最近更新 更多