2014-05-09 31 views
0

下面的代碼正常工作:ggmap上的ggmap繪製點時/ ggplot錯誤:[參數意味着不同的行數]

library(ggmap) 
mp2 <- ggmap::get_map(location="South America", zoom = 4, source="google") 

ggmap(mp2) + 
    geom_point(aes(c(-60), c(-1)), size=15) # plot one single point on map 

產生這樣的:

code that works

儘管下面由於某些原因,其行爲不如預期:

ggmap(mp2) + 
    geom_point(aes(c(-60, -65, -62), c(-1, -5, -10))) 

givin摹我下面的錯誤:

Error in data.frame(x = c(-60, -65, -62), y = c(-1, -5, -10), PANEL = c(1L, : 
    arguments imply differing number of rows: 3, 4 
+0

'你可以確認ggmap在第3行內部創建的緯度和經度的載體:'print.ggplot(名單(數據=列表(LON = C(-83.5725316875,-27.3225316875, -83.5725316875,-27.3225316875),LAT = C(-34.656848886632,-34.656848886632, 18.9102814177176,18.9102814177176))' – OdeToMyFiddle

+0

嗯我看到......這些都是ggmap的4個角落。 – Dan

+0

您的第一個塊代碼不再工作。你可以測試它並確認它嗎? –

回答

2

這應該使用`回溯()工作

df <- data.frame(lon=c(-60, -65, -62), lat = c(-1, -5, -10)) 
ggmap(mp2) + 
    geom_point(aes(x = lon, y = lat), size = 10, data = df) 
+0

它確實有效。這裏的基本原理是什麼? – Dan

+0

這是我的理解,ggplot期待從data.frames獲取數據,使用長格式的表現更好(更容易)。如果沒有data.frame,ggplot會在內部產生一個錯誤:'stop(「ggplot2不知道如何處理類的數據,class(model),call。= FALSE)'。 –

相關問題