2015-02-05 84 views
4

我在R中使用ggmap庫我試圖用它下載一個矩形地圖,但我知道它會給我一個方形。我只需要返回的方塊的邊界框。從ggmap對象中獲取邊界框

library(ggmap) 
map <- get_map(c(-65.7,-3.1,-64.4,-2.3),maptype="satellite",filename="map.png") 
str(map) 

chr [1:1280, 1:1280] "#294829" "#294829" "#2D512D" "#264425" ... 
- attr(*, "class")= chr [1:2] "ggmap" "raster" 
- attr(*, "bb")='data.frame': 1 obs. of 4 variables: 
    ..$ ll.lat: num -3.14 
    ..$ ll.lon: num -65.5 
    ..$ ur.lat: num -2.26 
    ..$ ur.lon: num -64.6 

對象地圖有兩個類 「ggmap」 和 「光柵」。我不能在其中使用@或$。那麼我怎樣才能從「bb」子對象訪問ll.lat和其他屬性?

回答

8

你可以這樣做:

> attr(map, "bb") 
    ll.lat ll.lon ur.lat ur.lon 
1 -3.139567 -65.48877 -2.261646 -64.60986 
+0

呵呵呵那麼明顯當你意識到這一點...... – Rodrigo 2015-02-05 19:38:34

+1

也許。在看到大多數答案之後,我通常會這樣認爲! :)很高興它幫助。 – lawyeR 2015-02-05 20:01:55

+0

我在'qmap'中找不到這個對象;我是不是該?我看到'map $ data'中的框可能是... – MichaelChirico 2016-10-30 21:52:49