2015-04-20 149 views
5

我是新來的r,並已嘗試了幾個小時繪製一個亞利桑那地圖上的蝴蝶家庭的點。我可能做的完全錯誤或有一些缺少我不知道,任何幫助將不勝感激!新手繪製座標在R與csv文件的地圖

我現在下面的代碼和已經嘗試了許多人:

rio = read.csv("Rioninidae_Cleaned.csv",stringsAsFactors = FALSE) 
arizona <- get_googlemap(center=c(lon=-110.713,lat=31.815), zoom = 3) 
lon <-data.frame(rio$latitude) 
lat <-data.frame(rio$longitude) 
df <- as.data.frame(cbind(lon,lat)) 
df 
arizona <- get_googlemap(center = c(lon = -110.713,lat = 31.815), zoom = 3) 
ggmap(arizona) + 
    geom_point(data = df, aes(x = lon, y = lat), size = 5, shape = 21) + 
    guides(fill = FALSE, alpha = FALSE, size = FALSE) 

我的csv文件可以發現在:https://www.dropbox.com/s/yxj1uvmt9bw8gvn/Rioninidae_Cleaned.csv?dl=0

 genus province   county latitude longitude 
1 Apodemia Arizona   Apache 33.90011 -109.5844 
2 Apodemia Arizona Cochise County 31.46260 -110.2895 
3 Apodemia Arizona Cochise County 31.46260 -110.2895 
4 Apodemia Arizona Santa Cruz 31.50503 -110.6547 
5  Emesis Arizona  Santa Cruz 31.74001 -110.9411 
6  Emesis Arizona  Santa Cruz 31.74001 -110.9411 
7  Emesis Arizona  Santa Cruz 31.38333 -111.0833 
8 Apodemia Arizona  Santa Cruz 31.38333 -111.0833 
9 Calephelis Arizona   Pima 31.76667 -111.5500 

謝謝!

回答

7

我想你可能正在尋找這樣的東西。

library(ggmap) 
library(ggplot2) 

# Get a map 
arizona <- get_map(location = c(lon = -110.713, lat = 31.815), zoom = 6) 

ggmap(arizona) + 
geom_point(data = mydf, aes(x = longitude, y = latitude, fill = genus), size = 3, shape = 21) 

enter image description here

DATA

mydf <- structure(list(genus = structure(c(1L, 1L, 1L, 1L, 3L, 3L, 3L, 
1L, 2L), .Label = c("Apodemia", "Calephelis", "Emesis"), class = "factor"), 
province = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L 
), .Label = "Arizona", class = "factor"), county = structure(c(1L, 
2L, 2L, 5L, 4L, 4L, 4L, 4L, 3L), .Label = c("Apache", "Cochise County", 
"Pima", "Santa Cruz", "Santa Cruz "), class = "factor"), 
latitude = c(33.9001056, 31.4625978, 31.4625978, 31.5050272, 
31.7400056, 31.7400056, 31.38333333, 31.38333333, 31.76666667 
), longitude = c(-109.58444, -110.2895241, -110.2895241, 
-110.65472, -110.94111, -110.94111, -111.0833333, -111.0833333, 
-111.55)), .Names = c("genus", "province", "county", "latitude", 
"longitude"), class = "data.frame", row.names = c(NA, -9L)) 
+0

是的,這也正是它!非常感謝,我從來沒有想過這個結構命令! – poolshark

+0

@poolshark快樂。很高興聽到這是你的後。 :) – jazzurro

+0

謝謝!只是想知道如果我有超過100個家庭座標,我會怎麼做?我將如何改變結構? – poolshark