-1

I just got my location data from Falkland Island, and i tried to map the locations that I got from the tags, however, when i run this code r stop working.

I have a data frame for 30 penguins, with different amount of location each, thus, the table looks like this: ID: penguin ID, V3 is longitud, V4 is latitude

This is the code that i tried:

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

plot(gentoo$V3~gentoo$V4,ylab="Latitude",xlab="Longitude",
     col=gentoo$V1,aspect="iso")
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205
  • 2
    We typically ask for reproducible questions, i.e. we need data that can easily be replicated on our computers, so an image of the table is not usually helpful. However, from your image I see that the first line is not data but column labels. Try removing the first line or use them as column names using `header=T` in `read.csv()`. – K.Daisey Feb 20 '17 at 20:17
  • Thank you very much, is the first time I write here so I will improve my question next time – Daniel González Feb 22 '17 at 00:34

2 Answers2

0

I could finally plot my data, with the bathymetry of the area:

#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

Just use 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

iskandarblue
  • 7,208
  • 15
  • 60
  • 130
  • Thank you very much for your help! added to the matrix all the data from the tags and when i try to run the ggmap i have the next message-> # Error: GeomRasterAnn was built with an incompatible version of ggproto. Please reinstall the package that provides this extension I am still trying to fix it – Daniel González Feb 22 '17 at 01:04
  • I can´t still make the plot, this is my script >gentoo<-read.csv("Regularised Gentoos.csv", header=T) mapImageData <- get_map(location = "Falkland Islands",source = "google", zoom = 9) ggmap(mapImageData, extent = "panel", ylab = "Latitude", xlab = "Longitude", legend = "right") + geom_point(aes(x = lat, # path outline y = lon), data = gentoo, colour = "black") + labs(x = "Longitude", y = "Latitude") + ggtitle("Penguin Sightings") + theme(plot.title = element_text(lineheight=.8, face="bold")) – Daniel González Mar 06 '17 at 11:36
  • And I always have the same message -> Error: GeomRasterAnn was built with an incompatible version of ggproto. Please reinstall the package that provides this extension. I tried many times to reinstall but can´t make it work, or even see the map from the Falkland Islands – Daniel González Mar 06 '17 at 11:39
  • This is a known issue, maybe try some of the following solutions here: http://stackoverflow.com/questions/40642850/ggmap-error-geomrasterann-was-built-with-an-incompatible-version-of-ggproto – iskandarblue Mar 06 '17 at 15:32