Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove the margins from a ggmap

Tags:

margin

r

map

ggmap

I was trying to plot a map using ggmap package without any margin, axis, labels, etc. I was able to remove the labels, and axis but have no idea have to remove the margin here. Any help will be appreciated..!

library("ggmap")
amap <- get_map(location = c(lon = -95.3632715, lat = 29.7632836), maptype = c("terrain"))
basemap <- ggmap(amap)
plot(basemap)
like image 914
jinlong Avatar asked Dec 06 '13 03:12

jinlong


3 Answers

Try extent = 'device'. See ?ggmap::ggmap for other options.

library("ggmap")
amap <- get_map(location = c(lon = -95.3632715, lat = 29.7632836), maptype = c("terrain"))
basemap <- ggmap(amap, extent = "device")
basemap
like image 117
Sandy Muspratt Avatar answered Sep 20 '22 16:09

Sandy Muspratt


All previous solutions do not answer the question exactly and still leave some white-space.

I ended up with:

ggmap(yourmap) +
  theme(axis.line = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        plot.margin = unit(c(0, 0, -1, -1), 'lines')) +
  xlab('') +
  ylab('')

Before:

Before:

After:

After

like image 20
MS Berends Avatar answered Sep 20 '22 16:09

MS Berends


library("ggmap")
amap <- get_map(location = c(lon = -95.3632715, lat = 29.7632836), 
    maptype = c("terrain"))
basemap <- ggmap(amap) + 
theme(axis.line = element_line(color = NA)) + 
xlab("") + ylab("")
basemap 
like image 32
Maiasaura Avatar answered Sep 20 '22 16:09

Maiasaura