A simple loop to add multiple layers
Library leaflet with R is well integrated with pipe writing (%>%). Thus, it is really easy to add multiple layers and options in a leaflet widget.
If you want to add a lot of layers in your widget, it is not necessary to provide a “addPolygons” for each of these layers, you can simply use a loop. You will need to previously standardize the names of your layers to make a clear code. Moreover, this also allows to use different group names for different view options.
The leaflet widget below shows an example of multiple layers viewing, added with a loop. The R-code is also provided. Because the html code created by knitr for this leaflet widget is quite heavy (1Mo), I included the widget as an iframe on this website :
<iframe src="..../TAC_leaflet.html" height="500" width="500"></iframe>
Discrepancies between fishing quotas and scientific advices areas
The example below is a widget realised for AFH (French Association of fisheries scientists). This shows different cases for the discrepancies between fishing quotas areas defined by the European commission and areas delimited by scientists to give their advices concerning fish resources. The complete article can be directly downloaded on the AFH website (in French).
Key points of the AFH note
(Translation from French)
- On December, 12-13. 2016, EU ministers of fisheries will set 2017 fishing quotas, in theory according to scientific advice and with the objective of sustainable fisheries that provide maximum sustainable yield.
- Scientific advice is established at the scale of fonctional units for fish populations, which are based on biological knowledge and evolve in time according to new knowledge on species ecology.
- On the other hand, management areas, for which quotas are set, were defined in 1982, and hardly evolved since then.
- Consequently, there is an increasing mismatch between the scale at which advice is given and the scale at which fishing is managed. This results in a very complex and often nontransparent quota-setting process for all stakeholders.
- More importantly, these discrepancies create risks for the sustainability of biological resources. They jeopardize the achievement of maximum sustainable yield for the stocks concerned.
- Case 1: Concordance management unit – functional unit
- Case 2: Scientific advice is split into several Total Allowable Catches (TACs)
- Case 3: A TAC gathers several advice areas
- Case 4: Complete mismatch between the management unit and the scientific advisory unit (division and / or recombination of advices areas, mixing of previous cases)
R-code to loop multiple layers in a leaflet widget
This is indeed a R-markdown code.