[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
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


-- 
*Diego Pavón Jordán*

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

*Helsinki. Finland*



*0445061210https://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]]



More information about the R-sig-Geo mailing list