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