This vignette shows how to generate seasonal plots of LFMC values.

Libraries

library(LFMC)
library(tidyverse) # data transforming and plotting
library(ggplotFL) # drawing quantiles
library(viridis) # color scales for plots

Specify the path for the LFMC database

setDBpath("../data/lfmc.sqlite")

Choose the species and site codes to be plotted

spCodes <- c(1, 2) # Salvia rosmarinus and Quercus coccifera 
siteCodes <- c(7, 8)

Generate seasonal plots per species by site

for(sp in spCodes) {
  for(site in siteCodes) {
    p <- seasonalPlot(speciesCode = sp, siteCode = site, period = "Fortnight",
                      MOutliers = T, AOutliers = F, plotCurrentYear = T)

    # Plot style
    p <- p +  theme_light() 

    # Axis x - Fortnightly data
    p <- p + scale_x_continuous(breaks = seq(0.7, 26, 2.2),
                                labels = c("Jan","Feb","Mar","Apr","May","Jun",
                                           "Jul","Aug","Sep","Oct","Nov","Dec"))
    # Defining the limits of the y-axis by species
    if(sp == 1) {
      p <- p + scale_y_continuous(limits = c(30, 190), 
                                  breaks = seq(30, 190, 40))
    }
    else if(sp == 2) {
      p <- p + scale_y_continuous(limits = c(55, 160), 
                                  breaks = seq(55, 160, 20))
    } 

    # Axis size
    p <- p + theme(axis.text.x = element_text(size = 7, vjust = 0.9))
    p <- p + theme(axis.text.y = element_text(size = 7))

    # Axis titles
    p <- p + labs(x = "", y = "")
    p <- p + theme(axis.title.y = element_text(size = 8))

    # Plot title
    spName <- p$data[["SpeciesName"]][[1]]
    siteName <- p$data[["SamplingSiteName"]][[1]]

    p <- p + ggtitle(paste(spName, siteName, sep = " - "))
    p <- p + theme(plot.title = element_text(size = 8, hjust = 0.5, color= "gray30"))

    # Legend
    p <- p + theme(legend.position = "bottom", legend.box.spacing = unit(-0.4, 'cm'))
    p <- p + theme(legend.title = element_text(size = 8, color= "gray30"))
    p <- p + theme(legend.text = element_text(size = 8, color= "gray30"))
    print(p)
  }
}


spif-ctfc/LFMC documentation built on Sept. 29, 2022, 2:21 a.m.