knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%", dpi = 300, message = FALSE, warning = FALSE )
The goal of mermaidreporting is to provide utility functions for cleaning, summarizing, and visualizing MERMAID Collect data. It works alongside the mermaidr
package, which helps you accesses MERMAID data in R.
If you run into any problems working with this package, please open an issue.
You can install the development version of mermaidreporting with:
# install.packages("remotes") remotes::install_github("data-mermaid/mermaidreporting", upgrade = "never")
Data is available from the mermaidr
package. There are details there on authorization and accessing data.
All functions in mermaidreporting
(and mermaidr
) are of the form mermaid_*()
, to take advantage of RStudio auto-completion and make them easier to find when you have other packages loaded.
First, we read in data using mermaidr
:
library(mermaidr) library(dplyr) my_projects <- mermaid_get_my_projects() xpdc <- my_projects %>% filter(name == "XPDC Kei Kecil 2018") xpdc_fishbelt <- xpdc %>% mermaid_get_project_data(method = "fishbelt", data = "sampleevents")
The data from mermaidr
comes in a form that may seem a little unfriendly to work with!
For example, in xpdc_fishbelt
, the mean total biomass data is contained in a data frame column:
xpdc_fishbelt %>% select(biomass_kgha_by_trophic_group_avg)
Use mermaid_clean_columns()
to clean this up and split each trophic group into its own column:
library(mermaidreporting) xpdc_fishbelt %>% select(biomass_kgha_by_trophic_group_avg) %>% mermaid_clean_columns()
This works on Benthic PIT data, as well, and auto-detects any columns in this format to clean!
xpdc_benthicpit <- xpdc %>% mermaid_get_project_data(method = "benthicpit", data = "sampleevents") xpdc_benthicpit %>% select(percent_cover_by_benthic_category_avg) %>% mermaid_clean_columns()
Default data from mermaidr
has specific details about management rules:
north_sulawesi_fishbelt <- my_projects %>% filter(name == "North Sulawesi (North Minahasa, Sitaro, Tatoareng MPA) Ecological Survey") %>% mermaid_get_project_data("fishbelt", "sampleevents") north_sulawesi_fishbelt %>% distinct(management_rules)
If you want to look at management rules more broadly, you can clean up the data and group together Partial Restrictions using mermaid_clean_management_rules
:
north_sulawesi_fishbelt %>% distinct(management_rules) %>% mermaid_clean_management_rules()
This groups together the Partial Restrictions rules, tidies up the names, and converts any empty strings to NA
s for better missing-value handling!
If you want to have a different value, instead of NA
, you can change it via missing_value
:
north_sulawesi_fishbelt %>% distinct(management_rules) %>% mermaid_clean_management_rules(missing_value = "Not Specified")
You can generate map of site locations using mermaid_map_sites_static()
and mermaid_map_sites_interactive()
, which produce static and interactive maps, respectively.
library(mermaidreporting) xpdc_sites <- xpdc %>% mermaid_get_project_sites() mermaid_map_sites_static(xpdc_sites)
mermaid_map_sites_interactive(xpdc_sites)
Note that this is just a screenshot of the interactive plot, but you can try it out in an interactive R session by running the above code!
You can also map sites by the value of a variable. For example, to map sites by mean total biomass use mermaid_map_sites_static()
with plot_var
set to biomass_kgha_avg
:
mermaid_map_sites_static(xpdc_fishbelt, biomass_kgha_avg)
Or by management rules:
xpdc_fishbelt %>% mermaid_clean_management_rules() %>% mermaid_map_sites_static(management_rules)
You can plot Fish Belt biomass, split by a grouping variable (such as trophic group) and compared by another variable (such as reef exposure).
xpdc_fishbelt %>% mermaid_plot_fish_belt_biomass(biomass_kgha_by_trophic_group_avg, reef_exposure)
Or by reef zone:
xpdc_fishbelt %>% mermaid_plot_fish_belt_biomass(biomass_kgha_by_trophic_group_avg, reef_zone)
Similarly, you can plot Benthic PIT percent cover, split by a grouping variable (such as benthic category) and compared by another variable (such as management rules):
xpdc_benthicpit %>% mermaid_clean_management_rules(missing_value = "Not Specified") %>% mermaid_plot_benthic_pit_percent_cover(percent_cover_by_benthic_category_avg, management_rules)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.