简体   繁体   English

R纬度经度可视化

[英]R latitude longitude visualization

I'm trying to make a visualization of latitude and longitude values. 我正在尝试对纬度和经度值进行可视化。 Thanks to another post I managed to get the right values to be passed to ggplot. 感谢另一篇文章,我设法将正确的值传递给ggplot。 The code I'm using is as follows: 我正在使用的代码如下:

tweets <- searchTwitter('weather', n=1000,lang='en')
t <- twListToDF(tweets)
lat <- t[, c("latitude")]
lon <- t[, c("longitude")]
l.df <- data.frame(lat,lon)
l.df <- na.omit(l.df)
require(ggplot2)
ggplot(l.df, aes(x=l.df$lon, y=l.df$lat,)) + geom_point(size=10.9, alpha=.02)

The problem is that I'm getting a nearly empty plot. 问题是我的情节几乎是空的。 I'm saying nearly empty as there are some spots but are difficult to identify 我说几乎是空的,因为有一些斑点,但很难识别

How can I get a plot to display the map of the world and dots for the geo-location? 如何获得一个图表来显示世界地图和地理位置的点?

在此输入图像描述

With the leaflet package, you can simply call the map with your data.frame and pass in the values of latitude and longitude to create markers and get started: 使用leaflet包,您只需使用data.frame调用地图并传入纬度和经度值即可创建标记并开始使用:

library(leaflet)
yourMap <- leaflet(l.df) %>% addTiles() %>% addCircles(lng = ~lon, lat = ~lat)
yourMap      # Prints the map

If you choose to use leaflet , be sure to install dependencies because the %>% is the piping operator from the magrittr package. 如果选择使用leaflet ,请确保安装依赖项,因为%>%magrittr包中的管道运算符。

I suggested leaflet since, if you're looking to share your data and/or ever host it on a Shiny web server, they supply great documentation on the RStudio "Leaflet for R" Github page for its use, as I mentioned in the comments. 我建议leaflet因为,如果你想分享你的数据和/或曾经在Shiny网络服务器上托管它们,他们提供了关于RStudio“Leaflet for R” Github页面的优秀文档供我使用,正如我在评论中提到的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM