2

I'm having some trouble trying to make a spatial visualisation of my data using the package ggmap.

I already have:

  1. ggmap package
  2. Lat_lon of my business
  3. Lat_lon of my 250 customers

I wanna plot my business in green and my customers in red, over a map of my city.

Here's my code atm:

dot.Py
  • 5,007
  • 5
  • 31
  • 52
  • maybe you have 245 rows of invalid LAT and LON for Ribeirao Preto – pcantalupo Sep 11 '15 at 13:07
  • 1
    Please don't post screenshots of data/code. Copy-paste them. – Heroka Sep 11 '15 at 13:11
  • 1
    Please learn how to produce a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) – Jaap Sep 11 '15 at 13:16
  • @pcantalupo, I already tried to plot them using google maps... and it worked. – dot.Py Sep 11 '15 at 13:21
  • @Heroka, thanks.. already changed that! – dot.Py Sep 11 '15 at 13:22
  • @Jaap, already bookmarked that page. thanks a lot! – dot.Py Sep 11 '15 at 13:22
  • 1
    Your customer lat/lon values are pretty far away from *Ribeirao Preto*. Try another zoomlevel (e.g. 8) will help. – Jaap Sep 11 '15 at 13:29
  • @Jaap, I used zoom = 5 and the error continues... only my business is displayed in the map. it looks like it's something wrong in my `dados_empr`... as it plots only 2 of my 245 values.. is there any way to upload my .csv here? – dot.Py Sep 11 '15 at 13:45
  • With `dput(dados_empr)` you wil get output that starts with `structure(...`. You can paste that output in the question. – Jaap Sep 11 '15 at 13:49
  • 1
    I think you need `zoom=4` – Jaap Sep 11 '15 at 13:51
  • @Jaap, well... it seems that my geocode() haven't worked properly.... I think I should refine my adresses and get the coordinates again. / Using zoom = 2 I saw that some of my customers are plotted in wrong cities... but at least I can see them in my map... / I'll improve my data and try again. / Thanks for your efforts in helping me. You should create an answer, so I can accept your help. – dot.Py Sep 11 '15 at 14:03

1 Answers1

2

It looks like you have some customers far far away from your business. You will therefore have to use an appropriate zoom-level; in your case zoom=3 will include most datapoints. With:

library(ggplot2)
library(ggmap)

rp <- get_map(location = 'Ribeirao Preto', zoom = 3, maptype = 'satellite', color = "bw")

ggmap(rp) +
  geom_point(data = dados_empr, aes(x = lon, y = lat), color = 'red', size = 2, shape=19, alpha=0.5) +
  geom_point(data = dados_grnd,  aes(x = lon, y = lat), color = 'green', size = 3, shape=19)

I get:

enter image description here

Jaap
  • 81,064
  • 34
  • 182
  • 193