在Google地图上用R绘制数据点

在Google地图上用R绘制数据点,r,google-maps,twitter,plot,R,Google Maps,Twitter,Plot,我使用searchtwitter函数从twitter中提取tweets,创建了一个包含“经度”和“纬度”列的csv文件,并创建了一个变量“tweets”来读取csv文件。每个tweet/行都有经度和纬度数据。我想在新加坡的谷歌地图上标出推特的位置 如何在使用PlotOnStaticMap函数创建的google地图上绘制点?这是实现我的谷歌地图的代码: sgmap<-GetMap(center="Singapore",zoom=11) PlotOnStaticMap(sgmap) point

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

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

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

sgmap下面是使用
ggmap
ggplot2
执行此任务的另一种方法。使用
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")
库(ggmap)
图书馆(GG2)

sing Try
PlotOnStaticMap(sgmap,lat=tweets$latitude,lon=tweets$longitude,col=“red”,cex=.6)
我试过了,得到了这个错误:MaxZoom(latR,lonR,size)中的错误:缺少参数“size”,没有默认值我得到了这个错误:注释中的错误(“rect”,xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax,:未使用的参数注释中的错误(“rect”,xmin=xmin,xmax=xmax,ymin=ymax,ymax=ymax,fill=darken[2],alpha=as.numeric(darken[1]):未使用的参数(xmin=xmin,xmax=xmax,ymax=ymax,ymin=ymin,ymax=ymax,fill=darken[2],alpha=as.numeric(darken[‌​1] )“我刚从控制台复制了这一点。可能是其他R程序包导致了这一点。您能否从当前R会话中删除所有内容(键入
rm(list=ls(all=TRUE)
)然后重新启动R?然后,上传
ggmap
ggplot2
,看看会发生什么。我已经重新启动R并准确复制了您的代码。我仍然得到了相同的结果error@RachelBoey我再次运行了代码。但是,我没有任何错误消息。您有哪个版本的R和包?它们都是最新的吗?
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)
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")