绘制经纬度 [英] Plot latitude and longitude

查看:105
本文介绍了绘制经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试绘制纬度和经度,但是却收到错误消息.

I'm trying to plot the latitude and longitude, but I'm getting an error message.

我正在使用的代码如下

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.na <- l.df[!is.na(l.df)]
require(ggplot2)
ggplot(l.na, aes(x=lon, y=lat,)) + geom_point(size=1.9, alpha=.02)

错误消息如下:

错误:ggplot2不知道如何处理类字符的数据

Error: ggplot2 doesn't know how to deal with data of class character

我在l.na中获得的值如下:

The values I'm getting in l.na are the following:

[1] "61.22"         "54.55508056"   "37.57"         "-5.14"         "37.78678264"   "29.42989111"   "32.79755357"   "30.26960519"   "29.75523769"  
[10] "51.04839287"   "30.1774"       "44.34334946"   "49.89034914"   "34.05161048"   "41.88804564"   "32.72791305"   "51.52027778"   "-31.77"       

为什么我会收到错误消息?

Any ideas why I'm getting the error message?

推荐答案

尝试将经纬度列转换为数值列.

Try converting the lat and lon columns into numeric.

l.df$lat <- as.numeric(l.df$lat)

l.df$lon <- as.numeric(l.df$lon)

l.na <- l.df[!is.na(l.df)]

然后应用ggplot函数:

Then apply the ggplot function:

ggplot(l.na, aes(x=lon, y=lat,)) + geom_point(size=1.9, alpha=.02)

这篇关于绘制经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