2

I am trying to use my lat-log data to plot over google maps. For that I tried to download the google maps and then use it for plotting the values.

Here's how I tried to download but I couldn't understand the function properly:

Let's say:

data.lat.long <- data.frame(lat=c(2,3,4,5,6,7,3,7,8,9,2),long=c(3,7,8,9,2,1,2,3,4,5,6),C=c(1,1,1,2,2,1,1,1,1,2,2))

data <- data.lat.long %>% mutate(mean_lat = mean(Latitude)) %>% mutate(mean_long = mean(Longitude))

library(RgoogleMaps)
GetMap(center = c(lat = data$meanlatitude, lon = data$meanlongitude), 
size = c(640, 640), destfile = "C:/m/googlemaps/", zoom = 12,
sensor = "true", maptype = c("terrain"),format = c("gif"),
RETURNIMAGE = TRUE, GRAYSCALE = FALSE, NEWMAP = TRUE, SCALE = 1,
API_console_key = NULL, verbose = 0)

what I am trying to do is: I have calculated max and min lat-long points. And I want to download that region only [from maximum latitude to minimum latitude & maximum longitude to minimum longitude].

ayush
  • 343
  • 3
  • 20
  • You might want to try the `ggmap` package. For some inspiration, see [this](http://stackoverflow.com/questions/23130604/r-plot-coordinates-on-map/23143501#23143501) and [this](http://stackoverflow.com/questions/31285754/how-to-join-ggplot-having-lon-lat-and-fill-value-with-ggmap-in-r/31286663#31286663) answer. – Jaap Jul 23 '15 at 12:36
  • You're code needs a `library(dplyr)` and you're missing `Latitude` and `Longitude` in `data.lat.long`. If those aren't actual lat/lon pairs, please use real ones when you update the post. – hrbrmstr Jul 23 '15 at 12:37
  • @jaap thanks.. I'll try to do it. Is mapgilbert() function is used to download the gmaps? – ayush Jul 23 '15 at 12:38
  • @hrbrmstr I didn't provided the whole code.. I did used that. But it seems that i am doing it wrong! – ayush Jul 23 '15 at 12:39
  • @hrbrmstr can you provide some better results for this? Because I didn't really get how to use the destfile span and other attributes in this! – ayush Jul 23 '15 at 12:40

1 Answers1

1

Basic usage for ggmap:

library(dplyr)
library(ggmap)
library(ggthemes)

data.lat.long <- data.frame(lat=c(2,3,4,5,6,7,3,7,8,9,2),
                            long=c(3,7,8,9,2,1,2,3,4,5,6),
                            C=c(1,1,1,2,2,1,1,1,1,2,2))

data.lat.long %>%
  mutate(mean_lat = mean(lat),
         mean_long = mean(long)) -> dat

# use variables in your own code, pref with a bounding box vs centroid
# as that makes it possible to not rely on the zoom param

loc <- get_map(c(lon=4.545455, lat=5.090909), zoom=4)

gg <- ggmap(loc)
gg <- gg + geom_point(data=data.lat.long,
                      aes(x=long, y=lat),
                      size=3, color="black")
gg <- gg + theme_map()
gg

enter image description here

hrbrmstr
  • 77,368
  • 11
  • 139
  • 205