[英]plot data points on googlemap in R
I extracted tweets from twitter using searchtwitter function and created a csv file containing the columns "longitude" and "latitude" and I created a variable "tweets" to read the csv file. 我使用searchtwitter函数从twitter提取了推文,并创建了一个包含“经度”和“纬度”列的csv文件,并创建了一个变量“ tweets”来读取csv文件。 Each tweet/row has longitude and latitude data.
每个推文/行都有经度和纬度数据。 I want to plot the location of the tweets onto the google map of Singapore.
我想将这些推文的位置绘制到新加坡的Google地图上。
How do I plot the points on the google map that I created using PlotOnStaticMap function? 如何在使用PlotOnStaticMap函数创建的Google地图上绘制点? This is the code to achieve my google map:
这是实现我的谷歌地图的代码:
sgmap<-GetMap(center="Singapore",zoom=11)
PlotOnStaticMap(sgmap)
points(tweets$longitude,tweets$latitude,col="red",cex=.6)
I've also tried this code: 我也尝试过以下代码:
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)
and: 和:
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)
Here is another way to do this task using ggmap
and ggplot2
. 这是使用
ggmap
和ggplot2
完成此任务的另一种方法。 You download a map using ggmap
then plot data points on the map using geom_point
in ggplot2
. 您可以使用
ggmap
下载地图,然后使用geom_point
中的ggplot2
在地图上绘制数据点。
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")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.