View on GitHub

Effectiveness

An R package for plots of effectiveness landscapes in mutualisms (seed dispersal, pollination)

Download this project as a .zip file Download this project as a tar.gz file

Plotting effectiveness landscapes.

Effectiveness landscapes are the two-dimensional representation of the possible combinations of the quantity and the quality of dualistic services (seed dispersal, pollination) and with elevational contours representing isoclines of effectiveness. These representations can be 2D bivariate plots of multiplicative effects of any of the seed dispersal (SDE) or pollination (PE) effectiveness components. For example, SDE can be quantified as the number of seeds dispersed by a dispersal agent multiplied by the probability that a dispersed seed produces a new adult: SDE = Quantity · Quality. Quantity and quality in turn are each determined by two subcomponents. Quantity is (1) the number of visits a dispersal agent makes multiplied by (2) the number of seeds dispersed per visit, while quality is (1) the probability that a dispersed seed survives handling by the dispersal agent in a viable condition (quality of treatment in the mouth and gut) multiplied by (2) the probability that a viable dispersed seed will survive, germinate, and produce a new adult (quality of deposition). Thus the SDE landscape can be any 2D plot of Qty x Qlty, with isoclines representing equal values of overall SDE. Or we may plot no. visits x no. fruits/visit, with isoclines representing the overall Qty component. Isoclines just plot the values of the product of two variables. The code is the following:

You can install the last version of the R package directly with:


# Installation.
devtools::install_github("pedroj/effectiveness_pckg")
library(effect.lndscp)

This is the skeleton for the function code. Please see the example datasets included in the package.


# Example datasets.
data(prunus)
data(cecropia)

#----------------------------------------------------------------------
# effectiveness
# Function to plot effectiveness landscapes.
#----------------------------------------------------------------------
# autoisolines: Code for automatically plotting isolines of
# effectiveness landscapes.
# Based on code for plotting effectiveness landscapes by Pedro 
# Jordano and code for automatic calculation of isolines 
# by Bernardo Santos.
# 3 December 2013. UNESP, Rio Claro, Brazil. Pedro Jordano.
#----------------------------------------------------------------------
## First version 12 Jan 2009. Revised 3 December 2013.
## New revision 23 January 2015.
#----------------------------------------------------------------------
# Options:
#   q1, the "quantitative component", to plot on the X axis. 
#   q2, the "qualitative component", to plot on the Y axis.
#   group=NA, a grouping variable to set point shapes (e.g., family).
#   label= NA, a label for the individual points (e.g., spcies acronym).
#   nlines=10, specify the number of isolines.
#   myxlab= "QtComp", optional label for axis X.
#   myylab= "QltComp", optional label for axis Y.
# 
# Example:
# effectiveness(sde$visits, sde$eff_per_vis, sde$group, sde$animal, 10, 
#               myxlab= "No. visits/10h", 
#               myylab="Effectiveness/vis (No. fruits handled)")
# effectiveness(cgla$totvis, cgla$totbic, cgla$fam, cgla$code, 15, 
#               myxlab= "Total no. visits", 
#               myylab="No. fruits pecked/vis")
#----------------------------------------------------------------------
#
effectiveness<- function(q1, q2, group=NA, label= NA, nlines=10,
                        myxlab= "QtComp", myylab= "QltComp")    {
    # q1 is the component to plot on X axis
    # q2 is the component to plot on Y axis
    # group is a group label
    # label is a taxa label
    require(devtools)
    require(ggplot2)
    #
    d<-as.data.frame(cbind(q1, q2, group, label))
    names(d)
    nlines <- nlines+1 # number of isolines wanted
    # slope of a straight line linking (left,bottom) to (right,above) 
    # corners of the graphic
    alfa <- max(d$q2)/max(d$q1)
    # sequence of (nlines) regular spaced x values for the isoclines
    xval <- seq(0, max(d$q1), 
        length.out=(nlines+1))[2:(nlines+1)] 
    isoc <- (xval*xval*alfa) # values of the isoclines
    vis1<-seq(0, max(d$q1), length.out= 1000)
    #
    pp<- as.data.frame(vis1) # Build dataset for within loop plot.
    for(i in 1:nlines)
    {
        pp<- cbind(pp, isoc[i]/vis1)
    }    
    # Main plot -------------------------------------------------------
    # mytheme_bw.R - Getting a custom theme for the plot.
    devtools::source_gist("https://gist.github.com/b843fbafa3af8f408972")
    #
    p1<- ggplot(d, aes(x=q1, y=q2)) + 
        geom_point(shape= group, size=5) +
        geom_text(size= 4, label= label, hjust= 0.5, vjust= 1.9) +
        mytheme_bw()
    # Adding isolines -------------------------------------------------
    labelx<- rep(0.8*max(q1), nlines)
    labely<- as.vector(t(pp[800,1:nlines+1]))
    
    for(i in 1:nlines+1){ 
         p1= p1 + geom_line(aes(x, y), 
            data= data.frame(x= pp$vis1, y= pp[,i]), 
            col="blue", size = 0.25, alpha= 0.6) + 
            ylim(0, max(q2)) +
            xlab(paste(myxlab)) + 
            ylab(paste(myylab))
    }
    p1 + annotate("text", x= labelx, y= labely,
        label=paste("QC= ", round(isoc,1)), 
        size=4, colour="red", hjust=0) 
}
#----------------------------------------------------------------------

Example

To do the SDE or PE plot, let's use an example: We use the actual values obtained for the seed dispersal of Prunus mahaleb and . We were interested in plotting the locations of the different species of frugivores visiting the tree for fruit food and dispersing its seeds, and visualize them on the PE landscape.

The function overlays the isolines automatically. You can set the number of desired isolines.

Here is an example run. You can get the whole RMarkdown file in my GitHub repository for the effectiveness landscapes code in R. The whole run of the example is here.


# Installation.
devtools::install_github("pedroj/effectiveness_pckg")
library(effect.lndscp)

#--------------------------------------------------------------------
# Based on a dataset of Prunus mahaleb frugivores.
# In this example we build the effectiveness landscape just for the 
# quantitative component, plotting its two subcomponents, visitation 
# rate and per-visit effectiveness.
#
data(prunus)
effectiveness(prunus$visits, prunus$eff_per_vis, 
   prunus$group, prunus$animal, 10, 
   myxlab= "No. visits/10h", 
   myylab="Effectiveness/vis (No. fruits handled)")
#--------------------------------------------------------------------
# Based on a dataset of Cecropia glaziovii frugivores.
# This effectiveness_plot function has repel labels activated.
data(cecropia)
effectiveness_plot(cecropia$totvis, cecropia$totbic, 
    cecropia$fam, cecropia$code, 10, 
    myxlab= "No. visits/10h", 
    myylab="Effectiveness/vis (No. fruits handled)")

The function returns a ggplot2 plot object that can be later customized with additional ggplot2 options, as well as the actual plot.

Suggested references: