MFggplot {MF.beta4}R Documentation

ggplot2 extension for a MF1_single or MF2_multiple object

Description

MFggplot provides graphical BEF relationships based on the output from the function MF1_single or MF2_multiple.

Usage

MFggplot(output, model = "LMM.both", caption = "slope", by_group = NULL)

Arguments

output

the output obtained from MF1_single or MF2_multiple.
For output obtained from MF1_single, if BEF relationships are desired within each category specified by_group, the by_group column must be included in the input.

model

specifying the fitting model, model = "lm" for linear model; model = "LMM.intercept", "LMM.slope" and "LMM.both" for linear mixed models with random effects for intercepts, slopes, and both, respectively. Default is model = "LMM.both".

caption

caption that will be shown in the BEF plots; caption = "slope" to show the estimated slopes in each plot, or caption = "R.squared" to show the ordinary R-squared for linear models or estimated marginal and conditional R-squared for linear mixed models in each plot. Default is caption = "slope".

by_group

the column name of the stratifying variable that is used to group data for model fitting. For example, if by_group = "country", then model will be fitted within each country. Default is NULL.
It is required if a linear mixed model is selected in the model.
If output is obtained from MF2_multiple, the by_group setting must be the same as that set in MF2_multiple.

Value

For an MF1_single object, this function returns a figure that plots the BEF relationship between multifunctionality of order q (= 0, 1 and 2) and species diversity of the same order q for two cases (i) correlations between functions are not corrected for, and (ii) correlations between functions are corrected. The fitted lines for the chosen model are also shown in the figure.

For an MF2_multiple object of given individual function weights, this function returns a list of two objects ($corr_uncorrected and $corr_corrected) that respectively for two cases: (i) correlations between functions are not corrected for, and (ii) correlations between functions are corrected for.

Each object consists of four figures: "$ALL" returns a figure that depicts the BEF relationship between alpha/beta/gamma multifunctionality of order q (= 0, 1 and 2) and the corresponding species diversity of the same order q. The fitted lines for the chosen model are also shown in the figure. "$Gamma" returns only the gamma part of "$ALL", "$Alpha" returns only the alpha part of "$ALL", and "$Beta" returns only the beta part of "$ALL".

Examples


library(dplyr)

### Use data from six countries


## single ecosystem
data("forest_function_data_normalized")
data("forest_biodiversity_data")
output1 <- MF1_single(func_data = forest_function_data_normalized[,6:31], weight = 1,
                      species_data = forest_biodiversity_data)
  
## Display fitted line of linear mixed model with random slopes and random intercepts  
output1 <- data.frame(output1, country=rep(forest_function_data_normalized$country, each = 6))
MFggplot(output1, model = "LMM.both", by_group="country", caption = "slope")


### Use data from five countries (data in Finland are excluded)
 
## multiple ecosystems
data("forest_function_data_normalized")
data("forest_biodiversity_data")
forest_function_data_normalized <- filter(forest_function_data_normalized, country != "FIN")
forest_biodiversity_data <- forest_biodiversity_data[-(1:48),]
output2 <- MF2_multiple(func_data = forest_function_data_normalized[,6:32],
                        species_data = forest_biodiversity_data,
                        weight = 1,
                        by_group = "country")

## Display fitted line of linear mixed model with random slopes and random intercepts  
figure_LMM <- MFggplot(output2, model = "LMM.both", by_group = "country", 
                       caption = "slope")
figure_LMM$corr_uncorrected$ALL
figure_LMM$corr_corrected$ALL


### Use partial data to quickly obtain output  
### (Take the first 18 plots in Germany and the last 18 plots in Italy)

## single ecosystem
data("forest_function_data_raw")
data("forest_biodiversity_data")
GER_ITA_forest_function_raw <- filter(forest_function_data_raw, 
                                      country=="GER"|country=="ITA")[c(1:18,57:74),]
GER_ITA_forest_function_normalized <- function_normalization(data = GER_ITA_forest_function_raw,
                                                             fun_cols = 6:31, 
                                                             negative = c("soil_cn_ff_10","wue"),
                                                             by_group = "country")
GER_ITA_forest_biodiversity <- forest_biodiversity_data[c(49:82,181:229),]
output3 <- MF1_single(func_data = GER_ITA_forest_function_normalized[,6:31], weight = 1,
                      species_data = GER_ITA_forest_biodiversity)


## Display fitted line of linear mixed model with random slopes and random intercepts  
output3 <- data.frame(output3, country=rep(GER_ITA_forest_function_normalized$country, each = 6))
MFggplot(output3, model = "LMM.both", by_group="country", caption = "slope")


## multiple ecosystems
data("forest_function_data_raw")
data("forest_biodiversity_data")
GER_ITA_forest_function_raw <- filter(forest_function_data_raw, 
                                      country=="GER"|country=="ITA")[c(1:18,57:74),]
GER_ITA_forest_function_normalized <- function_normalization(data = GER_ITA_forest_function_raw,
                                                             fun_cols = 6:31, 
                                                             negative = c("soil_cn_ff_10","wue"),
                                                             by_group = "country")
GER_ITA_forest_biodiversity <- forest_biodiversity_data[c(49:82,181:229),]
output4 <- MF2_multiple(func_data = GER_ITA_forest_function_normalized[,6:32],
                        species_data = GER_ITA_forest_biodiversity,
                        weight = 1,
                        by_group = "country")


## Display fitted line of linear mixed model with random slopes and random intercepts  
figure_LMM_GER_ITA <- MFggplot(output4, model = "LMM.both", by_group = "country", 
                               caption = "slope")
figure_LMM_GER_ITA$corr_uncorrected$ALL
figure_LMM_GER_ITA$corr_corrected$ALL



[Package MF.beta4 version 1.0.3 Index]