2017-02-20 5 views
-1

Ich habe gerade meine Standortdaten von Falkland Island, und ich habe versucht, die Standorte, die ich von den Tags bekommen habe, aber wenn ich diesen Code r r funktionieren nicht mehr funktionieren.Mapping Ort in R von einem Datenrahmen

ich einen Datenrahmen für jeweils 30 Pinguine, mit unterschiedlichen Menge an Ort haben, so sieht die Tabelle wie folgt aus: ID: penguin ID, V3 is longitud, V4 is latitude

Dies ist der Code, den ich versucht:

gentoo<-read.csv("Regularised Gentoos.csv", header=F) 

plot(gentoo$V3~gentoo$V4,ylab="Latitude",xlab="Longitude", 
    col=gentoo$V1,aspect="iso") 
+2

Wir in der Regel für eine reproduzierbare Fragen stellen, dh wir Daten benötigen, die auf unseren Computern leicht repliziert werden können, so dass ein Bild der Tabelle ist normalerweise nicht hilfreich. Aus Ihrem Bild sehe ich jedoch, dass die erste Zeile keine Daten, sondern Spaltenbeschriftungen sind. Versuchen Sie, die erste Zeile zu entfernen oder verwenden Sie sie als Spaltennamen mit 'header = T' in' read.csv() '. –

+0

Vielen Dank, ist das erste Mal, dass ich hier schreibe, damit ich meine Frage beim nächsten Mal verbessern werde –

Antwort

0

konnte ich endlich meine Daten plotten, mit dem bathymetry der näheren Umgebung:

#Load in libraries 
library(sp) 
library(rgdal) 
library(rgeos) 
library(maptools) 
library(raster) 
library(ggplot2) 
library(scales) 
library(gridExtra) 
library(adehabitatHR) 
library(maptools) 
library(marmap) 
library(maptools) 

#Load in shapefile from NaturalEarthData.com 
#Load in shapefile from NaturalEarthData.com 
world_shp = rgdal::readOGR("/Users/danielgonzalez/Desktop/Thesis/DATA EMAILS/natural_earth_vector/10m_physical",layer = "ne_10m_land") 
world_shp 

#Load in .csv file 
gentoo = read.csv("/Users/danielgonzalez/Desktop/Thesis/DATA EMAILS/Regularised Gentoos.csv") 
#Create a spatial points dataframe 
locs = sp::SpatialPointsDataFrame(coords = cbind(gentoo$lon, gentoo$lat), data = gentoo, proj4string=CRS("+proj=longlat +datum=WGS84")) 
locs 

#Extra... 
#To download bathymetry data FALKLAND ISLAND MAP 
#ETOPO1 database hosted on the NOAA website 
library(marmap) 
getNOAA.bathy(lon1=-70, lon2=-52, lat1=-57, lat2=-46, resolution = 1) -> bathy 
plot(bathy, image=TRUE, deep=-6000, shallow=0, step=1000) 
bat = as.raster(bathy) 
#Write 
writeRaster(bat, filename = "~/bathy.asc") 
#Read 
bat = readGDAL("~/bathy.asc") 


#Load in Raster data 
#This is 1 min resolution bathymetry from ETOPO1 database hosted on the NOAA website 

bathy = raster::raster("/Users/danielgonzalez/bathy.asc") 
#Define projection of bathymetry data 
raster::projection(bathy) = CRS("+proj=longlat +datum=WGS84") 

#Create a spatialpoints object of the colony 
Colonsay = sp::SpatialPoints(coords = cbind(-6.25, 56.07), proj4string = CRS("+proj=longlat +datum=WGS84")) 

#Quick plot 

#png("gentoo distribution.png",width=8,height=6,units="in",res=1800) 
image(bathy,ylab="Latitude",xlab="Longitud") 
lines(world_shp) 
points(gentoo$lon,gentoo$lat, pch = 19, cex = 0.3,col=gentoo$id) 
#dev.off() 
-1

Nur verwenden ggmap

library(ggmap) 
library(ggplot2) 

#lat/lon data 
df <- as.data.frame(matrix(nrow = 3, ncol =3)) 

colnames(df) <- c("lat", "lon", "id") 

df$lon <- c(-51.2798, -51.3558, -51.9) 
df$lat <- c(-59.6387, -59.7533, -59.4) 
df$id <- c("1", "2", "3") 

df 
     lat  lon id 
1 -59.6387 -51.2798 1 
2 -59.7533 -51.3558 2 
3 -59.4000 -51.9000 3 

#get the map 
library(ggmap) 
mapImageData <- get_map(location = "Falkland Islands", 
         source = "google", zoom = 9) 

#plot the points 
ggmap(mapImageData, 
     extent = "panel", 
     ylab = "Latitude", 
     xlab = "Longitude", 
     legend = "right") + 
    geom_point(aes(x = lat, # path outline 
       y = lon), 
      data = df, 
      colour = "black") + 
labs(x = "Longitude", 
    y = "Latitude") + ggtitle("Penguin Sightings") + 
    theme(plot.title = element_text(lineheight=.8, face="bold")) 

enter image description here

+0

Warum der Downvote? –

+0

Vielen Dank für Ihre Hilfe! hinzugefügt, um die Matrix alle Daten von den Tags und wenn ich versuche, die ggmap ich habe die nächste Nachricht-> # Fehler: GeomRasterAnn wurde mit einer inkompatiblen Version von ggproto gebaut. Bitte installieren Sie das Paket, das diese Erweiterung bietet erneut Ich versuche immer noch, es zu beheben –

+0

Ich kann noch nicht die Handlung machen, das ist mein Skript > Gentoo <-read.csv ("Regularisierte Gentoos.csv", Header = T) mapImageData <- get_map (location = "Falkland-Inseln", source = "google", zoom = 9) ggmap (mapImageData, Umfang = "Panel", YlaB = "Latitude", xlab = "Longitude", Legende = "right") + geom_point (aes (x = lat, # Pfad outline y = lon), data = gentoo, color = "black") + Labs (x = "geographische Länge", y = "Latitude") + ggtitle ("Pinguin-Sichtungen") + theme (plot.title = element_text (lineheight = .8, face = "fett")) –

Verwandte Themen