How to have widescreen resolution with ggmap

亡梦爱人 提交于 2019-12-18 13:35:36

问题


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.


回答1:


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)



回答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...



来源:https://stackoverflow.com/questions/15400644/how-to-have-widescreen-resolution-with-ggmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!