dkahle / ggmap Goto Github PK
View Code? Open in Web Editor NEWA package for plotting maps in R with ggplot2
A package for plotting maps in R with ggplot2
Is it possible to give more than one style argument to get_googlemap?
I wrote a possible solution, but I am not good with github yet so you get it here:
In line 188
You could insert:
if(is.list(style)){
style <- lapply(style, FUN = function(style) paste(paste(names(style), style, sep = ":"), collapse = "|" ))
}
And in line 294
You could add a collapse argument to paste:
style_url <- if(!missing(style)){ paste("style=", style, sep="", collapse ="&") } else { "" }
This might add support for style arguments in this form:
style <- list()
style[[1]] <- c(feature = "all", element = "labels", visibility = "off")
style[[2]] <- c(feature = "landscape.man_made", element = "geometry", lightness = -100)
geo_map_cph <- get_googlemap2("Vanløse", zoom = 11, color = "bw", maptype = "terrain", style = style)
map.cph <- ggmap(geo_map_cph, extent = "device")
map.cph
I think you need to adjust the checks for argument validity for this code to work.
require(ggmap)
pic = get_googlemap(center = c(lon = -95.3632715, lat = 29.7632836), zoom = 10, size = c(640, 640))
get_googlemap
does not work and return an error:
错误于download.file(url, destfile = paste0("ggmapFileDrawer/", destfile), :
无法打开目的文件'ggmapFileDrawer/.png',原因是'没有那个文件或目录'
which means couldn't open file 'ggmapFileDrawer/.png' cause the folder 'ggmapFileDrawer/' isn't exist.
It will work after I create a folder named 'ggmapFileDrawe' in my working folder.
Hi. Thanks for this very helpful package.
I found that unwanted single space is appearing in the parameters in URL to be sent to Google Maps. When I checked in the code, I saw the following:
scale_url <- if (!missing(scale)) {
paste("scale=", scale)
}
In the paste
function above, sep=""
is missing and hence an unwanted space is appearing in the generated URL. The same happens for scale, style and maybe other places where I haven't checked.
pointing to this repo
Let me see if I can start a conversation about a recent issue.
In the course of batch processing many addresses (1000s...) to geocode, I sometimes hit an error that causes geocode to fail and take with it all of the previously successful executions. It might be an Error 500 (internal server) or something like #24.
I'm wondering what would be the better approach to error handling: in the event of an error should geocode handle this internally and return only the successful results with a warning for the error(s)? Or, should I handle this externally by looping through the list of addresses and submit an address to geocode one by one and cache the successful results separately as part of the loop?
For now the latter is easy enough to do and keep my project moving, but if someone will suggest an approach for geocode to handle this internally, I would have interest to write a patch and submit a pull request.
Compare the readability of the following maps
library("ggmap")
crimes <- subset(crime, offense %in% c("murder", "rape"))
crimes <- crimes[crimes$lat < 30.5,]
houston <- get_map("houston", zoom=10)
bb <- attr(houston, "bb")
points <- geom_point(aes(x=lon, y=lat, colour=offense), data = crimes, size=2)
ggmap(houston, expand=T) + theme_nothing() + points
ggmap(houston, expand=T) + theme_nothing() +
annotate("rect", xmin=bb$ll.lon, ymin=bb$ll.lat,
xmax=bb$ur.lon, ymax=bb$ur.lat,
fill="white", alpha=0.5) +
points
ggmap(houston, expand=T) + theme_nothing() +
annotate("rect", xmin=bb$ll.lon, ymin=bb$ll.lat,
xmax=bb$ur.lon, ymax=bb$ur.lat,
fill="black", alpha=0.5) +
points
It would be nice to have this functionality built into ggmap (and qmap etc.). Possible interfaces could be
presets such as dodge
or wash
(lighten) and burn
or dim
(darken)
colorize
argument which gives control over the colour and opacity and enables the user to do
ggmap(houston, expand=T) + theme_nothing() +
annotate("rect", xmin=bb$ll.lon, ymin=bb$ll.lat,
xmax=bb$ur.lon, ymax=bb$ur.lat,
fill="purple", alpha=0.5) +
points
even if that's ugly ;)
When using geom_polygon with ggmap, polygons that are drawn onto the map are incorrect if the initial zoom level is too small (far away).
Reproducible example code that produces a correct polygon:
longitude <- c(-83.01422, -83.01429, -83.01468, -83.01466, -83.01377, -83.01331, -83.01285) latitude <- c(39.98964, 39.98962, 39.99023, 39.99031, 39.99068, 39.99061, 39.99026) coordinates <- data.frame(longitude, latitude) mapImageData <- ggmap::get_map(c(mean(range(longitude)), mean(range(latitude))), zoom=15) map <- ggmap::ggmap(mapImageData) map <- map + ggplot2::geom_polygon(ggplot2::aes(x=longitude, y=latitude), data=coordinates) plot(map)
The same code that produces an incorrect polygon (might need to zoom in to see):
longitude <- c(-83.01422, -83.01429, -83.01468, -83.01466, -83.01377, -83.01331, -83.01285) latitude <- c(39.98964, 39.98962, 39.99023, 39.99031, 39.99068, 39.99061, 39.99026) coordinates <- data.frame(longitude, latitude) mapImageData <- ggmap::get_map(c(mean(range(longitude)), mean(range(latitude))), zoom=14) map <- ggmap::ggmap(mapImageData) map <- map + ggplot2::geom_polygon(ggplot2::aes(x=longitude, y=latitude), data=coordinates) plot(map)
When using ggmap in R devel I have problems with finding the function scale_clone see the error and all code below. Anything i'm doing wrong? or has this to do with changes in namespaces in R
ggmap> ggmap(hdf, extent = "normal")
Error in match.fun(FUN) : object 'scale_clone' not found
In addition: Warning message:
In initialize(value, ...) :
Class definition for Class "Scales" doesn't have a parent environment for objects defined. Bug??
> require(ggmap)
Loading required package: ggmap
Loading required package: ggplot2
Need help? Try the ggplot2 mailing list: http://groups.google.com/group/ggplot2.
Google Maps API Terms of Service: http://developers.google.com/maps/terms.
Please cite ggmap if you use it: see citation('ggmap') for details.
> example(ggmap)
ggmap> ## extents and legends
ggmap> ##################################################
ggmap> hdf <- get_map()
Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=29.763284,-95.363271&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
ggmap> ggmap(hdf, extent = "normal")
Error in match.fun(FUN) : object 'scale_clone' not found
In addition: Warning message:
In initialize(value, ...) :
Class definition for Class "Scales" doesn't have a parent environment for objects defined. Bug??
> installed.packages()['ggmap',]
Package
"ggmap"
LibPath
"/home/bart/bmisc/small_projects/rDevel/svn/R/library"
Version
"2.5"
Priority
NA
Depends
"\nR (>= 2.14.0),\nggplot2 (>= 0.9.2)"
Imports
"\nproto,\nscales,\nRgoogleMaps,\npng,\nplyr,\nreshape2,\ngrid,\nrjson,\nmapproj,\njpeg,\ngeosphere,\ndigest"
LinkingTo
NA
Suggests
"\nMASS,\nstringr,\nhexbin,\ndplyr"
Enhances
NA
License
"GPL-2"
License_is_FOSS
NA
License_restricts_use
NA
OS_type
NA
MD5sum
NA
NeedsCompilation
NA
Built
"3.3.0"
> R.version
_
platform x86_64-unknown-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status Under development (unstable)
major 3
minor 3.0
year 2015
month 07
day 04
svn rev 68627
language R
version.string R Under development (unstable) (2015-07-04 r68627)
nickname Unsuffered Consequences
When plotting with source maps from cloudmade the latitude of the grid does not always correspond with the map features. It starts to be noticeable at around zoom level 7 and by level 4 can be off by nearly 3 degrees.
At zoom levels greater than 8 it seems negligible and longitude seems unaffected. Google and OSM maps do not have this problem.
This example centred on Europe illustrates the problem:
gmap = get_map(location = c(0,50), zoom = 4)
omap = get_map(location = c(0,50), zoom = 4, source="osm")
cmap = get_map(location = c(0,50), zoom = 4, source = 'cloudmade', api_key = api_key)
ggmap(gmap) + geom_hline(yintercept=c(30, 40, 50, 60))
ggmap(omap) + geom_hline(yintercept=c(30, 40, 50, 60))
ggmap(cmap) + geom_hline(yintercept=c(30, 40, 50, 60))
I'll be using the final maps for a commercial project so I cannot use the Google maps. OSM is OK but the advantage of CloudMade is the ability customise with your own style so I can get a nice clean look.
Thanks for reading.
Hi,
This is probably not related to ggmap
itsefl but impairs its usage (and maybe you can work around it). Quite otfen, I cannot download a tile through R while using the address in a web browser works.
For example
qmap("new-york", zoom=13, source="stamen", maptype="watercolor")Error in download.file(urls[[k]], destfile = destfile, quiet = !messaging, :
cannot open URL 'http://tile.stamen.com/watercolor/13/2411/3078.png'
In addition: Warning message:
In download.file(urls[[k]], destfile = destfile, quiet = !messaging, :
cannot open: HTTP status was '504 Gateway Time-out'
while immediately after, using http://tile.stamen.com/watercolor/13/2411/3078.png
in chrome returns the map.
However, both curl
and wget
also get the 504 time out.
Is there a usage limit in stamen maps?
Hi,
It seems that there might be an issue with how ggmap parses 'style' arguments to 'get_googlemap'. At the moment, on line 255 of 'get_googlemap.R', the 'style' argument is prefixed with 'style=' before being added to the URL for the request to Google Maps:
style_url <- if(!missing(style)){ paste("style=", style) } else { "" }
Unfortunately, 'paste' inserts an additional space (%20) between 'style=' and the 'style' argument, which causes Google to ignore the given styling information. To fix this, all that's needed is to specify an empty separator in 'paste':
style_url <- if(!missing(style)){ paste("style=", style, sep="") } else { "" }
Included below is an example, showing the 'style' argument being used to leave out the labels on a Google Maps terrain map. Without the above change, the current version of ggmap returns a map with the styling information ignored and all of the text labels still visible:
library(ggplot2)
library(ggmap)
# Suppress text labels on Google Maps terrain maps.
map.nolabels = get_googlemap(center = c(lon = -106.5813, lat = 52.47975), zoom = 10, maptype = 'terrain', style = 'feature:all|element:labels|visibility:off')
ggmap(map.nolabels, extent = 'device')
I hope this helps, but if any other information is needed to reproduce this issue, please let me know, and I would be glad to do what I can.
I have the dev version of ggplot2 and scales installed so perhaps that is causing problems:
> install_github("dkahle/ggmap")
Downloading github repo dkahle/ggmap@master
Installing ggmap
Skipping 2 packages ahead of CRAN: ggplot2, scales
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ \
--no-save --no-restore CMD INSTALL \
'/private/var/folders/wc/zv89d1fx5nxdljsysq40m6vr0000gn/T/RtmpYSGjDx/devtoolse2a716fe460/dkahle-ggmap-99653f1' \
--library='/Library/Frameworks/R.framework/Versions/3.2/Resources/library' \
--install-tests
* installing *source* package ‘ggmap’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Warning: replacing previous import by ‘grid::arrow’ when loading ‘ggmap’
Warning: replacing previous import by ‘grid::unit’ when loading ‘ggmap’
Warning: replacing previous import by ‘scales::alpha’ when loading ‘ggmap’
Error in eval(expr, envir, enclos) : could not find function "eval"
Error : unable to load R code in package ‘ggmap’
ERROR: lazy loading failed for package ‘ggmap’
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/ggmap’
* restoring previous ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/ggmap’
Error: Command failed (1)
> sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.8.0
loaded via a namespace (and not attached):
[1] httr_1.0.0 R6_2.1.0 magrittr_1.5 rversions_1.0.2
[5] tools_3.2.1 curl_0.9.1 Rcpp_0.12.0 memoise_0.2.1
[9] xml2_0.1.1 stringi_0.5-5 git2r_0.10.1 stringr_1.0.0
[13] digest_0.6.8 fortunes_1.5-2
> library(ggplot2)
> session_info()
Session info -------------------------------------------------------------------
setting value
version R version 3.2.1 (2015-06-18)
system x86_64, darwin13.4.0
ui X11
language (EN)
collate en_US.UTF-8
tz America/Chicago
Packages -----------------------------------------------------------------------
package * version date source
colorspace 1.2-6 2015-03-11 CRAN (R 3.2.0)
curl 0.9.1 2015-07-04 CRAN (R 3.2.0)
devtools * 1.8.0 2015-05-09 CRAN (R 3.2.0)
digest 0.6.8 2014-12-31 CRAN (R 3.2.0)
fortunes 1.5-2 2013-12-14 CRAN (R 3.2.0)
ggplot2 * 1.0.1.9002 2015-08-05 Github (hadley/ggplot2@d5947cb)
git2r 0.10.1 2015-05-07 CRAN (R 3.2.0)
gtable 0.1.2 2012-12-05 CRAN (R 3.2.0)
httr 1.0.0 2015-06-25 CRAN (R 3.2.0)
magrittr 1.5 2014-11-22 CRAN (R 3.2.0)
memoise 0.2.1 2014-04-22 CRAN (R 3.2.0)
munsell 0.4.2 2013-07-11 CRAN (R 3.2.0)
plyr 1.8.3 2015-06-12 CRAN (R 3.2.0)
R6 2.1.0 2015-07-04 CRAN (R 3.2.0)
Rcpp 0.12.0 2015-07-25 CRAN (R 3.2.0)
rstudioapi 0.3.1 2015-04-07 CRAN (R 3.2.0)
rversions 1.0.2 2015-07-13 CRAN (R 3.2.0)
scales 0.2.5.9003 2015-08-05 Github (hadley/scales@356bee8)
stringi 0.5-5 2015-06-29 CRAN (R 3.2.0)
stringr 1.0.0 2015-04-30 CRAN (R 3.2.0)
xml2 0.1.1 2015-06-02 CRAN (R 3.2.0)
I would like to be able to use UTM coordinates for my axes in ggmap. I currently do this by getting my background with get_map()
, converting the bounding box attributes via rgdal::spTransform
, and using ggplot() + inset_raster() + ... + coord_fixed()
. For small map areas, UTM are more understandable units because they are in meters. It would probably be helpful to be able to convert to meters/km and/or set the axes to start at zero at the origin.
The googlemaps API will allow transit requests for buses, gondolas, monorails, and more! Is there any plan to incorporate transit as a mode in the route function?
Entered this command to import a map of Chicago, IL:
chicagoMap <- get_stamenmap(location = 'Chicago', zoom = 12)
Was surprised to receive a map of Houston, TX instead.
I was able to get a map of Chicago with this command:
get_stamenmap(bbox = c(left = -87.9401009, bottom = 41.643919, right = -87.523984, top = 42.0230219), zoom=12)
But just thought it would be helpful to report this.
I'm currently building maps at zoom levels around 15-16, sometimes more. The stamen maps ("toner" type) seems to be more accurate than the other types. All of my coordinates are currently shifted a little to the left along the longitude from where they should be (they are locations for buildings only they're found in streets and parks).
For example (inaccurate):
ny_plot<-ggmap(get_map(location=center,zoom=16,maptype='terrain'))
ny_plot + geom_point(x= -73.96457, y= 40.80993, color="red")
versus (accurate):
ny_plot<-ggmap(get_map(location=center,zoom=16,maptype='toner'))
ny_plot + geom_point(x= -73.96457, y= 40.80993, color="red")
I'm using:
ggmap version 2.4
ggplot version 1.01
R version 3.1.3
The get_***
functions may have a support to caching mechanism.
The basic idea is,
digest::digest
get_***
functions may have an option force
. If true ignore the cache and always download a new map.When running on geocode on each row of a data.table, data.table will give a type mismatch error if any of the rows return NULL/NA for a location.
Error in `[.data.table`(crimes, , geocodeWrapper(Location), by = Location) :
Column 1 of result for group 178 is type 'logical' but expecting type 'double'. Column types must be consistent for each group.
For example, lat and lon are expected to be reals, if missing or null should return as NA_real_
Would it be possible to have a geom_ggmap()
that made it easier to add a layer to an existing plot?
I think this should just be a simple modification of insert_raster
that also gets the attributes from the object. Something like:
geom_ggmap <- function(map) {
stopifnot(inherits(map, "ggmap"))
bb <- attr(mi_raster$bb)
GeomRasterAnn$new(
geom_params = list(
raster = raster,
xmin = bb[1],
ymin = bb[2],
xmax = bb[3],
ymax = bb[4]
)
stat = "identity",
position = "identity",
data = NULL,
inherit.aes = FALSE
)
}
(note the use of inherit.aes = FALSE
- insert_raster
should also do that
Hello, all:
In order to avoid a ggsave error with tableGrob objects, I updated to the development version of ggplot2 from GitHub (1.0.1.9003).
However, it looks like the ggmap() function now pushes an unused argument down to layer(), resulting in the following error:
map <- get_map()
ggmap(map)
Error in layer(mapping = NULL, data = NULL, stat = "identity", geom = <environment>, :
unused argument (geom_params = list(raster = c("#E2E8DC", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E4EADE", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E0E5D8", "#E0E5D8", "#E0E5D8", "#E0E5D8", "#E2E8DC", "#E2E8DC", "#E4EADE", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E0E5D8", "#E2E8DC", "#E2E8DC", "#E4EADE", "#E4EADE", "#E4EADE", "#E4EADE", "#E4EADE", "#E0E5D8", "#E4EADE", "#E8EADE",
"#E4EADE", "#E4EADE", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E0E5D8", "#E0E5D8", "#E4EADE", "#E2E8DC", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E4EADE", "#E2E8DC", "#E4EADE", "#E2E8DC", "#E0E5D8", "#E2E8DC", "#E2DFD4", "#E2E8DC", "#F8F8F8", "#F8F8F8", "#E4EADE", "#E4EADE", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E2E8DC", "#E4EADE", "#E0E5D8", "#E2E8DC", "#DCD8D0", "#E8EAD ...
sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] stringr_1.0.0 reshape2_1.4.1 scales_0.3.0 dplyr_0.4.3 zoo_1.7-12 lubridate_1.3.3 leafletR_0.3-3
[8] jsonlite_0.9.17 brew_1.0-6 ggmap_2.5.2 rgdal_1.0-7 classInt_0.1-23 RColorBrewer_1.1-2 rgeos_0.3-13
[15] maptools_0.8-37 sp_1.2-0 maps_3.0.0-2 ggplot2_1.0.1.9003 gtable_0.1.2 gridExtra_2.0.0 RCurl_1.95-4.7
[22] bitops_1.0-6
loaded via a namespace (and not attached):
[1] Rcpp_0.12.1 plyr_1.8.3 class_7.3-14 tools_3.2.2 digest_0.6.8 memoise_0.2.1 lattice_0.20-33
[8] png_0.1-7 DBI_0.3.1 rstudioapi_0.3.1 mapproj_1.2-4 parallel_3.2.2 proto_0.3-10 e1071_1.6-7
[15] RgoogleMaps_1.2.0.7 R6_2.1.1 jpeg_0.1-8 foreign_0.8-66 RJSONIO_1.3-0 magrittr_1.5 assertthat_0.1
[22] geosphere_1.4-3 colorspace_1.2-6 labeling_0.3 stringi_0.5-5 lazyeval_0.1.10 munsell_0.4.2 rjson_0.2.15
Can y'all please help us out?
Many thanks.
I might be way of the mark here, but after a good look through the documentation there isn't a way to force new geocoding for cached items is there?
This might be an issue if for example a string is geocoded with the wrong encoding and contains special characters. Then the user is forced to figure out that the geocoded places are stored in the .GeocodeInformation and remove it. Since new geocoding with the right encoding won't suffice.New workfile would also do the trick but maybe that is not the right approach.
Maybe a note in the documentation or a force argument in geocode?
An error is thrown with subsequent attempts to geocode a location that had multiple matches and the response cached in .GeocodedInformation
. The loc
variable used in the message is only defined when the result is not on file.
This is fixed by changes in #61
> geocode("Peach Leaf Gaithersburg MD 20878",source="google",messaging=T)
contacting http://maps.googleapis.com/maps/api/geocode/json?address=Peach+Leaf+Gaithersburg+MD+20878&sensor=false...Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Peach+Leaf+Gaithersburg+MD+20878&sensor=false
done.
more than one location found for "Peach Leaf Gaithersburg MD 20878", using address
"peach leaf drive, gaithersburg, md 20878, usa"
lon lat
1 -77.25023 39.10837
>
> geocode("Peach Leaf Gaithersburg MD 20878",source="google",messaging=T)
Using stored information.
Error in paste("more than one location found for \"", loc, "\", using address\n \"", :
object 'loc' not found
Just wondering if in the course of development of this (very awesome) package, if the possibility of interfacing with Landsat had been considered? Not pushing this for a feature request, just wanted to know from people who are more familiar with the landscape/obstacles. I haven't kept up with U.S. map offerings in the recent years but doing a search now yields some promising leads:
The most promising service seems to be AWS's Landsat S3:
Landsat 8 data is available for anyone to use via Amazon S3. All Landsat 8 scenes from 2015 are available along with a selection of cloud-free scenes from 2013 and 2014. All new Landsat 8 scenes are made available each day, often within hours of production.
A CLI from Development Seed: Power tools for Satellite Imagery
Over the past few months we’ve built tools to automate our own work with satellite imagery. It once took us all day to collect, georeference, composite, color correct, and pan-sharpen imagery. Now, we can do it in a matter of minutes. We’ve packaged our processing scripts into a command line utility. Landsat-util makes it easier for other developers and organizations to work with open satellite imagery.
USGS: The following examples demonstrate usage of The National Map services in other APIs.
GIS Stackexchange: Site to download al USGS Topo Maps in bulk - a couple of interesting suggestions and options.
ProPublica's SimpleTiles library, which may have some useful guidance: https://propublica.github.io/simple-tiles/
Use tempfile()
Reproducible example:
geocode("Pelagonia, Macedonia", output = "more")
Returns the message
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Pelagonia,+Macedonia&sensor=false
Google Maps API Terms of Service : http://developers.google.com/maps/terms
Error in data.frame(long_name = "Pelagonia", short_name = "Pelagonia", :
arguments imply differing number of rows: 1, 0
Under the dev version of ggplot2, ggmap will not install from either CRAN or github.
install.packages('ggmap')
Installing package into ‘/usr/local/lib/R/3.2/site-library’
(as ‘lib’ is unspecified)
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 33 2879k 33 961k 0 0 1438k 0 0:00:02 --:--:-- 0:00:02 1436k100 2879k 100 2879k 0 0 2832k 0 0:00:01 0:00:01 --:--:-- 2833k
* installing *source* package ‘ggmap’ ...
** package ‘ggmap’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Warning: replacing previous import by ‘grid::arrow’ when loading ‘ggmap’
Warning: replacing previous import by ‘grid::unit’ when loading ‘ggmap’
Warning: replacing previous import by ‘scales::alpha’ when loading ‘ggmap’
Error in eval(expr, envir, enclos) : could not find function "eval"
Error : unable to load R code in package ‘ggmap’
ERROR: lazy loading failed for package ‘ggmap’
* removing ‘/usr/local/lib/R/3.2/site-library/ggmap’
Warning in install.packages :
installation of package ‘ggmap’ had non-zero exit status
library(devtools)
install_github("dkahle/ggmap")
Downloading GitHub repo dkahle/ggmap@master
Installing ggmap
Skipping 1 packages ahead of CRAN: ggplot2
'/usr/local/Cellar/r/3.2.2_1/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save \
--no-restore CMD INSTALL \
'/private/var/folders/mc/rdd5ddpn2ng8ypg91nk__71c0000gn/T/Rtmpliic2O/devtools5c622cb5cf78/dkahle-ggmap-8972677' \
--library='/usr/local/lib/R/3.2/site-library' --install-tests
* installing *source* package ‘ggmap’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Warning: replacing previous import by ‘grid::arrow’ when loading ‘ggmap’
Warning: replacing previous import by ‘grid::unit’ when loading ‘ggmap’
Warning: replacing previous import by ‘scales::alpha’ when loading ‘ggmap’
Error in eval(expr, envir, enclos) : could not find function "eval"
Error : unable to load R code in package ‘ggmap’
ERROR: lazy loading failed for package ‘ggmap’
* removing ‘/usr/local/lib/R/3.2/site-library/ggmap’
Error: Command failed (1)
sessionInfo()
R version 3.2.2 (2015-08-14)
Platform: x86_64-apple-darwin14.5.0 (64-bit)
Running under: OS X 10.10.3 (Yosemite)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] maps_3.0.0-2 devtools_1.9.1 sp_1.2-0
loaded via a namespace (and not attached):
[1] httr_1.0.0 R6_2.1.1 magrittr_1.5 tools_3.2.2 curl_0.9.3
[6] shinychord_0.0.99 memoise_0.2.1 stringi_0.5-5 grid_3.2.2 stringr_1.0.0
[11] digest_0.6.8 lattice_0.20-33
It is possible to specify an api key for cloudmade maps with the parameter api_key
for the function get_cloudmademap
.
I would like to have the same functionality also for the function get_googlemap
. Please add the argument api_key
also for the function get_googlemap
. I believe the function get_map
should be adjusted accordingly.
When passing a vector of to/from to mapdist that includes repeated pairs of to/from, the returned data frame re-duplicates repeated entries, and returns too many lines.
Here is code that demonstrates the problem.
library(ggmap)
library(dplyr)
# Create data frame with cities for map test, including repeated lines
cities <-c("Paris, France","London,England","Berlin, Germany")
df <- data_frame(from=rep(cities,2)) %>% mutate(to=lead(from,1)) %>% na.omit()
# Limit to the round trip of cities
roundTrip <- df[1:length(cities),]
# Repeat the first leg
tripRepeatedLeg <- df[1:(length(cities)+1),]
# The starting round trip trip gives the same number of results
roundTripDist <- suppressMessages(mapdist(roundTrip$from,roundTrip$to))
nrow(roundTrip)==nrow(roundTripDist)
# Trips with repeated legs return frames with additional rows
tripRepeatedLegDist <- suppressMessages(mapdist(tripRepeatedLeg$from,tripRepeatedLeg$to))
nrow(tripRepeatedLeg)==nrow(tripRepeatedLegDist)
When I use source="stamen" with a zoom=5 (or other zooms at the regional / state / country / continent level), the latitude of the map is not aligned with reality.
I have included an example below. You will see by comparing liberty.map1 and liberty.map2 that the zoom=5 map puts the Statue of Liberty in the Catskill region (significantly north of reality). Comparing liberty.map2 and liberty.map3, you will see that the tick-mark for latitude 35 is at the southern border of Tennessee in the Google map and much further north in Tennessee in the stamen map.
I am using R 3.1.0, ggplot2 1.0.0, and ggmap 2.3.
library(ggmap)
library(ggplot2)
liberty.map1 <- get_map(location = c(lon=-74.0445, lat= 40.68925), source="stamen", maptype="toner", zoom=15)
liberty.map2 <- get_map(location = c(lon=-74.0445, lat= 40.68925), source="stamen", maptype="toner", zoom=5)
liberty.map3 <- get_map(location = c(lon=-74.0445, lat= 40.68925), zoom=5)
ggmap(liberty.map1) + geom_point(x= -74.0445, y= 40.68925, color="red")
ggmap(liberty.map2) + geom_point(x= -74.0445, y= 40.68925, color="red")
ggmap(liberty.map3)
The geocode function returns NAs whenever the letters æ, ø or å appear in the address.
I have tried to build the url manually to check if it is the API that returns an error but both of these work.
https://maps.googleapis.com/maps/api/geocode/json?address=Højdetoften+1,+4500®ion=dk
https://maps.googleapis.com/maps/api/geocode/json?address=H%C3%B8jdetoften+1,+4500®ion=dk
Here's some code that returns both lat/lon and NAs.
library(ggmap)
addr <- c("Bjerget 30, 4500 Denmark", "Topvej 18, 4500 Denmark", "Højdetoften 1, 4500 Denmark",
"Bøsserup Eng 12, 4500 Denmark", "Udlodden 12, 4500 Denmark",
"Møstvej 4, 4500 Denmark")
latlon <- geocode(location = addr, output = "latlon", messaging = FALSE, sensor = FALSE)
head(latlon)
Otherwise a great package! I hope I'm not missing something obvious.
EDIT: Here's the result I get.
head(latlon)
lon lat
1 11.57720 55.95856
2 11.64852 55.93368
3 NA NA
4 NA NA
5 11.60960 55.93532
6 NA NA
EDIT_EDIT: And here's my sessioninfo :)
sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 LC_MONETARY=Danish_Denmark.1252
[4] LC_NUMERIC=C LC_TIME=Danish_Denmark.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggmap_2.3 lubridate_1.3.3 ggplot2_1.0.0 tidyr_0.1 dplyr_0.4.1 magrittr_1.5 mapDK_0.3.0
loaded via a namespace (and not attached):
[1] assertthat_0.1 colorspace_1.2-4 DBI_0.3.1 digest_0.6.4 grid_3.1.2 gtable_0.1.2
[7] labeling_0.2 lazyeval_0.1.10 mapproj_1.2-2 maps_2.3-9 MASS_7.3-35 memoise_0.2.1
[13] munsell_0.4.2 parallel_3.1.2 plyr_1.8.1 png_0.1-7 proto_0.3-10 Rcpp_0.11.2
[19] reshape2_1.4 RgoogleMaps_1.2.0.7 rjson_0.2.15 RJSONIO_1.3-0 scales_0.2.4 stringi_0.3-1
[25] stringr_0.6.2 tools_3.1.2
It seems that the function get_googlemap does not like it when I request a rectangular map size.
I have R 3.0.0 running on Ubuntu 12.04 and ggmap version 2.3. When I run the following code, the map is not what I expect.
map_center <- c(lon=-123.1119, lat=49.2505)
test <- get_googlemap(center=map_center, zoom=3, maptype="satellite", size=c(640,320))
ggmap(test)
When I change the size parameter to any square dimensions, I get a nice map
The site really downplays the ability to build your own maps now, http://maps.cloudmade.com/
qmap('united states', zoom = 4, maptype = 'watercolor')
qmap("new york", zoom=12)
qmap("new york", zoom=13)
qmap("new york", zoom=12.2)
qmap("new york", zoom=12.7)
12.2 and 12.7 produce the same output which is the default zoom=10. Use round
on the zoom argument (and possibly issue a warning that only integers are accepted).
For other map sources it simply fails
qmap("new york", zoom=12.4, source="osm")
qmap("antarctica")
fails and produces the warnings
Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -Inf
On the other side of the earth:
ggmap(get_map("greenland", zoom=4))
works
ggmap(get_map("greenland", zoom=3))
fails.
Please see http://stackoverflow.com/q/11162824/559676 for detailed comments, if the OP has not contacted you yet. Thanks!
The goal is to allow constructions such as
ggplot(data=mydata) +
geom_map(source="stamen", maptype="toner) +
geom_point(aes(x=lon, y=lat))
geom_map()
would figure out the bounding box of the data argument (inherited from the ggplot call in the example above) and draw the appropriate map. I should probably also set coord_map even though that kind of breaks the grammar of graphics convention.
> ### Name: geocode
> ### Title: Geocode
> ### Aliases: geocode geocodeQueryCheck
>
> ### ** Examples
>
> # Types of input
> geocode('Baylor University')
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=Baylor+University&sensor=false
lon lat
1 -97.11844 31.54822
> geocode('1600 Pennsylvania Avenue, Washington DC')
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=1600+Pennsylvania+Avenue,+Washington+DC&sensor=false
lon lat
1 -76.98168 38.87866
> geocode('the white house')
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=the+white+house&sensor=false
lon lat
1 -77.03653 38.89768
> geocode(c('baylor university', 'salvation army waco'))
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=baylor+university&sensor=false
Information from URL : http://maps.googleapis.com/maps/api/geocode/json?address=salvation+army+waco&sensor=false
lon lat
1 -97.11844 31.54822
2 -97.12858 31.54158
>
> # Types of output
> geocode('Baylor University', output = "latlona")
lon lat
1 -97.11844 31.54822
address
1 baylor university, 1311 south 5th street, waco, tx 76706, usa
> geocode('Baylor University', output = "more")
Error in data.frame(long_name = "Baylor University", short_name = "Baylor University", :
arguments imply differing number of rows: 1, 0
Calls: geocode ... as.data.frame -> as.data.frame.list -> eval -> eval -> data.frame
Execution halted
In this example
library("ggmap")
crimes <- subset(crime, offense %in% c("murder", "rape"))
crimes <- crimes[crimes$lat < 30.5,]
qmplot(lon, lat, data=crimes, size=I(5))
Two points are cut out on the right and on the left. The map needs to be a bit larger to accomodate such situations (and it's actually surprising that it works correctly on the top and bottom).
This is different from expand because we don't want blank space around the data, we want more map.
Checking for presence of client & signature works, but when specified, is not added to the geocode request url.
Hi
thx for the great package. I think the "cloudmade" service is down and stamen:terrain does not work any more :(
Best wishes
Christof
The documentation for v 2.2 (http://cran.r-project.org/web/packages/ggmap/ggmap.pdf) states:
zoom
map zoom, an integer from 0 (whole world) to 21 (building), default value 10
(city)
I am using v2.2:
> sessionInfo
ggmap_2.2
However when trying to use zoom = 0
, I get the following error:
Error: zoom must be a whole number between 1 and 21
I get errors with 0-2, with 3 seeming like the minimum value in my attempts with google, Open Street Maps, and/or Stamen. At zoom = 3
, they all seem to successfully download.
Is the documentation in error, or am I doing something wrong? Was trying to get a world map as I thought it would be easier to center around something other than 0 or 180 compared to just using the maps
library.
Thanks for this package! For smaller scale work (not at the world level), I am really excited to use it!
Try this:
bug
lon lat
1 10.56261 48.67790
2 10.70112 48.69171
3 10.54414 48.59922
4 10.59666 48.79024
5 10.62209 48.67063
6 10.45170 48.70223
7 10.62660 48.71989
8 10.68440 48.69027
9 10.53342 48.82974
10 10.43407 48.74760str(bug)
'data.frame': 10 obs. of 2 variables:
$ lon: num 10.6 10.7 10.5 10.6 10.6 ...
$ lat: num 48.7 48.7 48.6 48.8 48.7 ...qmplot(lon, lat, data = bug)
Dots are on a gray background.
The geocode function in ggmap relies on the datasciencetoolkit.org to use the Google Maps API. However, datasciencetoolkit.org is down. Based on creator Pete Warden's post in late September - http://petewarden.com/2015/09/27/openheatmap-and-datasciencetoolkit-under-new-management/ - the site may be down for good.
Since Thursday running geocode() has resulted in errors like this:
Warning messages:
1: In readLines(connect, warn = FALSE) :
unable to connect to 'www.datasciencetoolkit.org' on port 80.
2: In FUN(X[[i]], ...) :
geocoding failed for "0 13TH ST NE, Washington DC".
if accompanied by 500 Internal Server Error with using dsk, try google.
David, ggmap is great!
I've been working with geocode a lot this morning and I have a suggestion: it'd be nice if geocode appended the original input to the data set it returns when it returns a data set. This would make it quicker to add the geocode data back into an existing dataset. For example,
df <- data.frame(place = sample(c("Juneau, AK", "Houston, TX" , "Austin, TX"), 10, replace = TRUE),
value = 1:10, stringsAsFactors = FALSE)
places <- unique(df$place)
place_info <- geocode(places2, output = "more")
place_info$place <- places ## can cut out this step
df <- join(df, place_info, by = "place")
If there's a more obvious workflow that I'm missing, just close this comment and ignore it :)
Hi all
Not sure this is right forum, but I could not find a better.. :)
I installed the newest version of ggmap from CRAN and get the following error.
> R.Version()
$platform
[1] "x86_64-apple-darwin14.0.0"
$arch
[1] "x86_64"
$os
[1] "darwin14.0.0"
$system
[1] "x86_64, darwin14.0.0"
$status
[1] ""
$major
[1] "3"
$minor
[1] "1.2"
$year
[1] "2014"
$month
[1] "10"
$day
[1] "31"
$`svn rev`
[1] "66913"
$language
[1] "R"
$version.string
[1] "R version 3.1.2 (2014-10-31)"
$nickname
[1] "Pumpkin Helmet"
> sunMap <- get_map(location = 'Copenhagen')
Map from URL : http://maps.googleapis.com/maps/api/staticmap?center=Copenhagen&zoom=10&size=640x640&scale=2&maptype=terrain&language=en-EN&sensor=false
Error in readPNG(tmp) : unable to initialize libpng
In addition: Warning message:
In readPNG(tmp) :
libpng warning: Application built with libpng-1.6.16 but running with 1.5.17
I tried deleting the png package and letting ggmap install it as a dependency, but same result. It should be mentioned that I have libpng version 1.6.16 installed via macports.
Any help is greatly appreciated!
Best,
Per
I am trying to grab a map like this:
get_map(location = c(6.815375, 51.217942), zoom = 11, source = "osm")
Following error occures:
Error in download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
can't open URL 'http://maps.googleapis.com/maps/api/staticmap?center=51.217942,6.815375&zoom=11&size=%20640x640&maptype=terrain&sensor=false'
And an additional warning:
W
In download.file(url, destfile = destfile, quiet = !messaging, mode = "wb") :
cannot open: HTTP status was '403 Forbidden'
Why does ggmap query google, although source is set to "osm" ? And why is the status 403 forbidden?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.