[R-sig-Geo] ploting Kernel results (adhabitatHR) with ggplot2
Roman Luštrik
roman.lustrik at gmail.com
Mon Feb 22 10:58:46 CET 2016
Hi,
can you provide a reproducible example?
Cheers,
Roman
On Mon, Feb 22, 2016 at 10:48 AM, Diego Pavon <diego.pavonjordan at gmail.com>
wrote:
> Dear All
>
> I am new user of R as a GIS software and I would like to ask you about how
> to plot the results of a Kernel estimation with ggplot2 (amazing package!).
>
> So, I have a number of locations (latitude and longitude coordinates) and I
> wanted to do a kernel 50% of those locations. I used the adhabitatHR
> package to do so. I read in the help file of ggplot that it is required to
> have the input as a data.frame. So, after running the kernelUD command I
> get an object of class estUD with all the parameters of the kernel
> analysis. However this can't be understood by ggplot2.
>
> summary(AccgenK.kernel)Object of class estUD
> Coordinates:
> min max
> Var2 163706.1 8481877
> Var1 -1286076.5 7378685
> Is projected: TRUE
> proj4string :
> [+init=epsg:3035 +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000
> +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m
> +no_defs]
> Number of points: 9600
> Grid attributes:
> cellcentre.offset cellsize cells.dim
> Var2 207029.9 86647.61 96
> Var1 -1242752.7 86647.61 100
> Data attributes:
> ud
> Min. :0.000e+00
> 1st Qu.:0.000e+00
> Median :0.000e+00
> Mean :1.387e-14
> 3rd Qu.:3.890e-17
> Max. :5.162e-13
>
>
>
> I can transform this object to a data.frame:
>
> kernel.df<-as.data.frame(AccgenK.kernel)
>
> And I get this:
>
> str(kernel.df)'data.frame': 9600 obs. of 3 variables:
> $ ud : num 0 0 0 0 0 0 0 0 0 0 ...
> $ Var2: num 207030 207030 207030 207030 207030 ...
> $ Var1: num 7335361 7248713 7162065 7075418 6988770 ...>
> head(kernel.df) ud Var2 Var1
> 1 0 207029.9 7335361
> 2 0 207029.9 7248713
> 3 0 207029.9 7162065
> 4 0 207029.9 7075418
> 5 0 207029.9 6988770
> 6 0 207029.9 6902123
>
>
> But when I try to plot this with ggplot2... nothing happens.
>
> p <- ggmap(glgmap)
> p <- p + geom_point(aes(x=X, y=Y, col = Killed, shape = Killed), alpha=
> 0.5,
> data = Accgen,
> size = 4)
> p <- p + xlab("Longitude") + ylab("Latitude")
> p <- p + theme(text = element_text(size = 15))
> p <- p + scale_color_manual(values=c('royalblue', 'firebrick')) +
> labs(title = substitute(paste(italic('Turdus merula'))))
> p <- p + geom_polygon(data = kernel.df, aes(x = Var1, y = Var2))
> p
>
>
> I have also tried to create a SpatialPolygondataFrame:
>
> ver75_AccgenK <- getverticeshr(AccgenK.kernel, 75, unout= "km2")
>
> But then, this data.frame has only the area of the polygon...
>
> > as.data.frame(ver75_AccgenK) id area
> homerange homerange 2914920
>
>
> I can plot this using only the plot command, but I would like to use
> ggplot and all the features that it provides.
>
> So, does anyone know how can I plot this kernel polygon with ggplot? I
> have found this earlier post:
>
> https://stat.ethz.ch/pipermail/r-sig-geo/2010-April/008143.html
>
>
> but I fail to understand how he did it...
>
> Thank you very much for your time and help.
>
> Best
>
> Diego
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> *Diego Pavón Jordán*
>
> *Finnish Museum of Natural History*
> *PO BOX 17 *
>
> *Helsinki. Finland*
>
>
>
> *0445061210
> https://tuhat.halvi.helsinki.fi/portal/en/persons/diego-pavon-jordan%288d5db37c-eddd-4fca-92cd-9c9956a42b4a%29.html
> <
> https://tuhat.halvi.helsinki.fi/portal/en/persons/diego-pavon-jordan%288d5db37c-eddd-4fca-92cd-9c9956a42b4a%29.html
> >
> http://www.linkedin.com/profile/view?id=170617924&trk=nav_responsive_tab_profile
> <
> http://www.linkedin.com/profile/view?id=170617924&trk=nav_responsive_tab_profile
> >https://helsinki.academia.edu/DiegoPavon
> <https://helsinki.academia.edu/DiegoPavon>*
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
In God we trust, all others bring data.
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list