How to have widescreen resolution with ggmap
Asked Answered
D

2

4

I have a data like this:

YEAR-STORM-DATETIME-NORTH-WEST-PRESSURE-WIND-SPEED-TRACKDATE
2011-arlene-6/28/2011 6:00-19.9-92.8-1007-30-NA-6/28/2011
2011-arlene-6/28/2011 12:00-20.3-93.1-1006-35-4-6/28/2011
2011-arlene-6/28/2011 18:00-20.7-93.5-1006-40-5-6/28/2011
so on..

I am new to R and I am plotting a density-plot over ggmap. I am also using shiny R to display them in website. The problem is the output are all non-widescreen (squared) maps. I want to have a rectangular map, like google maps provided by Openlayers or KML. My code is :

library(ggplot2)
library(ggmap)

mydata <- read.csv("C:/R Data/Analytics/dMetrics.csv")
slice_year <- mydata[mydata$YEAR=='2009',]
map <- get_map(c(lon = -55.3632715, lat = 31.7632836), zoom = 3,
               source = 'google', maptype = c("terrain"), messaging = FALSE,
               color = 'color')

world <- ggmap(map) #extent = 'device'
world <- world + 
         stat_density2d(data = slice_year,
                        aes(x = WEST, y = NORTH, fill = ..level.., alpha = ..level..),
                        show_guide = FALSE, geom = "polygon", na.rm = TRUE) + 
         scale_fill_gradient(name = "Density", low = "maroon", high = "yellow", 
                             guide = 'colorbar')
world

Please guide me through to create a widescreen resolution map, possibly a high resolution.

Dissociable answered 14/3, 2013 at 3:25 Comment(0)
P
3

To save the image as widescreen, add this to the end: ggsave(file="map.pdf", width=8, height=4.5)

To open a widescreen window, add this before calling world: windows(800,450)

Edit

It looks like ggmap just doesn't support non-sqaure aspect ratios.

The documentation claims that a bounding box can be passed into the location property, but it appears to just ignore it.

scale <- 5
ratio <- 16/9
size <- c(ratio, 1) * scale
latlongCenter <- c(0, 45)
latlongBox <- c(latlongCenter - size/2, latlongCenter + size/2)

map <- get_map(location = latlongBox)
ggmap(map)
Phung answered 14/3, 2013 at 6:2 Comment(3)
Thanks for the idea. I tried that but still the maps are saved as 4:3 aspect ratio and white spaces around them to fit the resolution. Can we have any cropping mechanism or anything similar to make it true widescreen resolution (16:9) to make it nicely fit under webpage?Dissociable
Updated response. It doesn't appear to support it.Phung
Yeah, I tried providing bounding box instead, and still it didn't solve my problem.Dissociable
A
2

One solution would be to produce a bigger map, and then crop the piece you don't need.

But I'm still trying to figure how to produce a big, high-resolution map (the map I'm getting is 1280x1280 - that's enough for most needs, but not to print a big map). I think there's no function for that, or bots could occupy all of Google's bandwidth. A simpler solution is to get many square maps and assemble them together, but then you'll have the Google logo in all of them.

I think the only way to do that is to produce the small square maps and cut the bottom, where the logo and copyright information are. To add their logo again in the borders of the final map (cutting them differently) would give even more work...

Alphonse answered 5/2, 2015 at 15:7 Comment(3)
Now that everyone is forced to aquire an API key from the Google side, once you get one (for free still unless you actually generate in the order of thousands queries a day ... ) this allows to use the previously 'only Premium' resolution of 2560x2560 ..... since now you can use scale factor=4 (640x4=2560), Still, once I print my generated map, it looks not very high quality ..Orthopter
@Orthopter Last time I tried to automatize maps download with a Google API key, I ended up with Microsoft's Bing Maps... When did you get your API key? Can you automate map download with it (in R, for instance)?Alphonse
I see no obstacle in automazing the download/generation of maps via ggmap in R through the now mandatory use of an API key on google side. Certainly the mandatory registration on an API key through a credit card is annoying but they clearly state that up to 10,000 downloads a month of static maps (i.e) is for free. I've been using it for very sparse downloadsOrthopter

© 2022 - 2024 — McMap. All rights reserved.