R ggmap: Why can I create rectangular maps using the filename attribute, but not use them in a plot?
Asked Answered
S

1

8

I would like to create a world map in R. I'm somewhat familiar with ggmap, so I tried something like this:

ggmap(get_googlemap(center=c(83,25),
                    zoom=1, scale=4, filename="world", size=c(640,300)))

It does work fine as far as the world.png is concerned.

The world.png output

I was actually quite happy to have found a workaround for ggmap's "can't show anything above 80° latitude" issue, due to which it's more or less impossible to create maps of the whole world.

However, in R itself, that is in the plots, the map looks not at all the way it's supposed to: Failed R map plot

This only happens when the map is rectangular (when the size attribute is set accordingly), and not square (as would be the default).

Why's that? Is there any chance that this issue will be resolved in the future? And what's the quickest way from here to a proper world map?

Strake answered 17/10, 2013 at 22:18 Comment(4)
Why not just save the .png then load it as a background image in ggplot?Haemin
Would you mind giving me a hint as to how that would work? I know that it's possible to load a background image in ggplot, but I haven't been able to find a working solution in which the lon/lat ticks are aligned properly.Strake
From ?ggmap, "maps of the whole world currently not supported".Illdisposed
@AndyClifton: Sorry if I wasn't clear enough: I'm aware of that. The main reason I asked the question was that I'm trying to find a workaround for this problem.Strake
G
3

Use a scale limit.

Normal map

ggmap(get_map(location=c(28.978359,41.008240), zoom=13, scale="auto"))

Square Istanbul

Rectangular (cropped) map

ggmap(get_map(location=c(28.978359,41.008240), zoom=13, scale="auto")) +
    scale_x_continuous(limits = c(28.925,29.025), expand = c(0, 0)) +
    scale_y_continuous(limits = c(40.99,41.03), expand = c(0, 0))

Rectangular Istanbul

Glassware answered 2/10, 2018 at 22:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.