[R-sig-Geo] Plotting Kernel results with ggplot2

Diego Pavon diego.pavonjordan at gmail.com
Mon Feb 29 08:34:02 CET 2016

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

# Transform SpatialPoints into a data.frame to be used in ggplot2
xy.df <- as.data.frame(xy)

# 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))

# This makes the kernels
p2 <- p + stat_density_2d(data = xy.df, aes(x=x, y=y), col = 'red', alpha =

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.



*Diego Pavón Jordán*

*Finnish Museum of Natural History*
*PO BOX 17 *

*Helsinki. Finland*


	[[alternative HTML version deleted]]

More information about the R-sig-Geo mailing list