1

first thank you all for your time.... i want to let you know Im new to using R I am trying to plot my coordinates using R. I have tried already to follow different post an functions one of them i will add it bellow, i have file with coordinates points covers the world i want to plot them in google satellite map? also i have API key but i dont know how to add it in the code?

require(ggplot2)
require(ggmap)
require(maps)
require(mapproj)
require(mapdata)
require(rgeos)
require(maptools)
require(sp)
require(raster)
require(rgdal)
require(dismo)
require(tmp)
####
swf1 <- read.csv("D:/jamal project/swf1.csv",header=TRUE)
head(swf1)
 Lon      Lat
1 46.60638 24.88843
2 39.57275 21.39170
3 39.63389 24.43904
4 46.73168 24.64144
5 46.77773 24.73872
6 43.98056 26.33847
#i try using ggmap’s make_bbox function
swfp <- make_bbox(lon = swf$lon, lat = swf$lat, f = .1)
swfp
        ###i got this messg
        Warning messages:
       1: In min(x, na.rm = na.rm) :
        no non-missing arguments to min; returning Inf
       2: In max(x, na.rm = na.rm) :
        no non-missing arguments to max; returning -Inf
       3: In min(x, na.rm = na.rm) :
        no non-missing arguments to min; returning Inf
       4: In max(x, na.rm = na.rm) :
        no non-missing arguments to max; returning -Inf
       > swfp
      left bottom  right    top 
      -Inf   -Inf    Inf    Inf 

problem that now I don't know how to add my points and I will like one color for each region.

Could anyone help me going forward with it?

the other option I have tried is :

# loading the required packages
library(ggplot2)
library(ggmap)

# creating a sample data.frame with your lat/lon points
lon <- c(-38.31,-35.5)
lat <- c(40.96, 37.5)
df <- as.data.frame(cbind(lon,lat))

# getting the map
mapgilbert <- get_map(location = c(lon = mean(df$lon), lat = mean(df$lat)), 
zoom = 4,
                  maptype = "satellite", scale = 2)

# plotting the map with some points on it
ggmap(mapgilbert) +
geom_point(data = df, aes(x = lon, y = lat, fill = "red", alpha = 0.8), size = 
5, shape = 21) +
guides(fill=FALSE, alpha=FALSE, size=FALSE)

when i run it i got this Error in download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") : cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=39.23,-36.905&zoom=4&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false' In addition: Warning message: In download.file(url, destfile = tmp, quiet = !messaging, mode = "wb") : cannot open URL 'http://maps.googleapis.com/maps/api/staticmap?center=39.23,-36.905&zoom=4&size=640x640&scale=2&maptype=satellite&language=en-EN&sensor=false': HTTP status was '403 Forbidden'

help please the coordinates file HERE try it ... thank you

