2016-05-16 13 views
1

Ich versuche eine Karte zu erstellen, die einige Studienseiten in drei Staaten zeigt. Ich möchte die schwarzen Grenzen, die durch die Karte gehen, loswerden. Wie unten:ggmap border line Problem

Map with plotted Study sites. Black state borders cutting through map

lon <- c(-89.105917,-89.377778,-86.700278,-86.677361,-87.338083,-87.340444) 
lat <- c(37.358694, 37.215278,38.460528,38.448389,37.594583,37.5945) 
#crop 
lon1 <- c(-86.6214142,-87.3423767,-87.6656265,-87.1565475,-87.8155823,-87.3194199,-87.3565598) 
lat1 <- c(38.484581,37.7038918,37.7400513,38.0794983,37.6372185,37.4466667,37.3590546) 
#CRP 
lon2 <-c(-88.4263,-87.4707718,-86.435585,-87.9516907,-89.2439117,-88.3630524,-89.0109711) 
lat2 <- c(37.3582993,37.5196114,37.5220261,37.4958801,37.3413811,37.2275009,37.3633308) 
#Forest 
lon3 <-c(-86.608551,-87.3794403,-88.9937515,-86.7436066,-86.7483826) 
lat3 <- c(38.2506294,36.9505539,37.4111404,38.1277695,37.1684914) 
#Pasture 
lon4 <-c(-86.6036377,-86.2461395,-86.9746704,-87.4977493,-88.9970474,-86.2609634,-86.6067734,-86.9820709) 
lat4 <- c(37.0606689,37.8114433,37.5391922,37.8073006,37.4703789,37.3089409,38.1600189,37.6018295) 

df <- as.data.frame(cbind(lon,lat)) 
df1 <- as.data.frame(cbind(lon1,lat1)) 
df2 <- as.data.frame(cbind(lon2,lat2)) 
df3 <- as.data.frame(cbind(lon3,lat3)) 
df4 <- as.data.frame(cbind(lon4,lat4)) 


pdf("/Users/tribaker/Desktop/Thesis/RaCA/RaCASites.pdf") 
al1 = get_map(location = c("posey county,indiana"), 
       zoom = 8, maptype = 'satellite') 
mdat <- map_data('state',Fill=TRUE) 
ggmap(al1) + 
    geom_path(data=mdat,aes(x=long,y=lat, regions=c('"Kentucky","Illinois","Indiana"')),colour="black",alpha=1)+ 
    borders("county", colour="grey60", alpha=.5)+ 
    borders("state", colour="black", alpha=.8)+ 
    geom_point(data = df, aes(x = lon, y = lat,colour = "Study Site", alpha = 0.8), size = 8, shape = 15) + 
    geom_point(data = df1, aes(x = lon1, y = lat1,colour = "Crop",fill=TRUE, alpha = 0.8), size = 8, shape = 16) + 
    geom_point(data = df2, aes(x = lon2, y = lat2,colour = "CRP", fill = TRUE ,alpha = 0.8), size = 8, shape = 16) + 
    geom_point(data = df3, aes(x = lon3, y = lat3, colour = "Forest",fill = TRUE,alpha = 0.8), size = 8, shape =16) + 
    geom_point(data = df4, aes(x = lon4, y = lat4,colour = "Pasture",fill = TRUE,alpha = 0.8), size = 8, shape = 16) + 
    guides(fill=FALSE, alpha=FALSE, size=FALSE) 
    geom_text(aes(label = state), data = mdat, size = 2, angle = 45) 

Dank im Voraus

+0

Sie müssen möglicherweise einen benutzerdefinierten Stil auf der Basislayerzuordnung vornehmen. Google und ggmap machen es ziemlich schmerzlos. Ich habe hier ein Tutorial geschrieben ... http://www.r-bloggers.com/creating-styled-google-maps-in-ggmap/ – cory

+0

Es sieht so aus, als ob du diese Zeilen selbst zeichnest ... und sie tun es nicht komm nicht von Google. Haben Sie versucht, Ränder zu entfernen ("state", color = "black", alpha = .8) + '? – cory

+0

Ja, kann sie entfernen, aber ich möchte sie haben, um die Grenzen der Staaten zu zeigen – tribaker

Antwort

1

konnte ich die borders Funktion nicht korrekt funktioniert, aber man kann es nur manuell tun ...

Neues Datenrahmen mit den County-Daten und zeichnen Sie die Grenzen selbst ...

lon <- c(-89.105917,-89.377778,-86.700278,-86.677361,-87.338083,-87.340444) 
lat <- c(37.358694, 37.215278,38.460528,38.448389,37.594583,37.5945) 
#crop 
lon1 <- c(-86.6214142,-87.3423767,-87.6656265,-87.1565475,-87.8155823,-87.3194199,-87.3565598) 
lat1 <- c(38.484581,37.7038918,37.7400513,38.0794983,37.6372185,37.4466667,37.3590546) 
#CRP 
lon2 <-c(-88.4263,-87.4707718,-86.435585,-87.9516907,-89.2439117,-88.3630524,-89.0109711) 
lat2 <- c(37.3582993,37.5196114,37.5220261,37.4958801,37.3413811,37.2275009,37.3633308) 
#Forest 
lon3 <-c(-86.608551,-87.3794403,-88.9937515,-86.7436066,-86.7483826) 
lat3 <- c(38.2506294,36.9505539,37.4111404,38.1277695,37.1684914) 
#Pasture 
lon4 <-c(-86.6036377,-86.2461395,-86.9746704,-87.4977493,-88.9970474,-86.2609634,-86.6067734,-86.9820709) 
lat4 <- c(37.0606689,37.8114433,37.5391922,37.8073006,37.4703789,37.3089409,38.1600189,37.6018295) 

df <- as.data.frame(cbind(lon,lat)) 
df1 <- as.data.frame(cbind(lon1,lat1)) 
df2 <- as.data.frame(cbind(lon2,lat2)) 
df3 <- as.data.frame(cbind(lon3,lat3)) 
df4 <- as.data.frame(cbind(lon4,lat4))  

al1 = get_map(location = c("posey county,indiana"), 
       zoom = 8, maptype = 'satellite') 
mdat <- map_data('state', regions=c("Kentucky","Illinois","Indiana")) 
mdat2 <- map_data('county', regions=c("Kentucky","Illinois","Indiana")) 

ggmap(al1) + 
    geom_path(data=mdat2,aes(x=long,y=lat,group=group), colour="grey60", alpha=.5)+ 
    geom_path(data=mdat,aes(x=long,y=lat,group=group), colour="black", alpha=.8)+ 
    geom_point(data = df, aes(x = lon, y = lat,colour = "Study Site", alpha = 0.8), size = 8, shape = 15) + 
    geom_point(data = df1, aes(x = lon1, y = lat1,colour = "Crop",fill=TRUE, alpha = 0.8), size = 8, shape = 16) + 
    geom_point(data = df2, aes(x = lon2, y = lat2,colour = "CRP", fill = TRUE ,alpha = 0.8), size = 8, shape = 16) + 
    geom_point(data = df3, aes(x = lon3, y = lat3, colour = "Forest",fill = TRUE,alpha = 0.8), size = 8, shape =16) + 
    geom_point(data = df4, aes(x = lon4, y = lat4,colour = "Pasture",fill = TRUE,alpha = 0.8), size = 8, shape = 16) + 
    guides(fill=FALSE, alpha=FALSE, size=FALSE) 
    geom_text(aes(label = state), data = mdat, size = 2, angle = 45) 

plot

+0

Schön, kann nicht glauben, dass ich nicht daran gedacht habe! Danke!!!! – tribaker