Hello list
I am trying to do a Kernel analysis of bird ring recoveries and I would
like to plot the kernel contour in ggplot. I have found that the command
'stat_density_2d()' can do this kernels. However, when I plot it, it draws
all the kernels from 10%... 90%. See example below:
# Simulate data
xy <- data.frame(x = runif(30), y = runif(30))
coordinates(xy) <- ~ x + y
plot(xy)
class(xy)
# Transform SpatialPoints into a data.frame to be used in ggplot2
xy.df <- as.data.frame(xy)
head(xy.df)
str(xy.df)
# Make the plot
p <- ggplot(data=xy.df, aes(background="white"))
p <- p + geom_point(aes(x=x, y=y),
data = xy.df,
size = 4)
p <- p + xlab("X") + ylab("Y")
p <- p + theme(text = element_text(size = 15))
p
# This makes the kernels
p2 <- p + stat_density_2d(data = xy.df, aes(x=x, y=y), col = 'red', alpha =
0.6)
p2
However, I am only interested in drawing the lines for the kernel 50% and
75% and not all of them.
Does anyone has an idea how to select only those lines (in my case 50 and
75%) to be plotted and omit the rest?
Thank you very much in advance for you time and help.
Best
Diego