Hello Laila,

do you possibly mix adehabitat and adehabitatHR? See code below.

Hope this helps,
Johannes


library(adehabitat)
library(adehabitatHR)
library(proj4)

## Original data:

Geo7 <- read.table(textConnection("
     lon latcom
27 30.73 -41.08
30 37.44 -40.66
31 37.59 -40.54
33 46.27 -43.86
35 49.94 -43.25
38 53.52 -40.07"), header=TRUE)



location <- proj4::project(Geo7,list(proj="laea", lat_O=1,lon_0=2, x_0=6,
y_0=7),inverse=FALSE, degrees=TRUE, silent=FALSE)  #### we use Lambert
azimuthal equal-area projection

location1a <- data.frame(location)     #### It's necessary to convert the
list into dataframe
xy= location1a[c("x", "y")]
class(location1a)
coordinates(location1a) <- ~x+y      ###### To convert mapping coordinates
to Spatial points
class(location1a)

################ KERNEL
## Do you load adehabitat or adehabitatHR?

## This fails, because adehabitat::kernelUD requires coordinates as a data
frame
Kernel1 <- adehabitat::kernelUD(location1a, h="href",grid=40,same4all=F,
hlim=c(0.1,1.5),kern=c("bivnorm"),extent=0.5)    ###
## Error in if (ncol(xy) != 2) stop("xy should have 2 columns") :
##  argument is of length zero

## Works
Kernel1 <- adehabitat::kernelUD(data.frame(location),
h="href",grid=40,same4all=F,
hlim=c(0.1,1.5),kern=c("bivnorm"),extent=0.5)    ###


## Works as expected
Kernel1 <- adehabitatHR::kernelUD(location1a, h="href",grid=40,same4all=F,
hlim=c(0.1,1.5),kern=c("bivnorm"),extent=0.5)    ###



On Thu, Jul 25, 2013 at 11:07 PM, laila Aranda Romero <laila_...@hotmail.com
> wrote:

> He everybody,
>
> I'm studying the migration pattern  and wintering distribution of the
> Great shearwater using geolocation data. For this, I want to work out the
> kernel density surfaces using the package adehabitat of R. However, I've
> some problems when I'm trying to run my script.
>
> Original data:
>
> head(Geo7)     lon latcom
> 27 30.73 -41.08
> 30 37.44 -40.6631 37.59 -40.54
> 33 46.27 -43.86
> 35 49.94 -43.25
> 38 53.52 -40.07> class(Geo7)[1] "data.frame"> str(Geo7)'data.frame':  160 
> obs. of  2 variables:
>  $ lon   : num  30.7 37.4 37.6 46.3 49.9 ...
>  $ latcom: num  -41.1 -40.7 -40.5 -43.9 -43.2 ..
>
>
> Script:
> Geo7 <- subset(Geo6b, select=c (lon, latcom)) ########## cambiar latitud y
> longitud de orden
> location<-project(Geo7,list(proj="laea", lat_O=1,lon_0=2, x_0=6,
> y_0=7),inverse=FALSE, degrees=TRUE, silent=FALSE)  #### we use Lambert
> azimuthal equal-area projection
> location1a <- data.frame(location)     #### It's necessary to convert the
> list into dataframe
> xy= location1a[c("x", "y")]
> class(location1a)
> coordinates(location1a) <- ~x+y      ###### To convert mapping coordinates
> to Spatial points
> class(location1a)
>
> ################KERNEL
> Kernel1<-kernelUD(location1a, h="href",grid=40,same4all=F,
> hlim=c(0.1,1.5),kern=c("bivnorm"),extent=0.5)    ###
> image(Kernel1, axes=FALSE, mar=c(0,0,2,0), addcontour=TRUE, addpoints=TRUE)
> kernel2 <-getvolumeUD(Kernel1)
> Kernel3 <- kernel.area(kernel2, id=NULL, h="href", grid=40,
> same4all=FALSE, hlim=c(0.1,1.5), kern="bivnorm", levels=seq(25,95,by=10),
> unin=c("m"), unout=c("m2"), extent=0.5)   ###### same problem I need two
> columns instead of oneele
> Kernel6<-getverticeshr(Kernel1,lev=40)
> image(Kernel1)  ### problemas con la paleta por eso he eliminado
> col=rainbow(4)
> plot(Kernel6, add=TRUE)
> Kernel7 <- getverticeshr(kernel1,lev=90)
> image(Kernel1)
> plot(Kernel6, add=TRUE)
>
> When a run it:
>
> location<-project(Geo7,list(proj="laea", lat_O=1,lon_0=2, x_0=6, 
> y_0=7),inverse=FALSE, degrees=TRUE, silent=FALSE)  #### we use Lambert 
> azimuthal equal-area projection> class(location)[1] "list"> str(location)List 
> of 2
>  $ x: num [1:160] 2533084 3115667 3132780 3682706 3994351 ...
>  $ y: num [1:160] -4593850 -4615167 -4603968 -5069889 -5060989 ...> 
> location1a <- data.frame(location)     #### It's necessary to convert the 
> list into dataframe> xy= location1a[c("x", "y")]> class(location1a)[1] 
> "data.frame"> coordinates(location1a) <- ~x+y      ###### To convert mapping 
> coordinates to Spatial points> class(location1a)[1] "SpatialPoints"
> attr(,"package")
> [1] "sp"
>
>
>
>
>
> Kernel1<-kernelUD(location1a, h="href",grid=40,same4all=F, 
> hlim=c(0.1,1.5),kern=c("bivnorm"),extent=0.5)    ###Error en if (ncol(xy) != 
> 2) stop("xy should have 2 columns") :
>   argumento tiene longitud cero
>
>
>
> I would appreciate a lot if someone can help me to find a solution to this 
> error.
>
>
>
> Laila
>
>
> _______________________________________________
> AniMov mailing list
> AniMov@faunalia.it
> http://lists.faunalia.it/cgi-bin/mailman/listinfo/animov
>
>
_______________________________________________
AniMov mailing list
AniMov@faunalia.it
http://lists.faunalia.it/cgi-bin/mailman/listinfo/animov

Reply via email to