Reputation: 103
I’m trying to plot a map of Europe with every country filled in a colour according to a certain numeric value – I thought this should be no problem with shapefiles (that I got here http://www.naturalearthdata.com/downloads/10m-cultural-vectors/) and ggmap. However it only works for a very large map but I am not able to properly zoom in.
I tried to do so by setting xlim()
and ylim()
, but since thereby I was cutting off shapes at the edges, R connected points that were not supposed to be connected. For ggplot I could solve this issue by using coord_fixed(xlim, ylim)
instead, but when applying the same to my ggmap-plot the country shapes and the map would not fit onto each other anymore.
Here is my code that I used for the plot:
my.map <- get_map(location = "europe", source = "google", maptype = "satellite", zoom = 3)
ggmap(my.map) +
geom_polygon(aes(x = long, y = lat, group = group), fill = eu$value, size = .2, color = 'green', data = eu, alpha = 0.5) +
coord_fixed(xlim = c(0, 35), ylim = c(35, 65), ratio = 1.6)
Does anybody know how I can solve this problem?
(I know it works with ggplot but I'd really like to use ggmap.)
Thank you!
Upvotes: 1
Views: 2056
Reputation: 6333
Use coord_map()
instead of coord_fixed()
:
my.map <- get_map(location = "europe", source = "google", maptype = "satellite", zoom = 3)
ggmap(my.map)+
geom_polygon(aes(x=long, y = lat, group = group), fill='white', size=.2, color='green', data=eu, alpha=0.5)+
coord_map(xlim=c(0, 35), ylim=c(35, 65))
Upvotes: 2