【问题标题】:plot data points on googlemap in R在 R 中的 googlemap 上绘制数据点
【发布时间】:2015-01-24 09:44:33
【问题描述】:

我使用 searchtwitter 函数从 twitter 中提取了推文,并创建了一个包含“经度”和“纬度”列的 csv 文件,并创建了一个变量“tweets”来读取 csv 文件。每条推文/行都有经度和纬度数据。我想将推文的位置绘制到新加坡的谷歌地图上。

如何在使用 PlotOnStaticMap 函数创建的谷歌地图上绘制点?这是实现我的谷歌地图的代码:

sgmap<-GetMap(center="Singapore",zoom=11)
PlotOnStaticMap(sgmap)
points(tweets$longitude,tweets$latitude,col="red",cex=.6)

我也试过这个代码:

sgmap<-GetMap(center="Singapore",zoom=11)
PlotOnStaticMap(sgmap,cex=.6,col="red",FUN=points,add=F)
points(tweets$longitude,tweets$latitude,col="red",cex=.6)

和:

sgmap<-GetMap(center=c(1.352083,103.8198),zoom=11,destfile="map.png",maptype="satellite")
PlotOnStaticMap(lat=tweets$latitude,lon=tweets$longitude,zoom=11,cex=.6,col="red",FUN=points)

【问题讨论】:

  • 试试PlotOnStaticMap(sgmap, lat=tweets$latitude, lon=tweets$longitude, col="red",cex=.6)
  • 我试过了,我得到了这个错误: MaxZoom(latR,lonR,size) 中的错误:缺少参数“size”,没有默认值

标签: r google-maps twitter plot


【解决方案1】:

这是使用ggmapggplot2 执行此任务的另一种方法。您使用ggmap 下载地图,然后在ggplot2 中使用geom_point 在地图上绘制数据点。

library(ggmap)
library(ggplot2)

sing <- get_map(location = "singapore", color = "bw",
                zoom = 11, maptype = "toner", source = "google")

# This is a pseudo tweets data frame including long and lat only
set.seed(12)
foo <- data.frame(long = runif(300, 103.68, 104),
                  lat = runif(300, 1.3, 1.42))

ggmap(sing) +
geom_point(data = foo, aes(x = long, y = lat), color = "red")

【讨论】:

  • 我得到这个错误:注释错误(“rect”,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,:未使用的参数(xmin=xmin,xmax=xmax,ymin =ymin,ymax=ymax,fill=darken[2],alpha=as.numeric(darken[1]))
  • "注释错误("rect",xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,: 未使用的参数 (xmin=xmin,xmax=xmax,ymin=ymin,ymax =ymax,fill=darken[2],alpha=as.numeric(darken[‌​1]))" 我刚刚从控制台复制了这个。
  • 可能是其他 R 包导致了这种情况。您能否从当前的 R 会话中删除所有内容(键入 rm(list=ls(all=TRUE))并重新启动 R?然后,上传ggmapggplot2 看看会发生什么。
  • 我已重新启动 R 并准确复制了您的代码。我仍然遇到同样的错误
  • @RachelBoey 我再次运行了代码。但是,我没有任何错误信息。你有哪个版本的 R 和包?它们都是最新的吗?
猜你喜欢
  • 2010-12-23
  • 1970-01-01
  • 2021-10-29
  • 2013-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多