Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Overview
< !-- /#table-of-contents -->Introduction
Lately, I was plotting a lot of spatial statistic functions, comparing them and trying to make a sense out of them.
To facilitate the procedure I wrote the following function to create a plot for the spatstat class ‘fv’, combined with ‘Quantum Plots’ from:
Esser, D. S., Leveau, J. H. J., Meyer, K. M., & Wiegand, K. (2014). Spatial scales of interactions among bacteria and between bacteria and the leaf surface. FEMS Microbiology Ecology, 91(3), fiu034. http://doi.org/10.1093/femsec/fiu034
The colored bands at the bottom of the plot highlight the spatial scales at which the summary statistics deviate from the simulation envelopes.
Function
quantumPlot <- function(x,colour=c("#d73027", "#ffffbf", "#91bfdb")){ # load Packages require(ggplot2) require(ggthemes) # convert fv to dataframe env.data <- as.data.frame(tree.data) env.data <- env.data[-1,] # plot it gg_quantomPlot <- ggplot(env.data, aes(r, obs))+ # plot observed value geom_line(colour=c("#4d4d4d"))+ # plot simulation envelopes geom_ribbon(aes(ymin=lo,ymax=hi),alpha=0.1, colour=c("#e0e0e0")) + # axes names and limits ylim(min(env.data$obs)-1, max(env.data$obs)+2) + xlab("Distance r (m)") + ylab("summary statistic") + # plot expected value, according to null model geom_hline(yintercept=1, linetype = "dashed", colour=c("#999999")) + # plot 'Quantums' geom_rug(data=env.data[env.data$obs > env.data$hi,], sides="b", colour=colour[1]) + geom_rug(data=env.data[env.data$obs < env.data$lo,], sides="b", colour=colour[2]) + geom_rug(data=env.data[env.data$obs >= env.data$lo & env.data$obs <= env.data$hi,], sides="b", color=colour[3]) + # make it look beautiful theme_tufte() return(gg_quantomPlot) }
https://gist.github.com/marcosci/e261a586f82d8575a843
Now you can give the result your envelope-fv object and plot it:
attach(redwood) redwood.pcf <- envelope(redwood, fun=pcf) quantumPlot(redwood.pcf)
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.