Maram Mubarak
  • 323
  • 2
  • 3
  • 11
  • Have you tried using e.g. https://cran.r-project.org/web/packages/RgoogleMaps ? – Roman Luštrik Nov 25 '18 at 09:17
  • @RomanLuštrik yes i have i got some Error like Error in GetMap(center = center, zoom = zoom, type = "satellite", destfile = "satellite.png") : unused argument (type = "satellite") – Maram Mubarak Nov 25 '18 at 09:28
  • In the second case, you probably need to provide a API key .See https://stackoverflow.com/questions/51481913/mapping-in-ggmap-with-api-key . – lbusett Nov 25 '18 at 09:41
  • In the first case, you have a case mismatch in column names. This should be : `swfp <- make_bbox(lon = swf$Lon, lat = swf$Lat, f = .1)` – lbusett Nov 25 '18 at 09:43
  • @Ibusett thank you for your answer, even when i provide the API key still no map and points. may i ask you to try in my data to see what i have got wrong? `swf1 <- read.csv("D:/jamal project/swf1.csv",header=TRUE) head(swf1) swfp <- make_bbox(lon = swf$Lon, lat = swf$Lat, f = .1) swfp swfp <- get_map(location = swfp, maptype = "satellite", source = "google") ggmap(swfp) + geom_point(data = sisquoc, mapping = aes(x = lon, y = lat), color = "red")` – Maram Mubarak Nov 25 '18 at 17:20
  • @lbusett thank you for your answer, even when i provide the API key still no map and points. may i ask you to try in my data to see what i have got wrong? `swf1 <- read.csv("D:/jamal project/swf1.csv",header=TRUE) head(swf1) swfp <- make_bbox(lon = swf$Lon, lat = swf$Lat, f = .1) swfp swfp <- get_map(location = swfp, maptype = "satellite", source = "google") ggmap(swfp) + geom_point(data = sisquoc, mapping = aes(x = lon, y = lat), color = "red")` – Maram Mubarak Nov 26 '18 at 17:11
  • @lbusett may you help me please.. – Maram Mubarak Nov 26 '18 at 17:12
  • Have a look here: https://lucidmanager.org/geocoding-with-ggmap/ - You probably need to install the devel version from github. – lbusett Nov 27 '18 at 17:30
  • @lbusett i did that also, and i got lots of warnings, may i ask you to have a look in the file please – Maram Mubarak Nov 27 '18 at 18:03
  • try `library(googleway); google_map(key = "your_API_key") %>% add_markers( data = swf1, lon = "Lon", lat = "Lat") ` – SymbolixAU Nov 27 '18 at 21:19
  • @SymbolixAU hi, thank you so much for helping.. i need a code to plotting my coordinates in satellite world map so when i run the code it takes me to a web-page with the map in it like (https), also the code you give me `library(googleway); google_map(key = "your_API_key") %>% add_markers( data = swf1, lon = "Lon", lat = "Lat")` can i control with size symples ? thank you so much thank you..... – Maram Mubarak Dec 02 '18 at 08:45
  • @SymbolixAU may you help me with this one i tried to plot them to web browser with this code `swf1 <- read.csv("D:/modilingfinel/swf1.csv",header=TRUE) head(swf1) swfp <- make_bbox(lon = swf1$Lon, lat = swf1$Lat, f = .1) library(googleway); google_map(key = "api_key") %>% add_markers( data = swf1, lon = "Lon", lat = "Lat") google_map_url(swf1) ` and its open a web browser but without the points help thank you for your time – Maram Mubarak Dec 03 '18 at 14:35
  • @SymbolixAU Thank you for your answer, maybe you didn't see my last question i want to save my map with HTML URL so when i run the code it takes my to web-browser so i can control the zooming much better and shearing it with people i have tried this function google_map_url and savewidgets, sems not working... thank you – Maram Mubarak Dec 04 '18 at 06:56
  • In [this issue](https://github.com/SymbolixAU/googleway/issues/79) I describe how to get `webshot` working - is this what you're after? – SymbolixAU Dec 04 '18 at 08:07
  • @SymbolixAU no, i want to save the map like a HTML url. not like jpg .... – Maram Mubarak Dec 04 '18 at 08:13
  • `htmlwidgets::saveWidget(g, file = "googleMap.html")` saves it as an .html page. – SymbolixAU Dec 04 '18 at 08:15
  • @SymbolixAU i tried `swf1 <- read.csv("D:/modilingfinel/swf1.csv",header=TRUE) head(swf1) swfp <- make_bbox(lon = swf1$Lon, lat = swf1$Lat, f = .1) library(googleway); google_map(key = "api_key") %>% add_markers( data = swf1, lon = "Lon", lat = "Lat") htmlwidgets::saveWidget(swf1, file = "googleMap.html")` and it give me Error in system.file(config, package = package) : 'package' must be of length 1 – Maram Mubarak Dec 04 '18 at 08:34
  • `swf1` is not the widget object. You'll want to assign the map to a variable and save that - `g <- google_map(key = "api_key") %>% add_markers( data = swf1, lon = "Lon", lat = "Lat") htmlwidgets::saveWidget(g, file = "googleMap.html")` – SymbolixAU Dec 04 '18 at 09:43
  • @SymbolixAU even though i try it `g <- google_map(key = "api_key") %>% add_markers( data = swf1, lon = "Lon", lat = "Lat") htmlwidgets::saveWidget(g, file = "googleMap.html")` i got this Error: unexpected symbol in "g <- google_map(key = "api_key") %>% add_markers( data = swf1, lon = "Lon", lat = "Lat") htmlwidgets" – Maram Mubarak Dec 04 '18 at 09:59
  • the `htmlwidgets::saveWidget()` needs to be on a new line – SymbolixAU Dec 04 '18 at 10:06
  • @SymbolixAU i got this pandoc.exe: Could not fetch https://maps.googleapis.com/maps/api/js?key=api_key &libraries=visualization,geometry,places,drawing TlsExceptionHostPort (HandshakeFailed (Error_Misc "user error (unexpected type received. expecting handshake and got: Alert [(AlertLevel_Fatal,HandshakeFailure)])")) "maps.googleapis.com" 443 Error: pandoc document conversion failed with error 67 – Maram Mubarak Dec 04 '18 at 10:52
  • @SymbolixAU i know im bothering you im so sorry but i really wont to get this right – Maram Mubarak Dec 05 '18 at 13:34
  • Have you read [this issue](https://github.com/SymbolixAU/googleway/issues/79) I linked earlier and tried the solution? – SymbolixAU Dec 05 '18 at 21:25
  • @SymbolixAU yes dear when you send it to me i try it i got this errer > setwd("D:/modilingfinel/") > htmlwidgets::saveWidget(g, file = "googleMap.html") pandoc.exe: Could not fetch https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=visualization,geometry,places,drawing TlsExceptionHostPort (HandshakeFailed (Error_Misc "user error (unexpected type received. expecting handshake and got: Alert [(AlertLevel_Fatal,HandshakeFailure)])")) "maps.googleapis.com" 443 – Maram Mubarak Dec 06 '18 at 08:18
  • @SymbolixAU The rest of errer Error: pandoc document conversion failed with error 67 > webshot::webshot(url = "file:/D:/modilingfinel/savewidgets/googleMap.html", + file = "googleMap.jpg") PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable. NULL – Maram Mubarak Dec 06 '18 at 08:19
  • "PhantomJS not found. You can install it with webshot::install_phantomjs()" <- have you done this? – SymbolixAU Dec 06 '18 at 08:27
  • @SymbolixAU yes many times from r and as zip from internet i got this > install.packages("phantomjs") Installing package into ‘C:/Users/maram/Documents/R/win-library/3.5’ (as ‘lib’ is unspecified) Warning in install.packages : package ‘phantomjs’ is not available (for R version 3.5.1) – Maram Mubarak Dec 06 '18 at 08:34
  • I don't think I have the answers for you. The only thing I can suggest is have a look at [this question](https://stackoverflow.com/questions/25721884/how-should-i-deal-with-package-xxx-is-not-available-for-r-version-x-y-z-wa), and also if you still have `webshot` issues then you an ask on [their github issues](https://github.com/wch/webshot) page. – SymbolixAU Dec 06 '18 at 08:48
  • @SymbolixAU thank you so much for everything, i will keep trying some how i will make it work.... thank you again – Maram Mubarak Dec 06 '18 at 09:08
  • @SymbolixAU hello once again, i tried to do a heat map in the same data using this code `swf1 <- read.csv("D:/modilingfinel/swf1.csv",header=TRUE) head(swf1) set.seed(20170417) df <- swf1 df$weight <- sample(1:10, size = nrow(df), replace = T) google_map(key = "API_Key", data = df) %>% add_heatmap(lon = "Lon", lat = "Lat", weight = "weight", option_radius = 0.001, legend = T)` and i got the lagend without heat map – Maram Mubarak Dec 10 '18 at 17:33
  • please start a new question – SymbolixAU Dec 10 '18 at 20:37
  • @SymbolixAU i did [https://stackoverflow.com/questions/53713456/displaying-and-animated-google-heat-map] – Maram Mubarak Dec 10 '18 at 20:52

1 Answers1

2

Here's a solution using library(googleway)

library(googleway)

set_key( "API_KEY" )

swf1 <- read.table(text='
Lon      Lat
1 46.60638 24.88843
2 39.57275 21.39170
3 39.63389 24.43904
4 46.73168 24.64144
5 46.77773 24.73872
6 43.98056 26.33847')

## you've asked for colours and sizes, so I'm making some random values which you can use in the plot
swf1$region <- sample(c("a","b"), size = nrow(swf1), replace = T)
swf1$size <- sample(50000:100000, size = nrow(swf1))

google_map() %>%
  add_circles(
    data = swf1, lon = "Lon", lat = "Lat", fill_colour = "region", radius = "size"
  )

enter image description here

And to get a satellite view, press the 'satellite' button on the map

enter image description here

SymbolixAU
  • 25,502
  • 4
  • 67
  • 139