问题
I'm trying to plot the latitude and longitude, but I'm getting an error message.
The code I'm using is the following
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)
The error message is the following:
Error: ggplot2 doesn't know how to deal with data of class character
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?
回答1:
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)]
Then apply the ggplot function:
ggplot(l.na, aes(x=lon, y=lat,)) + geom_point(size=1.9, alpha=.02)
来源:https://stackoverflow.com/questions/42462677/plot-latitude-and-longitude