Reputation: 11
I am trying to plot some longitude and latitude points over a google map in R however I receive the error message:
Don't know how to automatically pick scale for object of type data.frame. Defaulting to continuous Error: Aesthetics must either be length one, or the same length as the dataProblems:sg
This is my R Code:
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.
Upvotes: 1
Views: 914
Reputation: 263481
It pays to read the error messages. I'm a really inexperienced ggplot user and ditto for ggmap. The error message read: 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".
mapPoints <- ggmap(map) +
geom_point(aes(x = lon, y = lat, color=ref), data = sg, alpha = .5)
mapPoints
Upvotes: 3