[英]Plotting points over google map using R
I am trying to plot some longitude and latitude points over a google map in R however I receive the error message: 我试图在R中的谷歌地图上绘制一些经度和纬度点但是我收到错误消息:
Don't know how to automatically pick scale for object of type data.frame. 不知道如何自动为data.frame类型的对象选择比例。 Defaulting to continuous Error: Aesthetics must either be length one, or the same length as the dataProblems:sg
默认为连续错误:美学必须是长度为1或与dataProblems相同的长度:sg
This is my R Code: 这是我的R代码:
sg <- read.csv("sg.csv")
head(sg)
library(ggmap)
library(mapproj)
map <- get_map(location = 'Midway Point, Tasmania', zoom = 12)
ggmap(map)
mapPoints <- ggmap(map) +
geom_point(aes(x = lon, y = lat, data = sg, alpha = .5))
mapPoints
The data looks like the below: 数据如下所示:
> head(sg)
ref lat lon
1 Male -42.80429 147.4954
2 Male -42.80367 147.4951
3 Male -42.80521 147.4919
4 Male -42.80525 147.4925
5 Male -42.80501 147.4955
6 Male -42.80414 147.4959
Can anyone help me out?? 谁能帮我吗?? Thank you so much.
非常感谢。
It pays to read the error messages. 阅读错误消息是值得的。 I'm a really inexperienced ggplot user and ditto for ggmap.
我是一个非常缺乏经验的ggplot用户,并且同样适用于ggmap。 The error message read:
Error: Aesthetics must either be length one, or the same length as the dataProblems:sg
. 读取的错误消息:
Error: Aesthetics must either be length one, or the same length as the dataProblems:sg
。 So I looked at the examples in ?ggmap
and decided 1) that the data argument shouldn't be in the aes()
call and 2) that you need a third argument in aes
so I pick color and it "worked". 所以我查看了
?ggmap
中的示例,并决定1)数据参数不应该在aes()
调用中,2)你需要aes
的第三个参数,所以我选择颜色并且“工作”。
mapPoints <- ggmap(map) +
geom_point(aes(x = lon, y = lat, color=ref), data = sg, alpha = .5)
mapPoints
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.