-1

I am trying to put the name from the individuals of my research in a polygons home-range plot, but after many attempts I still can not achieve it.

Here and example of my data: X and Y are coordinates and id are individuals

X   Y   id          
29  29  4           
44  28  7           
57  57  5           
60  81  11          
32  41  4           
43  29  7           
57  57  5           
46  83  11          
32  41  4           
43  29  7           
57  56  5           
60  82  11          
35  40  4           
43  28  7           
62  55  5           
54  73  11          
27  40  4           
43  28  7           
61  54  5

First, i calculated the home-range of my data with MPC cp <- mcp((data)[,1],percent=95, unin = c("m"), unout = c("m2"))

And the plot it plot(cp, axes=TRUE, border = rainbow(12))

But i don´t kown which polygons correspond to each individual, and if possible i need to include the id of my individuals inside each polygon

Any help would be appreciated!!

Thanks

Juan

1 Answers1

1

Here is an example using the example data from the adehabitatHR package, since you not really providing a reproducible example.

library(adehabitatHR)
data("puechabonsp")

cp <- mcp(puechabonsp$relocs[, 1], percent=95, unin = c("m"), unout = c("m2"))

One way would be to use ggplot2 and sf:

library(sf)
library(tidyverse)

st_as_sf(cp) %>% ggplot(., aes(fill = id)) + geom_sf(alpha = 0.5) +
  scale_fill_discrete(name = "Animal id")

enter image description here

johannes
  • 14,043
  • 5
  • 40
  • 51
  • Manny thanks for your help johannes. I am trying to run the script that you show me (with "puechabonsp" data) but i have next error with the last part of the script "Error in geom_sf(alpha = 0.5) : could not find function "geom_sf" ". I am going to edit my question and providing a reproducible example. Thanks again. – juanentuculandia May 24 '18 at 19:49
  • you need the development version of `ggplot2`, see here: https://github.com/tidyverse/ggplot2 – johannes May 24 '18 at 20:19
  • Ok, i understand , but i have some problems to update ggplot2, i have the 2.2.1 version . do i need the 2.2.1.9000 version? Sorry for these basic things, i am new with R – juanentuculandia May 24 '18 at 21:27
  • Manny Thanks, Juan – juanentuculandia May 24 '18 at 21:28