QuantumPlots with ggplot2 and spatstat

[This article was first published on spatialRecology - r, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.



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.


quantumPlot <- function(x,colour=c("#d73027", "#ffffbf", "#91bfdb")){

  # load Packages

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


Now you can give the result your envelope-fv object and plot it:

redwood.pcf <- envelope(redwood, fun=pcf)

To leave a comment for the author, please follow the link and comment on their blog: spatialRecology - r.

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.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)