diff --git a/.gitignore b/.gitignore index 8f4a197..ecdd2e1 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,7 @@ test.R test.png map.png -docs +# docs /doc/ /Meta/ diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/CITATION.md b/docs/CITATION.md new file mode 100644 index 0000000..a8367c1 --- /dev/null +++ b/docs/CITATION.md @@ -0,0 +1,6 @@ +# Citation + +

Giraud T (2025). +mapsf: Thematic Cartography. +doi:10.32614/CRAN.package.mapsf, R package v1.0.0. +

diff --git a/docs/LICENSE.md b/docs/LICENSE.md new file mode 100644 index 0000000..175443c --- /dev/null +++ b/docs/LICENSE.md @@ -0,0 +1,595 @@ +GNU General Public License +========================== + +_Version 3, 29 June 2007_ +_Copyright © 2007 Free Software Foundation, Inc. <>_ + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +## Preamble + +The GNU General Public License is a free, copyleft license for software and other +kinds of works. + +The licenses for most software and other practical works are designed to take away +your freedom to share and change the works. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change all versions of a +program--to make sure it remains free software for all its users. We, the Free +Software Foundation, use the GNU General Public License for most of our software; it +applies also to any other work released this way by its authors. You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General +Public Licenses are designed to make sure that you have the freedom to distribute +copies of free software (and charge for them if you wish), that you receive source +code or can get it if you want it, that you can change the software or use pieces of +it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or +asking you to surrender the rights. Therefore, you have certain responsibilities if +you distribute copies of the software, or if you modify it: responsibilities to +respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, +you must pass on to the recipients the same freedoms that you received. You must make +sure that they, too, receive or can get the source code. And you must show them these +terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: **(1)** assert +copyright on the software, and **(2)** offer you this License giving you legal permission +to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is +no warranty for this free software. For both users' and authors' sake, the GPL +requires that modified versions be marked as changed, so that their problems will not +be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of +the software inside them, although the manufacturer can do so. This is fundamentally +incompatible with the aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we have designed +this version of the GPL to prohibit the practice for those products. If such problems +arise substantially in other domains, we stand ready to extend this provision to +those domains in future versions of the GPL, as needed to protect the freedom of +users. + +Finally, every program is threatened constantly by software patents. States should +not allow patents to restrict development and use of software on general-purpose +computers, but in those that do, we wish to avoid the special danger that patents +applied to a free program could make it effectively proprietary. To prevent this, the +GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +## TERMS AND CONDITIONS + +### 0. Definitions + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this +License. Each licensee is addressed as “you”. “Licensees” and +“recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in +a fashion requiring copyright permission, other than the making of an exact copy. The +resulting work is called a “modified version” of the earlier work or a +work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on +the Program. + +To “propagate” a work means to do anything with it that, without +permission, would make you directly or secondarily liable for infringement under +applicable copyright law, except executing it on a computer or modifying a private +copy. Propagation includes copying, distribution (with or without modification), +making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through a computer +network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the +extent that it includes a convenient and prominently visible feature that **(1)** +displays an appropriate copyright notice, and **(2)** tells the user that there is no +warranty for the work (except to the extent that warranties are provided), that +licensees may convey the work under this License, and how to view a copy of this +License. If the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +### 1. Source Code + +The “source code” for a work means the preferred form of the work for +making modifications to it. “Object code” means any non-source form of a +work. + +A “Standard Interface” means an interface that either is an official +standard defined by a recognized standards body, or, in the case of interfaces +specified for a particular programming language, one that is widely used among +developers working in that language. + +The “System Libraries” of an executable work include anything, other than +the work as a whole, that **(a)** is included in the normal form of packaging a Major +Component, but which is not part of that Major Component, and **(b)** serves only to +enable use of the work with that Major Component, or to implement a Standard +Interface for which an implementation is available to the public in source code form. +A “Major Component”, in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system (if any) on which +the executable work runs, or a compiler used to produce the work, or an object code +interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the +source code needed to generate, install, and (for an executable work) run the object +code and to modify the work, including scripts to control those activities. However, +it does not include the work's System Libraries, or general-purpose tools or +generally available free programs which are used unmodified in performing those +activities but which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for the work, and +the source code for shared libraries and dynamically linked subprograms that the work +is specifically designed to require, such as by intimate data communication or +control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate +automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +### 2. Basic Permissions + +All rights granted under this License are granted for the term of copyright on the +Program, and are irrevocable provided the stated conditions are met. This License +explicitly affirms your unlimited permission to run the unmodified Program. The +output from running a covered work is covered by this License only if the output, +given its content, constitutes a covered work. This License acknowledges your rights +of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without +conditions so long as your license otherwise remains in force. You may convey covered +works to others for the sole purpose of having them make modifications exclusively +for you, or provide you with facilities for running those works, provided that you +comply with the terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for you must do so +exclusively on your behalf, under your direction and control, on terms that prohibit +them from making any copies of your copyrighted material outside their relationship +with you. + +Conveying under any other circumstances is permitted solely under the conditions +stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +### 3. Protecting Users' Legal Rights From Anti-Circumvention Law + +No covered work shall be deemed part of an effective technological measure under any +applicable law fulfilling obligations under article 11 of the WIPO copyright treaty +adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention +of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of +technological measures to the extent such circumvention is effected by exercising +rights under this License with respect to the covered work, and you disclaim any +intention to limit operation or modification of the work as a means of enforcing, +against the work's users, your or third parties' legal rights to forbid circumvention +of technological measures. + +### 4. Conveying Verbatim Copies + +You may convey verbatim copies of the Program's source code as you receive it, in any +medium, provided that you conspicuously and appropriately publish on each copy an +appropriate copyright notice; keep intact all notices stating that this License and +any non-permissive terms added in accord with section 7 apply to the code; keep +intact all notices of the absence of any warranty; and give all recipients a copy of +this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer +support or warranty protection for a fee. + +### 5. Conveying Modified Source Versions + +You may convey a work based on the Program, or the modifications to produce it from +the Program, in the form of source code under the terms of section 4, provided that +you also meet all of these conditions: + +* **a)** The work must carry prominent notices stating that you modified it, and giving a +relevant date. +* **b)** The work must carry prominent notices stating that it is released under this +License and any conditions added under section 7. This requirement modifies the +requirement in section 4 to “keep intact all notices”. +* **c)** You must license the entire work, as a whole, under this License to anyone who +comes into possession of a copy. This License will therefore apply, along with any +applicable section 7 additional terms, to the whole of the work, and all its parts, +regardless of how they are packaged. This License gives no permission to license the +work in any other way, but it does not invalidate such permission if you have +separately received it. +* **d)** If the work has interactive user interfaces, each must display Appropriate Legal +Notices; however, if the Program has interactive interfaces that do not display +Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are +not by their nature extensions of the covered work, and which are not combined with +it such as to form a larger program, in or on a volume of a storage or distribution +medium, is called an “aggregate” if the compilation and its resulting +copyright are not used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work in an aggregate +does not cause this License to apply to the other parts of the aggregate. + +### 6. Conveying Non-Source Forms + +You may convey a covered work in object code form under the terms of sections 4 and +5, provided that you also convey the machine-readable Corresponding Source under the +terms of this License, in one of these ways: + +* **a)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by the Corresponding Source fixed on a +durable physical medium customarily used for software interchange. +* **b)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by a written offer, valid for at least +three years and valid for as long as you offer spare parts or customer support for +that product model, to give anyone who possesses the object code either **(1)** a copy of +the Corresponding Source for all the software in the product that is covered by this +License, on a durable physical medium customarily used for software interchange, for +a price no more than your reasonable cost of physically performing this conveying of +source, or **(2)** access to copy the Corresponding Source from a network server at no +charge. +* **c)** Convey individual copies of the object code with a copy of the written offer to +provide the Corresponding Source. This alternative is allowed only occasionally and +noncommercially, and only if you received the object code with such an offer, in +accord with subsection 6b. +* **d)** Convey the object code by offering access from a designated place (gratis or for +a charge), and offer equivalent access to the Corresponding Source in the same way +through the same place at no further charge. You need not require recipients to copy +the Corresponding Source along with the object code. If the place to copy the object +code is a network server, the Corresponding Source may be on a different server +(operated by you or a third party) that supports equivalent copying facilities, +provided you maintain clear directions next to the object code saying where to find +the Corresponding Source. Regardless of what server hosts the Corresponding Source, +you remain obligated to ensure that it is available for as long as needed to satisfy +these requirements. +* **e)** Convey the object code using peer-to-peer transmission, provided you inform +other peers where the object code and Corresponding Source of the work are being +offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the +Corresponding Source as a System Library, need not be included in conveying the +object code work. + +A “User Product” is either **(1)** a “consumer product”, which +means any tangible personal property which is normally used for personal, family, or +household purposes, or **(2)** anything designed or sold for incorporation into a +dwelling. In determining whether a product is a consumer product, doubtful cases +shall be resolved in favor of coverage. For a particular product received by a +particular user, “normally used” refers to a typical or common use of +that class of product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected to use, the +product. A product is a consumer product regardless of whether the product has +substantial commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, +procedures, authorization keys, or other information required to install and execute +modified versions of a covered work in that User Product from a modified version of +its Corresponding Source. The information must suffice to ensure that the continued +functioning of the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for +use in, a User Product, and the conveying occurs as part of a transaction in which +the right of possession and use of the User Product is transferred to the recipient +in perpetuity or for a fixed term (regardless of how the transaction is +characterized), the Corresponding Source conveyed under this section must be +accompanied by the Installation Information. But this requirement does not apply if +neither you nor any third party retains the ability to install modified object code +on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to +continue to provide support service, warranty, or updates for a work that has been +modified or installed by the recipient, or for the User Product in which it has been +modified or installed. Access to a network may be denied when the modification itself +materially and adversely affects the operation of the network or violates the rules +and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with +this section must be in a format that is publicly documented (and with an +implementation available to the public in source code form), and must require no +special password or key for unpacking, reading or copying. + +### 7. Additional Terms + +“Additional permissions” are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. Additional +permissions that are applicable to the entire Program shall be treated as though they +were included in this License, to the extent that they are valid under applicable +law. If additional permissions apply only to part of the Program, that part may be +used separately under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any +additional permissions from that copy, or from any part of it. (Additional +permissions may be written to require their own removal in certain cases when you +modify the work.) You may place additional permissions on material, added by you to a +covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a +covered work, you may (if authorized by the copyright holders of that material) +supplement the terms of this License with terms: + +* **a)** Disclaiming warranty or limiting liability differently from the terms of +sections 15 and 16 of this License; or +* **b)** Requiring preservation of specified reasonable legal notices or author +attributions in that material or in the Appropriate Legal Notices displayed by works +containing it; or +* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that +modified versions of such material be marked in reasonable ways as different from the +original version; or +* **d)** Limiting the use for publicity purposes of names of licensors or authors of the +material; or +* **e)** Declining to grant rights under trademark law for use of some trade names, +trademarks, or service marks; or +* **f)** Requiring indemnification of licensors and authors of that material by anyone +who conveys the material (or modified versions of it) with contractual assumptions of +liability to the recipient, for any liability that these contractual assumptions +directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further +restrictions” within the meaning of section 10. If the Program as you received +it, or any part of it, contains a notice stating that it is governed by this License +along with a term that is a further restriction, you may remove that term. If a +license document contains a further restriction but permits relicensing or conveying +under this License, you may add to a covered work material governed by the terms of +that license document, provided that the further restriction does not survive such +relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in +the relevant source files, a statement of the additional terms that apply to those +files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a +separately written license, or stated as exceptions; the above requirements apply +either way. + +### 8. Termination + +You may not propagate or modify a covered work except as expressly provided under +this License. Any attempt otherwise to propagate or modify it is void, and will +automatically terminate your rights under this License (including any patent licenses +granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a +particular copyright holder is reinstated **(a)** provisionally, unless and until the +copyright holder explicitly and finally terminates your license, and **(b)** permanently, +if the copyright holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently +if the copyright holder notifies you of the violation by some reasonable means, this +is the first time you have received notice of violation of this License (for any +work) from that copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of +parties who have received copies or rights from you under this License. If your +rights have been terminated and not permanently reinstated, you do not qualify to +receive new licenses for the same material under section 10. + +### 9. Acceptance Not Required for Having Copies + +You are not required to accept this License in order to receive or run a copy of the +Program. Ancillary propagation of a covered work occurring solely as a consequence of +using peer-to-peer transmission to receive a copy likewise does not require +acceptance. However, nothing other than this License grants you permission to +propagate or modify any covered work. These actions infringe copyright if you do not +accept this License. Therefore, by modifying or propagating a covered work, you +indicate your acceptance of this License to do so. + +### 10. Automatic Licensing of Downstream Recipients + +Each time you convey a covered work, the recipient automatically receives a license +from the original licensors, to run, modify and propagate that work, subject to this +License. You are not responsible for enforcing compliance by third parties with this +License. + +An “entity transaction” is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an organization, or +merging organizations. If propagation of a covered work results from an entity +transaction, each party to that transaction who receives a copy of the work also +receives whatever licenses to the work the party's predecessor in interest had or +could give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if the predecessor +has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or +affirmed under this License. For example, you may not impose a license fee, royalty, +or other charge for exercise of rights granted under this License, and you may not +initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging +that any patent claim is infringed by making, using, selling, offering for sale, or +importing the Program or any portion of it. + +### 11. Patents + +A “contributor” is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The work thus +licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or +controlled by the contributor, whether already acquired or hereafter acquired, that +would be infringed by some manner, permitted by this License, of making, using, or +selling its contributor version, but do not include claims that would be infringed +only as a consequence of further modification of the contributor version. For +purposes of this definition, “control” includes the right to grant patent +sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license +under the contributor's essential patent claims, to make, use, sell, offer for sale, +import and otherwise run, modify and propagate the contents of its contributor +version. + +In the following three paragraphs, a “patent license” is any express +agreement or commitment, however denominated, not to enforce a patent (such as an +express permission to practice a patent or covenant not to sue for patent +infringement). To “grant” such a patent license to a party means to make +such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the +Corresponding Source of the work is not available for anyone to copy, free of charge +and under the terms of this License, through a publicly available network server or +other readily accessible means, then you must either **(1)** cause the Corresponding +Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the +patent license for this particular work, or **(3)** arrange, in a manner consistent with +the requirements of this License, to extend the patent license to downstream +recipients. “Knowingly relying” means you have actual knowledge that, but +for the patent license, your conveying the covered work in a country, or your +recipient's use of the covered work in a country, would infringe one or more +identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you +convey, or propagate by procuring conveyance of, a covered work, and grant a patent +license to some of the parties receiving the covered work authorizing them to use, +propagate, modify or convey a specific copy of the covered work, then the patent +license you grant is automatically extended to all recipients of the covered work and +works based on it. + +A patent license is “discriminatory” if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on the +non-exercise of one or more of the rights that are specifically granted under this +License. You may not convey a covered work if you are a party to an arrangement with +a third party that is in the business of distributing software, under which you make +payment to the third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties who would receive +the covered work from you, a discriminatory patent license **(a)** in connection with +copies of the covered work conveyed by you (or copies made from those copies), or **(b)** +primarily for and in connection with specific products or compilations that contain +the covered work, unless you entered into that arrangement, or that patent license +was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied +license or other defenses to infringement that may otherwise be available to you +under applicable patent law. + +### 12. No Surrender of Others' Freedom + +If conditions are imposed on you (whether by court order, agreement or otherwise) +that contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot convey a covered work so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not convey it at all. For example, if you +agree to terms that obligate you to collect a royalty for further conveying from +those to whom you convey the Program, the only way you could satisfy both those terms +and this License would be to refrain entirely from conveying the Program. + +### 13. Use with the GNU Affero General Public License + +Notwithstanding any other provision of this License, you have permission to link or +combine any covered work with a work licensed under version 3 of the GNU Affero +General Public License into a single combined work, and to convey the resulting work. +The terms of this License will continue to apply to the part which is the covered +work, but the special requirements of the GNU Affero General Public License, section +13, concerning interaction through a network will apply to the combination as such. + +### 14. Revised Versions of this License + +The Free Software Foundation may publish revised and/or new versions of the GNU +General Public License from time to time. Such new versions will be similar in spirit +to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that +a certain numbered version of the GNU General Public License “or any later +version” applies to it, you have the option of following the terms and +conditions either of that numbered version or of any later version published by the +Free Software Foundation. If the Program does not specify a version number of the GNU +General Public License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU +General Public License can be used, that proxy's public statement of acceptance of a +version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no +additional obligations are imposed on any author or copyright holder as a result of +your choosing to follow a later version. + +### 15. Disclaimer of Warranty + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +### 16. Limitation of Liability + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY +COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS +PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE +OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE +WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +### 17. Interpretation of Sections 15 and 16 + +If the disclaimer of warranty and limitation of liability provided above cannot be +given local legal effect according to their terms, reviewing courts shall apply local +law that most closely approximates an absolute waiver of all civil liability in +connection with the Program, unless a warranty or assumption of liability accompanies +a copy of the Program in return for a fee. + +_END OF TERMS AND CONDITIONS_ + +## How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to +the public, the best way to achieve this is to make it free software which everyone +can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them +to the start of each source file to most effectively state the exclusion of warranty; +and each file should have at least the “copyright” line and a pointer to +where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this +when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type 'show c' for details. + +The hypothetical commands `show w` and `show c` should show the appropriate parts of +the General Public License. Of course, your program's commands might be different; +for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to +sign a “copyright disclaimer” for the program, if necessary. For more +information on this, and how to apply and follow the GNU GPL, see +<>. + +The GNU General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may consider it +more useful to permit linking proprietary applications with the library. If this is +what you want to do, use the GNU Lesser General Public License instead of this +License. But first, please read +<>. diff --git a/docs/NEWS.md b/docs/NEWS.md new file mode 100644 index 0000000..28737c9 --- /dev/null +++ b/docs/NEWS.md @@ -0,0 +1,231 @@ +# mapsf 1.0.0 + +## Feat +- add alpha (transparency) for all types in mf_map() and in mf_raster() +- remove all deprecated functions and arguments: mf_legend_*() functions; +adjust in mf_arrow(); theme and export in mf_export(); theme in mf_init(); +pt_pch, pt_cex, pt_pch_na, pt_cex_na in mf_legend(); unit from mf_scale(); + +## Docs +- update the cheat sheet +- update the main vignette + + +# mapsf 0.12.0 + +## Fix +- use 1/4 of line for typical offset space (title, credits, scale bar, north arrow etc.) ([#74](https://github.com/riatelab/mapsf//issues/74)) +- change text adj to allow multiple lines titles in mf_title() +- make mf_inset_*() work on split windows ([#77](https://github.com/riatelab/mapsf//issues/77)) +- add a message when values are outside class limits for type="choro" + +## Feat +- add cex and adj args to mf_arrow(), better arrow shape, better real north adjustemnent +- add mf_get_pencil() function to create a pencil layer from a polygon layer +- add "Q6" and "ckmeans" classification methods to mf_get_breaks() +- add mf_get_borders() to extract borders from contiguous polygons + + + +# mapsf 0.11.0 + +## Fix +- better management of label display in mf_graticule(), fix [#73](https://github.com/riatelab/mapsf//issues/73) + +# mapsf 0.10.1 + +## Fix +- revert previous remove "export" and "theme" args from mf_export() to accommodate dependencies +- revert previous remove "theme" from mf_init() to accommodate dependencies + + +# mapsf 0.10.0 + +## Fix +- allow to plot non overlapping labels from a layer made of strictly overlapping features with mf_label() ([#65](https://github.com/riatelab/mapsf//issues/65)) +- fully display mf_raster() legends after a terra::plot() call ([#67](https://github.com/riatelab/mapsf//issues/67)) +- remove "export" and "theme" args from mf_export() +- remove "theme" from mf_init() + +## Feat +- improved and cleaner documentation for mf_map() ([#62](https://github.com/riatelab/mapsf//issues/62)) + + + +# mapsf 0.9.0 + +## Fix +- add the possibility to use a scale bar in (US) maps using feet based CRS ([#59](https://github.com/riatelab/mapsf//issues/59)) +- deprecate unit argument in mf_scale() +- remove wrong ellipsis propagation in mf_label() +- better environment management in mf_legend() to allow usage inside a +function ([#58](https://github.com/riatelab/mapsf//issues/58)) +- fix raster legends (using type arg, see feat.) ([#60](https://github.com/riatelab/mapsf//issues/60)) + +## Feat +- add "interval", "continuous" and "classes" types with matching legends in +mf_raster() ([#60](https://github.com/riatelab/mapsf//issues/60)) +- mf_raster() invisibly returns the initial raster + + + +# mapsf 0.8.0 + +## Fix +- raise an error and display an informative message if no points are plotted +when type = "prop*" + +## Feat +- add mf_distr(), a function to display a statistical distribution with +histogram, boxplot, stripchart and density curve +- add a lot of legend related args (leg_frame_border, leg_horiz, leg_adj, +leg_bg, leg_fg, leg_size, leg_border, leg_box_border, leg_box_cex) +- double legends (prop_choro, prop_typo, etc.) are stacked by default +- add legends for raster +- deprecate all mf_legend_*() functions +- add rev arg for function using pal to reverse named palettes +- add a q arg in mf_label() to select the quality of the non overlapping +placement + +## Refactor +- use the maplegend pkg for legends (this change may introduce minor breaking +changes) +- use s2 instead of overcomplicated sf code for othographic proj in +mf_worldmap() +- use R base instead of C++ in mf_label() non overalapping placement + + +# mapsf 0.7.1 + +## Fix +- fix bug in color assignment in 'choro', 'prop_choro' and 'symb_choro' maps +when supplying "incomplete" breaks ([#56](https://github.com/riatelab/mapsf//issues/56)) + +# mapsf 0.7.0 + +## Fix +- use a vector of colors for lines if necessary in mf_label() ([#50](https://github.com/riatelab/mapsf//issues/50)) +- enable pipe without side effects (no extra plot) +- use a default transparent background for insets +- deprecate "theme" arg in relevant function, adapt docs and vignettes, use +options() for themes instead of global variable & mimic the behaviour of +basetheme package +- force the use of cairo device, if available, in mf_export() for png +- fix wrong class allocation when using breaks = "jenks" ([#53](https://github.com/riatelab/mapsf//issues/53)) +- exports using unprojected objects do not produce figures with inaccurate +height/width ratio anymore. + +## Feat +- add expandBB arg in mf_map() +- add expandBB arg in mf_raster() +- add arg checking depending on type in mf_map() +- add an error message for functions that need a pre-existing plot +- add mf_graticule() to add graticule lines and labels +- set internally the 'add' arg for each map types in mf_map() + + + +# mapsf 0.6.1 + + +## Fix +- add explicit support for sfg objects in mf_base(), mf_map(..., type = "base") + + +# mapsf 0.6.0 + + +## Fix +- use val_max in mf_prop() for LINES +- add message when mf_export() is based on longlat obj +- add a test for "x" class in mf_map() +- enable proportional symbol plots for single points when using "prop", "prop_typo" & "prop_choro" maps; see [#45](https://github.com/riatelab/mapsf//issues/45) +- fix a bug in color assignment when there is a mismatch between the number of classes and the size of the color palette +- add an error for method "geom" in mf_get_breaks() when min(x) <= 0 +- remove Inf values from x when using mf_get_breaks() +- remove Inf values from x when using "prop", "prop_typo" & "prop_choro" maps +- add informative message when NA, 0 & Inf values are removed when using "prop", "prop_typo" & "prop_choro" maps +- add informative message when negative values are transformed to positive values when using "prop", "prop_typo" & "prop_choro" maps + +## Feat +- add "prop_typo"" maps for LINES objects +- add mf_get_ratio() to get appropriate values for map width & height + + + + + + +# mapsf 0.5.0 + +## Fix +- remove "export" arg for exports based on terra rasters +- remove "bg"" arg in mf_map() +- add "pch = 20" default to plot points with mf_base() +- get sf back from Depends to Imports +- remove s2 related message for recent version of sf in mf_worldmap() + +## Feat +- add "interactive" position for legends, north arrow, scale bar, annotation +- add self-adjusted rounded values for proportional circles legends + +# mapsf 0.4.0 + +## Fix +- allow the display of raster with >=2 bands (not only exactly 3) +- avoid mf_map(..., type="symb") failing when there is only one modality +- make mf_export() aware of the export format with the filename extension only (+ deprecate "export"" arg) +- add a default maximum to maxcell arg for raster display in mf_raster() +- change smooth defaults in mf_raster(), TRUE if nlyr>=2, FALSE otherwise + +## Feat +- add a web only vignette on faceted maps +- add a web only vignette on custom fonts +- add a cheat sheet +- add parameters to customize worldmaps (land and ocean colors and borders) +- add informatives messages concerning mf_map() input (checking type and variable names) + + +# mapsf 0.3.0 + +## Fix +* add support for native pipe +* suppress messages that appear when s2 use is switched with mf_worldmap() +* replace raster by terra in all things raster + +## Feat +* add a web only vignette on insets +* add a web only vignette on themes +* add mf_background(), a function to plot a background image for map +* add support for raster in mf_export() and mf_init() + + +# mapsf 0.2.0 + +## Fix +* change default value for interpolate and display without extra margins in mf_raster() +* increase minimal R version to 3.6.0 to use hcl.colors() +* adjust the largest symbol size in mf_map(..., "prop*") +* remove frame around insets +* remove LazyData from DESCRIPTION +* use sf 'on the fly' projection for unprojected sf objects +* better display of titles and maps (tiny extra space around maps) +* add explicit default value for "add" arg in mapping functions +* allow to plot (coherent) GEOMETRYCOLLECTIONS +* better default for POINT and LINES in mf_map(..., type = "base") +* fix mf_worldmap() by bypassing s2 use + + +## Feat +* Added a `NEWS.md` file to track changes to the package. +* split mf_init() to mf_init() and mf_export() +* allow width AND height set in mf_export() +* allow raster as input in mf_init() and mf_export() +* allow to change existent theme settings directrly in mf_theme() +* make mf_theme() return the current theme +* add default value for txt, add bg arg (for background) in mf_credits() +* add coordinates positioning for maps with 2 legends +* add alpha arg for transparency in mapping functions using "pal" +* change the default theme value to a theme with only tiny margins +* a web only vignette on map export +* allow hcl.colors palette names use in mf_legend*() functions \ No newline at end of file diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..f7e4452 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,173 @@ + + + + + +# mapsf + + + +[![CRAN](https://www.r-pkg.org/badges/version-ago/mapsf)](https://cran.r-project.org/package=mapsf) +[![R-CMD-check](https://github.com/riatelab/mapsf/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/riatelab/mapsf/actions/workflows/R-CMD-check.yaml) +[![downloads](https://cranlogs.r-pkg.org/badges/mapsf?color=brightgreen)](https://cran.r-project.org/package=mapsf) +[![Codecov test +coverage](https://codecov.io/gh/riatelab/mapsf/branch/master/graph/badge.svg)](https://app.codecov.io/gh/riatelab/mapsf?branch=master) +[![status](https://tinyverse.netlify.app/badge/mapsf)](https://CRAN.R-project.org/package=mapsf) +[![OpenSSF Best +Practices](https://www.bestpractices.dev/projects/8704/badge)](https://www.bestpractices.dev/projects/8704) +[![Project Status: Active – The project has reached a stable, usable +state and is being actively +developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) + + +Create and integrate thematic maps in your R workflow. This package +helps to design various cartographic representations such as +proportional symbols, choropleth or typology maps. It also offers +several functions to display layout elements that improve the graphic +presentation of maps (e.g. scale bar, north arrow, title, labels). +`mapsf` maps `sf` objects on `base` graphics. + +## Installation + +You can install the released version of `mapsf` from +[CRAN](https://cran.r-project.org/package=mapsf) with: + +``` r +install.packages("mapsf") +``` + +Alternatively, you can install the development version of `mapsf` from +GitHub (**dev** branch) with: + +``` r +remotes::install_github("riatelab/mapsf", ref = "dev") +``` + +## Usage + +This is a basic example which shows how to create a map with `mapsf`. +The main `mapsf` function is `mf_map()`. + +``` r +library(mapsf) +# Import the sample dataset +mtq <- mf_get_mtq() +# Plot the base map +mf_map(x = mtq) +# Plot proportional symbols +mf_map(x = mtq, var = "POP", type = "prop", leg_pos = "topright") +# Plot a map layout +mf_layout( + title = "Population in Martinique", + credits = "T. Giraud; Sources: INSEE & IGN, 2018" +) +``` + +![](man/figures/example1-1.png) + +A more detailed example: + +``` r +# Export a map with a theme and extra margins +mf_theme("green") +mf_export( + x = mtq, filename = "mtq.png", + width = 600, res = 120, + expandBB = c(0, 0, 0, .3) +) +# Plot a shadow +mf_shadow(mtq, col = "grey10", add = TRUE) +# Plot a choropleth map +mf_map( + x = mtq, var = "MED", type = "choro", + pal = "Dark Mint", + breaks = "quantile", + nbreaks = 6, + leg_title = "Median Income\n(euros)", + leg_val_rnd = -2, + add = TRUE +) +# Start an inset map +mf_inset_on(x = "worldmap", pos = "right") +# Plot mtq position on a worldmap +mf_worldmap(mtq, col = "#0E3F5C") +# Close the inset +mf_inset_off() +# Plot a title +mf_title("Wealth in Martinique, 2015") +# Plot credits +mf_credits("T. Giraud\nSources: INSEE & IGN, 2018") +# Plot a scale bar +mf_scale(size = 5) +# Plot a north arrow +mf_arrow("topleft") +dev.off() +``` + + + +## Resources + + ++++ + + + + + + +
+

+ +

+

+Cheat +Sheet +

+
+

+ +

+

+Website +

+
+ +- `mapsf`, a New Package for Thematic Mapping - useR 2021! + [Video](https://youtu.be/8PMF7cBBH7k?t=2621) & + [Slides](https://rcarto.github.io/user2021/) - FOSS4G 2021 + [Video](https://www.youtube.com/watch?v=dBNp0bzD454) & + [Slides](https://rcarto.github.io/foss4g2021/) (EN) +- [Cartographie avec R](https://rcarto.github.io/cartographie_avec_r/) (FR) + +## Background + +`mapsf` is the successor of +[`cartography`](https://github.com/riatelab/cartography). There are no +plans for new features or enhancements in `cartography`, but basic +maintenance and support will continue indefinitely. Existing projects +that use `cartography` can safely continue to use `cartography`. New +projects should use `mapsf` because it is friendlier, lighter and more +robust. + +## Alternatives + +- [cartography](https://github.com/riatelab/cartography) (*superseded by + `mapsf`*) +- [tmap](https://github.com/r-tmap/tmap) +- [ggplot2](https://github.com/tidyverse/ggplot2) + + [ggspatial](https://github.com/paleolimbot/ggspatial) + +## Community Guidelines + +One can contribute to the package through [pull +requests](https://github.com/riatelab/mapsf/pulls) and report issues or +ask questions [here](https://github.com/riatelab/mapsf/issues). See the +[CONTRIBUTING.md](https://github.com/riatelab/mapsf/blob/master/CONTRIBUTING.md) +file for detailed instructions on how to contribute. +This project uses [conventional +commits](https://www.conventionalcommits.org/en/v1.0.0-beta.3/) and +[semantic versioning](https://semver.org/). diff --git a/docs/_sidebar.md b/docs/_sidebar.md new file mode 100644 index 0000000..e9a7bc0 --- /dev/null +++ b/docs/_sidebar.md @@ -0,0 +1,40 @@ +* [Home](/) +* Vignettes + - [Cheat sheet](vignettes/cheat_sheet) + - [Get started with mapsf](vignettes/mapsf) + - [How to export maps](vignettes/how_to_export_maps) + - [How to use themes](vignettes/how_to_use_themes) + - [How to create faceted maps](vignettes/how_to_create_faceted_maps) + - [How to create inset maps](vignettes/how_to_create_inset_maps) + - [How to use a custom font](vignettes/how_to_use_a_custom_font_family) +* Functions + - Symbology + - [mf_map()](man/mf_map) + - [mf_label()](man/mf_label) + - [mf_raster()](man/mf_raster) + - [mf_graticule()](man/mf_graticule) + - Map layout + - [mf_theme()](man/mf_theme) + - [mf_shadow()](man/mf_shadow) + - [mf_background()](man/mf_background) + - [mf_legend()](man/mf_legend) + - [mf_annotation()](man/mf_annotation) + - [mf_arrow()](man/mf_arrow) + - [mf_credits()](man/mf_credits) + - [mf_layout()](man/mf_layout) + - [mf_title()](man/mf_title) + - [mf_scale()](man/mf_scale) + - [mf_inset_*()](man/mf_inset_on) + - [mf_worldmap()](man/mf_worldmap) + - Utility + - [mf_export()](man/mf_export) + - [mf_distr()](man/mf_distr) + - [mf_get_links()](man/mf_links) + - [mf_get_pal()](man/mf_get_pal) + - [mf_get_breaks()](man/mf_get_breaks) + - [mf_get_mtq()](man/mf_get_mtq) + - [mf_get_ratio()](man/mf_get_ratio) + - [mf_get_pencil()](man/mf_get_pencil) + - [mf_get_borders()](man/mf_get_borders) +* [News](NEWS.md) +* [Citation](CITATION.md) diff --git a/docs/docsify.html b/docs/docsify.html new file mode 100644 index 0000000..f270552 --- /dev/null +++ b/docs/docsify.html @@ -0,0 +1,47 @@ + + + + + + + + + + + + +
+ + + + + + + + diff --git a/docs/docsify.md b/docs/docsify.md new file mode 100644 index 0000000..8e2dff3 --- /dev/null +++ b/docs/docsify.md @@ -0,0 +1,41 @@ +* [Home](/) +* Vignettes + - [Cheat sheet](vignettes/cheat_sheet) + - [Get started with mapsf](vignettes/mapsf) + - [How to export maps](vignettes/how_to_export_maps) + - [How to use themes](vignettes/how_to_use_themes) + - [How to create faceted maps](vignettes/how_to_create_faceted_maps) + - [How to create inset maps](vignettes/how_to_create_inset_maps) + - [How to use a custom font](vignettes/how_to_use_a_custom_font_family) +* Functions + - Symbology + - [mf_map()](man/mf_map) + - [mf_label()](man/mf_label) + - [mf_raster()](man/mf_raster) + - [mf_graticule()](man/mf_graticule) + - Map layout + - [mf_theme()](man/mf_theme) + - [mf_shadow()](man/mf_shadow) + - [mf_background()](man/mf_background) + - [mf_legend()](man/mf_legend) + - [mf_annotation()](man/mf_annotation) + - [mf_arrow()](man/mf_arrow) + - [mf_credits()](man/mf_credits) + - [mf_layout()](man/mf_layout) + - [mf_title()](man/mf_title) + - [mf_scale()](man/mf_scale) + - [mf_inset_*()](man/mf_inset_on) + - [mf_worldmap()](man/mf_worldmap) + - Utility + - [mf_export()](man/mf_export) + - [mf_distr()](man/mf_distr) + - [mf_get_links()](man/mf_links) + - [mf_get_pal()](man/mf_get_pal) + - [mf_get_breaks()](man/mf_get_breaks) + - [mf_get_mtq()](man/mf_get_mtq) + - [mf_get_ratio()](man/mf_get_ratio) + - [mf_get_pencil()](man/mf_get_pencil) + - [mf_get_borders()](man/mf_get_borders) +* [News]($ALTDOC_NEWS) +* [Licence]($ALTDOC_LICENCE) +* [Citation]($ALTDOC_CITATION) diff --git a/docs/freeze.rds b/docs/freeze.rds new file mode 100644 index 0000000..303da19 Binary files /dev/null and b/docs/freeze.rds differ diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..3573f13 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,47 @@ + + + + + + + + + + + + +
+ + + + + + + + diff --git a/docs/man/figures/example1-1.png b/docs/man/figures/example1-1.png new file mode 100644 index 0000000..8b804f3 Binary files /dev/null and b/docs/man/figures/example1-1.png differ diff --git a/docs/man/figures/features.png b/docs/man/figures/features.png new file mode 100644 index 0000000..8bdd5e8 Binary files /dev/null and b/docs/man/figures/features.png differ diff --git a/docs/man/figures/logo.png b/docs/man/figures/logo.png new file mode 100644 index 0000000..3b60878 Binary files /dev/null and b/docs/man/figures/logo.png differ diff --git a/docs/man/figures/mapsf_cheatsheet.png b/docs/man/figures/mapsf_cheatsheet.png new file mode 100644 index 0000000..4d3102f Binary files /dev/null and b/docs/man/figures/mapsf_cheatsheet.png differ diff --git a/docs/man/figures/mtq.png b/docs/man/figures/mtq.png new file mode 100644 index 0000000..cdefcce Binary files /dev/null and b/docs/man/figures/mtq.png differ diff --git a/docs/man/figures/website.png b/docs/man/figures/website.png new file mode 100644 index 0000000..4130851 Binary files /dev/null and b/docs/man/figures/website.png differ diff --git a/docs/man/mapsf.md b/docs/man/mapsf.md new file mode 100644 index 0000000..60c0d8e --- /dev/null +++ b/docs/man/mapsf.md @@ -0,0 +1,215 @@ + + +# Package description + +## Description + +Create and integrate thematic maps in your workflow. This package helps +to design various cartographic representations such as proportional +symbols, choropleth or typology maps. It also offers several functions +to display layout elements that improve the graphic presentation of maps +(e.g. scale bar, north arrow, title, labels). mapsf maps +sf objects on base graphics. + +A "Get Started" vignette contains commented scripts on +how to create various maps: vignette(topic = “mapsf”, package = +“mapsf”) + +## Symbology + +These functions display cartographic layers. + +
    +
  • + +mf_map() Plot a map + +
  • +
  • + +mf_label() Plot labels + +
  • +
  • + +mf_raster() Plot a raster + +
  • +
  • + +mf_graticule() Plot graticules + +
  • +
+ +## Map layout + +These functions are dedicated to the map layout design. + +
    +
  • + +mf_theme() Set a theme + +
  • +
  • + +mf_shadow() Plot a shadow + +
  • +
  • + +mf_background() Plot a background image + +
  • +
  • + +mf_annotation() Plot an annotation + +
  • +
  • + +mf_arrow() Plot a north arrow + +
  • +
  • + +mf_credits() Plot credits + +
  • +
  • + +mf_layout() Plot a map layout + +
  • +
  • + +mf_title() Plot a title + +
  • +
  • + +mf_scale() Plot a scale bar + +
  • +
  • + +mf_inset_on() / mf_inset_off() Plot an inset + +
  • +
  • + +mf_worldmap() Plot a point on a world map + +
  • +
  • + +mf_legend() Plot a legend + +
  • +
+ +## Utility functions + +
    +
  • + +mf_export() Export a map + +
  • +
  • + +mf_distr() Plot a distribution + +
  • +
  • + +mf_get_links() Get a link layer from a data.frame of links + +
  • +
  • + +mf_get_pal() Get color palettes + +
  • +
  • + +mf_get_breaks() Get class intervals + +
  • +
  • + +mf_get_mtq() Get the ‘mtq’ dataset + +
  • +
  • + +mf_get_ratio() Get map width and height values + +
  • +
  • + +mf_get_pencil() Get a pencil layer from polygons + +
  • +
  • + +mf_get_borders() Get a border layer from polygons + +
  • +
+ +## Author(s) + +Maintainer: Timothée Giraud +timothee.giraud@cnrs.fr +(ORCID) + +Other contributors: + +
    +
  • + +Hugues Pecout +(ORCID) (Logo) +\[contributor\] + +
  • +
  • + +Ronan Ysebaert +(ORCID) (Cheat +sheet) \[contributor\] + +
  • +
  • + +Ian Fellows (No overlap algorithm for labels, from wordcloud package) +\[copyright holder\] + +
  • +
  • + +Jim Lemon (Arc drawing algorithm for annotations, from plotrix package) +\[copyright holder\] + +
  • +
+ +## See Also + +Useful links: + + diff --git a/docs/man/mf_annotation.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_annotation.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..dfaadd7 Binary files /dev/null and b/docs/man/mf_annotation.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_annotation.md b/docs/man/mf_annotation.md new file mode 100644 index 0000000..ccd2790 --- /dev/null +++ b/docs/man/mf_annotation.md @@ -0,0 +1,137 @@ + + +# Plot an annotation + +## Description + +Plot an annotation on a map. + +## Usage + +
mf_annotation(
+  x,
+  txt,
+  pos = "topright",
+  cex = 0.8,
+  col_arrow,
+  col_txt,
+  halo = FALSE,
+  bg,
+  s = 1,
+  ...
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +an sf object with 1 row, a couple of coordinates (c(x, y)) or +"interactive" +
+txt + +the text to display +
+pos + +position of the text, one of "topleft", "topright", "bottomright", +"bottomleft" +
+cex + +size of the text +
+col_arrow + +arrow color +
+col_txt + +text color +
+halo + +add a halo around the text +
+bg + +halo color +
+s + +arrow size (min=1) +
+ + +further text arguments. +
+ +## Value + +No return value, an annotation is displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_annotation( + x = c(711167.8, 1614764), + txt = "Look!\nImportant feature\nhere!", + pos = "bottomleft", cex = 1.2, font = 2, + halo = TRUE, s = 1.5 +) + +mf_annotation( + x = mtq[20, ], + txt = "This is less\nimportant", + cex = .7, font = 3, s = 1.3 +) +``` + +![](mf_annotation.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_arrow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_arrow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..e4b1ee5 Binary files /dev/null and b/docs/man/mf_arrow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_arrow.md b/docs/man/mf_arrow.md new file mode 100644 index 0000000..b1d50b1 --- /dev/null +++ b/docs/man/mf_arrow.md @@ -0,0 +1,82 @@ + + +# Plot a north arrow + +## Description + +Plot a north arrow. + +## Usage + +
mf_arrow(
+  pos = "topleft",
+  col = getOption("mapsf.fg"),
+  cex = 1,
+  adj = c(0, 0),
+  align
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + +
+pos + +position. It can be one of ‘topleft’, ‘top’,‘topright’, ‘right’, +‘bottomright’, ‘bottom’,‘bottomleft’, ‘left’, ‘interactive’ or a vector +of two coordinates in map units (c(x, y)) +
+col + +arrow color +
+cex + +arrow size +
+adj + +adjust the postion of the north arrow in x and y directions +
+align + +object of class sf or sfc used to adjust the +arrow to the real north +
+ +## Value + +No return value, a north arrow is displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_arrow(pos = "topright") +``` + +![](mf_arrow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_background.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_background.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..0f66826 Binary files /dev/null and b/docs/man/mf_background.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_background.md b/docs/man/mf_background.md new file mode 100644 index 0000000..a7ce280 --- /dev/null +++ b/docs/man/mf_background.md @@ -0,0 +1,54 @@ + + +# Plot a background image + +## Description + +Plot a background image on an existing plot + +## Usage + +
mf_background(filename, ...)
+
+ +## Arguments + + + + + + + + + + +
+filename + +filename of the background image, PNG or JPG/JPEG format. +
+ + +further parameters for rasterImage +
+ +## Value + +No return value, a background image is displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq, col = NA, border = NA) +mf_background(system.file("img/background.jpg", package = "mapsf")) +mf_map(mtq, lwd = 3, col = NA, border = "white", add = TRUE) +mf_credits( + txt = "Background photo by Noita Digital on Unsplash", + col = "white" +) +``` + +![](mf_background.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_credits.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_credits.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..ce767ee Binary files /dev/null and b/docs/man/mf_credits.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_credits.md b/docs/man/mf_credits.md new file mode 100644 index 0000000..873f4b9 --- /dev/null +++ b/docs/man/mf_credits.md @@ -0,0 +1,88 @@ + + +# Plot credits + +## Description + +Plot credits (sources, author, year…). + +## Usage + +
mf_credits(
+  txt = "Source(s) & Author(s)",
+  pos = "bottomleft",
+  col,
+  cex = 0.6,
+  font = 3,
+  bg = NA
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + +
+txt + +text of the credits, use ‘’ to add line breaks +
+pos + +position, one of ‘bottomleft’, ‘bottomright’ or ‘rightbottom’ +
+col + +color +
+cex + +cex of the credits +
+font + +font of the credits +
+bg + +background color +
+ +## Value + +No return value, credits are displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_credits(txt = "Author\nSources - Year") +``` + +![](mf_credits.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..e978ef8 Binary files /dev/null and b/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..022f0eb Binary files /dev/null and b/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..e1a8194 Binary files /dev/null and b/docs/man/mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_distr.md b/docs/man/mf_distr.md new file mode 100644 index 0000000..139007d --- /dev/null +++ b/docs/man/mf_distr.md @@ -0,0 +1,75 @@ + + +# Plot a distribution + +## Description + +This function displays a histogram, a box plot, a strip chart and a +density curve on the same plot. + +## Usage + +
mf_distr(x, nbins, bw)
+
+ +## Arguments + + + + + + + + + + + + + + +
+x + +a numeric variable +
+nbins + +number of bins in the histogram +
+bw + +bandwidth of the density curve +
+ +## Value + +The number of bins of the histogram and the bandwidth of the density +curve are (invisibly) returned in a list. + +## Examples + +``` r +library("mapsf") + +(mf_distr(rnorm(1000))) +``` + +![](mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + + $bw + [1] 0.2493926 + + $nbins + [1] 12 + +``` r +mf_distr(rbeta(1000, .6, 7)) +``` + +![](mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +``` r +mf_distr(rbeta(1000, 5, .6)) +``` + +![](mf_distr.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) diff --git a/docs/man/mf_export.md b/docs/man/mf_export.md new file mode 100644 index 0000000..f6f1769 --- /dev/null +++ b/docs/man/mf_export.md @@ -0,0 +1,116 @@ + + +# Export a map + +## Description + +Export a map with the extent of a spatial object.
The map is +exported in PNG or SVG format.
If only one of width +or height is set, mf_export uses the +width/height ratio of x bounding box to find a matching +ratio for the export.
Always use add = TRUE in +mf_map calls following an mf_export +call.
Use dev.off to finish the export (see +Examples). + +## Usage + +
mf_export(
+  x,
+  filename = "map.png",
+  width,
+  height,
+  res = 96,
+  ...,
+  expandBB = rep(0, 4)
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +object of class sf, sfc or +SpatRaster +
+filename + +path to the exported file. If the file extention is ".png" a png graphic +device is opened, if the file extension is ".svg" a svg graphic device +is opened. +
+width + +width of the figure (pixels for png, inches for svg) +
+height + +height of the figure (pixels for png, inches for svg) +
+res + +resolution (for png) +
+ + +further parameters for png or svg export +
+expandBB + +fractional values to expand the bounding box with, in each direction +(bottom, left, top, right) +
+ +## Value + +No return value, a map file is initiated (in PNG or SVG format). + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +(filename <- tempfile(fileext = ".png")) +``` + + [1] "/tmp/Rtmp7qqK5S/file2528711451f0e.png" + +``` r +mf_export(mtq, filename = filename) +mf_map(mtq, add = TRUE) +dev.off() +``` + + png + 2 diff --git a/docs/man/mf_get_borders.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_get_borders.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..91d5eff Binary files /dev/null and b/docs/man/mf_get_borders.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_get_borders.md b/docs/man/mf_get_borders.md new file mode 100644 index 0000000..77bb6e5 --- /dev/null +++ b/docs/man/mf_get_borders.md @@ -0,0 +1,50 @@ + + +# Get a border layer from polygons + +## Description + +This function extracts borders between contiguous polygons. + +## Usage + +
mf_get_borders(x)
+
+ +## Arguments + + + + + + +
+x + +an sf object of POLYGONS, using a projected CRS +
+ +## Value + +An sf object (MULTILINESTRING) of borders is returned. + +## Note + +If the polygon layer contains topology errors (such as contiguous +polygons not sharing exactly the same boundary) the function may not +return all boundaries correctly. It is possible to use +st_snap() or other functions to try and correct these +errors. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mtq_b <- mf_get_borders(mtq) +mf_map(mtq) +mf_map(mtq_b, col = 1:5, lwd = 4, add = TRUE) +``` + +![](mf_get_borders.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_get_breaks.md b/docs/man/mf_get_breaks.md new file mode 100644 index 0000000..bc8f13a --- /dev/null +++ b/docs/man/mf_get_breaks.md @@ -0,0 +1,143 @@ + + +# Get class intervals + +## Description + +A function to classify continuous variables. + +This function is a wrapper for classIntervals with some +additional methods. + +## Usage + +
mf_get_breaks(x, nbreaks, breaks, k = 1, central = FALSE, ...)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +a vector of numeric values. NA and Inf values are not used in the +classification. +
+nbreaks + +a number of classes +
+breaks + +a classification method; one of "fixed", "sd", "equal", "pretty", +"quantile", "kmeans", "hclust", "bclust", "fisher", "jenks", "dpih", +"q6", "Q6", geom", "arith", "em", "msd" or "ckmeans" (see Details) +
+k + +number of standard deviation for "msd" method (see Details) +
+central + +creation of a central class for "msd" method (see Details) +
+ + +further arguments of classIntervals +
+ +## Details + +"fixed", "sd", "equal", "pretty", "quantile", "kmeans", "hclust", +"bclust", "fisher", "jenks" and "dpih" are classIntervals +methods. You may need to pass additional arguments for some of +them.

+ +The "jenks", "fisher" and "ckmeans" methods are based on the same +concept of natural breaks and and produce similar +groupings. + +
    +
  • + +The "jenks" method produces class boundaries falling on data points and +is slow. + +
  • +
  • + +The "fisher" method produces class boundaries located more conveniently +between data points, and is faster than the "jenks" method. + +
  • +
  • + +The "ckmeans" method produces exactly the same class boundaries as the +"fisher" method, but is much faster. It uses the optimal univariate +k-means method from the Ckmeans.1d.dp package. If the +"ckmeans" method is selected but the Ckmeans.1d.dp package +is not installed then the "fisher" method is used. + +
  • +
+ +The relative speeds of these three methods may vary depending on the +number of data points and the number of classes.

+ +The "q6" method uses the following quantile probabilities: +0, 0.05, 0.275, 0.5, 0.725, 0.95, 1.

The "Q6" method uses +the following quantile probabilities: 0, 0.05, 0.25, 0.5, +0.75, 0.95, 1.

The "geom" method is based on a geometric +progression along the variable values, all values must be strictly +greater than zero.

The "arith" method is based on an +arithmetic progression along the variable values.

The "em" +method is based on nested averages computation.

The "msd" +method is based on the mean and the standard deviation of a numeric +vector. The nbreaks parameter is not relevant, use +k and central instead. k +indicates the extent of each class in share of standard deviation. If +central=TRUE then the mean value is the center of a class +else the mean is a break value. + +## Value + +A numeric vector of breaks + +## See Also + +classIntervals + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_get_breaks(x = mtq$MED, nbreaks = 6, breaks = "quantile") +``` + + [1] 11929.0 13667.0 14786.0 15685.5 16860.0 18622.0 21761.0 diff --git a/docs/man/mf_get_links.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_get_links.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..994143d Binary files /dev/null and b/docs/man/mf_get_links.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_get_links.md b/docs/man/mf_get_links.md new file mode 100644 index 0000000..663ab0a --- /dev/null +++ b/docs/man/mf_get_links.md @@ -0,0 +1,74 @@ + + +# Get a link layer from a data.frame of links + +## Description + +Create a link layer from a data.frame of links and an sf object. + +## Usage + +
mf_get_links(x, df, x_id, df_id)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + +
+x + +an sf object, a simple feature collection. +
+df + +a data.frame that contains identifiers of starting and ending points. +
+x_id + +name of the identifier variable in x, default to the first column +(optional) +
+df_id + +names of the identifier variables in df, character vector of length 2, +default to the two first columns. (optional) +
+ +## Value + +An sf object is returned, it is composed of df and the sfc (LINESTRING) +of links. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mob <- read.csv(system.file("csv/mob.csv", package = "mapsf")) +# Select links from Fort-de-France (97209)) +mob_97209 <- mob[mob$i == 97209, ] +# Create a link layer +mob_links <- mf_get_links(x = mtq, df = mob_97209) +# Plot the links +mf_map(mtq) +mf_map(mob_links, col = "red4", lwd = 2, add = TRUE) +``` + +![](mf_get_links.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_get_mtq.md b/docs/man/mf_get_mtq.md new file mode 100644 index 0000000..e960f65 --- /dev/null +++ b/docs/man/mf_get_mtq.md @@ -0,0 +1,29 @@ + + +# Get the ‘mtq’ dataset + +## Description + +Import the mtq dataset (Martinique municipalities). + +## Usage + +
mf_get_mtq()
+
+ +## Details + +This a wrapper around st_read(system.file(“gpkg/mtq.gpkg”, package += “mapsf”),quiet = TRUE). + +## Value + +an sf object of Martinique municipalities + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +``` diff --git a/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..83b2f93 Binary files /dev/null and b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..2c798a5 Binary files /dev/null and b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..48e5406 Binary files /dev/null and b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png new file mode 100644 index 0000000..b7b5fd2 Binary files /dev/null and b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png differ diff --git a/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png new file mode 100644 index 0000000..3e3904a Binary files /dev/null and b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png differ diff --git a/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png new file mode 100644 index 0000000..d54c634 Binary files /dev/null and b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png differ diff --git a/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png new file mode 100644 index 0000000..347053f Binary files /dev/null and b/docs/man/mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png differ diff --git a/docs/man/mf_get_pal.md b/docs/man/mf_get_pal.md new file mode 100644 index 0000000..f7fd022 --- /dev/null +++ b/docs/man/mf_get_pal.md @@ -0,0 +1,131 @@ + + +# Get color palettes + +## Description + +mf_get_pal builds sequential, diverging and qualitative +color palettes. Diverging color palettes can be dissymmetric (different +number of colors in each of the two gradients). + +## Usage + +
mf_get_pal(n, palette, alpha = NULL, rev = c(FALSE, FALSE), neutral)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + +
+n + +the number of colors (\>= 1) to be in the palette +
+palette + +a valid palette name. See hcl.pals to get available palette names. The +name is matched to the list of available palettes, ignoring upper +vs. lower case, spaces, dashes, etc. in the matching. +
+alpha + +an alpha-transparency level in the range \[0,1\] (0 means transparent +and 1 means opaque) +
+rev + +logical indicating whether the ordering of the colors should be reversed +
+neutral + +a color, if two gradients are used, the ‘neutral’ color can be added +between them +
+ +## Value + +A vector of colors. + +## Examples + +``` r +library("mapsf") + +cols <- mf_get_pal(n = 10, pal = "Reds 2") +plot(1:10, rep(1, 10), bg = cols, pch = 22, cex = 4) +``` + +![](mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +``` r +cols <- mf_get_pal(n = c(3, 7), pal = c("Reds 2", "Greens")) +plot(1:10, rep(1, 10), bg = cols, pch = 22, cex = 4) +``` + +![](mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +``` r +cols <- mf_get_pal(n = c(5, 5), pal = c("Reds 2", "Greens")) +plot(1:10, rep(1, 10), bg = cols, pch = 22, cex = 4) +``` + +![](mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) + +``` r +cols <- mf_get_pal(n = c(7, 3), pal = c("Reds 2", "Greens")) +plot(1:10, rep(1, 10), bg = cols, pch = 22, cex = 4) +``` + +![](mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png) + +``` r +cols <- mf_get_pal( + n = c(5, 5), pal = c("Reds 2", "Greens"), + neutral = "grey" +) +plot(1:11, rep(1, 11), bg = cols, pch = 22, cex = 4) +``` + +![](mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png) + +``` r +opar <- par(bg = "black") +cols <- mf_get_pal( + n = c(7, 3), pal = c("Reds 2", "Greens"), + alpha = c(.3, .7) +) +plot(1:10, rep(1, 10), bg = cols, pch = 22, cex = 4) +``` + +![](mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png) + +``` r +par(opar) +cols <- mf_get_pal( + n = c(5, 5), pal = c("Reds 2", "Greens"), + rev = c(TRUE, TRUE) +) +plot(1:10, rep(1, 10), bg = cols, pch = 22, cex = 4) +``` + +![](mf_get_pal.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png) diff --git a/docs/man/mf_get_pencil.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_get_pencil.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..1b70495 Binary files /dev/null and b/docs/man/mf_get_pencil.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_get_pencil.md b/docs/man/mf_get_pencil.md new file mode 100644 index 0000000..3c183b6 --- /dev/null +++ b/docs/man/mf_get_pencil.md @@ -0,0 +1,78 @@ + + +# Get a pencil layer from polygons + +## Description + +Create a pencil layer. This function transforms a POLYGON or +MULTIPOLYGON sf object into a MULTILINESTRING one. + +## Usage + +
mf_get_pencil(x, size = 100, buffer = 0, lefthanded = TRUE, clip = FALSE)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + +
+x + +an sf object, a simple feature collection (POLYGON or MULTIPOLYGON). +
+size + +density of the penciling. Median number of points used to build the +MULTILINESTRING. +
+buffer + +buffer around each polygon. This buffer (in map units) is used to take +sample points. A negative value adds a margin between the penciling and +the original polygons borders +
+lefthanded + +if TRUE the penciling is done left-handed style. +
+clip + +if TRUE, the penciling is cut by the original polygon. +
+ +## Value + +A MULTILINESTRING sf object is returned. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mtq_pencil <- mf_get_pencil(x = mtq, clip = FALSE) +mf_map(mtq) +mf_map(mtq_pencil, add = TRUE) +``` + +![](mf_get_pencil.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_get_ratio.md b/docs/man/mf_get_ratio.md new file mode 100644 index 0000000..c4c95f5 --- /dev/null +++ b/docs/man/mf_get_ratio.md @@ -0,0 +1,95 @@ + + +# Get map width and height values + +## Description + +This function is to be used to get width and height values for maps +created in reports (*.Rmd, *.qmd).
It uses the width / height +ratio of a spatial object bounding box to find a matching ratio for the +map.
If width is specified, then height is deduced from the width +/ height ratio of x, figure margins and title size.
If height is +specified, then width is deduced from the width / height ratio of x, +figure margins and title size. + +## Usage + +
mf_get_ratio(
+  x,
+  width,
+  height,
+  res = 96,
+  expandBB = rep(0, 4),
+  theme = mf_theme()
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +object of class sf, sfc or +SpatRaster +
+width + +width of the figure (inches), use only one of width or height +
+height + +height of the figure (inches), use only one of width or height +
+res + +resolution +
+expandBB + +fractional values to expand the bounding box with, in each direction +(bottom, left, top, right) +
+theme + +theme used for the map +
+ +## Value + +Width and height are returned in inches. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_get_ratio(x = mtq, width = 5) +``` + + [1] 5.00 6.06 diff --git a/docs/man/mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..7971691 Binary files /dev/null and b/docs/man/mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..672a823 Binary files /dev/null and b/docs/man/mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_graticule.md b/docs/man/mf_graticule.md new file mode 100644 index 0000000..3578f5d --- /dev/null +++ b/docs/man/mf_graticule.md @@ -0,0 +1,145 @@ + + +# Plot graticules + +## Description + +Display graticules and labels on a map. + +## Usage + +
mf_graticule(
+  x,
+  col = col,
+  lwd = 1,
+  lty = 1,
+  expandBB = rep(0, 4),
+  label = TRUE,
+  pos = c("top", "left"),
+  cex = 0.7,
+  add = TRUE
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +object of class sf, sfc or +SpatRaster +
+col + +graticules and label color +
+lwd + +graticules line width +
+lty + +graticules line type +
+expandBB + +fractional values to expand the bounding box with, in each direction +(bottom, left, top, right) +
+label + +whether to add labels (TRUE) or not (FALSE) +
+pos + +labels positions ("bottom", "left", "top" and / or "right") +
+cex + +labels size +
+add + +whether to add the layer to an existing plot (TRUE) or not (FALSE) +
+ +## Value + +An (invisible) layer of graticules is returned (LINESTRING). + +## Use of graticules + +From st_graticule: "In cartographic visualization, the use +of graticules is not advised, unless the graphical output will be used +for measurement or navigation, or the direction of North is important +for the interpretation of the content, or the content is intended to +display distortions and artifacts created by projection. Unnecessary use +of graticules only adds visual clutter but little relevant information. +Use of coastlines, administrative boundaries or place names permits most +viewers of the output to orient themselves better than a graticule." + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq, expandBB = c(0, .1, .1, 0)) +mf_graticule(mtq) +``` + +![](mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +``` r +mf_graticule( + x = mtq, + col = "coral4", + lwd = 2, + lty = 2, + expandBB = c(.1, 0, 0, .1), + label = TRUE, + pos = c("right", "bottom"), + cex = .8, + add = FALSE +) +mf_map(mtq, add = TRUE) +``` + +![](mf_graticule.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) diff --git a/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..c24b8f2 Binary files /dev/null and b/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..5dbec99 Binary files /dev/null and b/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..3da76ae Binary files /dev/null and b/docs/man/mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_inset_on.md b/docs/man/mf_inset_on.md new file mode 100644 index 0000000..8d9c466 --- /dev/null +++ b/docs/man/mf_inset_on.md @@ -0,0 +1,99 @@ + + +# Plot an inset + +## Description + +This function is used to add an inset map to the current map. + +## Usage + +
mf_inset_on(x, pos = "topright", cex = 0.2, fig)
+
+mf_inset_off()
+
+ +## Arguments + + + + + + + + + + + + + + + + + + +
+x + +an sf object, or "worldmap" to use with mf_worldmap. +
+pos + +position, one of "bottomleft", "left", "topleft", "top", "bottom", +"bottomright", "right", "topright" +
+cex + +share of the map width occupied by the inset +
+fig + +coordinates of the inset region (in NDC, see in ?par()) +
+ +## Details + +If x is used (with pos and cex), the width/height ratio of the inset +will match the width/height ratio of x bounding box.
If fig is +used, coordinates (xmin, xmax, ymin, ymax) are expressed as fractions of +the mapping space (i.e. excluding margins).
If map layers have to +be plotted after the inset (i.e after mf_inset_off()), please use add = +TRUE.
It is not possible to plot an inset within an inset.
+It is possible to plot anything (base plots) within the inset, not only +map layers. + +## Value + +No return value, an inset is initiated or closed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_inset_on(x = mtq[1, ], cex = .2) +mf_map(mtq[1, ]) +mf_inset_off() +``` + +![](mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +``` r +mf_map(mtq) +mf_inset_on(x = "worldmap", pos = "bottomleft") +mf_worldmap(x = mtq) +mf_inset_off() +``` + +![](mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +``` r +mf_map(mtq) +mf_inset_on(fig = c(0, 0.25, 0, 0.25)) +mf_map(x = mtq) +mf_inset_off() +``` + +![](mf_inset_on.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) diff --git a/docs/man/mf_label.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_label.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..6c22c2f Binary files /dev/null and b/docs/man/mf_label.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_label.md b/docs/man/mf_label.md new file mode 100644 index 0000000..9eca757 --- /dev/null +++ b/docs/man/mf_label.md @@ -0,0 +1,142 @@ + + +# Plot labels + +## Description + +Put labels on a map. + +## Usage + +
mf_label(
+  x,
+  var,
+  col,
+  cex = 0.7,
+  overlap = TRUE,
+  lines = TRUE,
+  halo = FALSE,
+  bg,
+  r = 0.1,
+  q = 1,
+  ...
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +object of class sf +
+var + +name(s) of the variable(s) to plot +
+col + +labels color, it can be a single color or a vector of colors +
+cex + +labels cex, it can be a single size or a vector of sizes +
+overlap + +if FALSE, labels are moved so they do not overlap. +
+lines + +if TRUE, then lines are plotted between x,y and the word, for those +words not covering their x,y coordinate +
+halo + +if TRUE, a ‘halo’ is displayed around the text and additional arguments +bg and r can be modified to set the color and width of the halo. +
+bg + +halo color, it can be a single color or a vector of colors +
+r + +width of the halo, it can be a single value or a vector of values +
+q + +quality of the non overlapping labels placement. Possible values are 0 +(quick results), 1 (reasonable quality and speed), 2 (better quality), 3 +(insane quality, can take a lot of time). +
+ + +further text arguments. +
+ +## Value + +No return value, labels are displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mtq$cex <- c(rep(.8, 8), 2, rep(.8, 25)) +mf_label( + x = mtq, var = "LIBGEO", + col = "grey10", halo = TRUE, cex = mtq$cex, + overlap = FALSE, lines = FALSE +) +``` + +![](mf_label.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_layout.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_layout.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..ba1f4d0 Binary files /dev/null and b/docs/man/mf_layout.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_layout.md b/docs/man/mf_layout.md new file mode 100644 index 0000000..48eebaa --- /dev/null +++ b/docs/man/mf_layout.md @@ -0,0 +1,82 @@ + + +# Plot a map layout + +## Description + +Plot a map layout (title, credits, scalebar, north arrow, frame). + +This function uses mf_title, mf_credits, +mf_scale and mf_arrow with default values. + +## Usage + +
mf_layout(
+  title = "Map Title",
+  credits = "Authors & Sources",
+  scale = TRUE,
+  arrow = TRUE,
+  frame = FALSE
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + +
+title + +title of the map +
+credits + +credits +
+scale + +display a scale bar +
+arrow + +display an arrow +
+frame + +display a frame +
+ +## Value + +No return value, a map layout is displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_layout() +``` + +![](mf_layout.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_legend.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_legend.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..2621b87 Binary files /dev/null and b/docs/man/mf_legend.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_legend.md b/docs/man/mf_legend.md new file mode 100644 index 0000000..bf313be --- /dev/null +++ b/docs/man/mf_legend.md @@ -0,0 +1,447 @@ + + +# Plot a legend + +## Description + +Plot different types of legend. The "type" argument defines the legend +type. Please note that some arguments are available for all types of +legend and some others are only relevant for specific legend types (see +Details). mf_legend() is a wrapper for +maplegend::leg(). + +## Usage + +
mf_legend(
+  type,
+  val,
+  pos = "left",
+  pal = "Inferno",
+  alpha = 1,
+  col = "tomato4",
+  inches = 0.3,
+  symbol = "circle",
+  self_adjust = FALSE,
+  lwd = 0.7,
+  border = "#333333",
+  pch = seq_along(val),
+  cex = rep(1, length(val)),
+  title = "Legend Title",
+  title_cex = 0.8 * size,
+  val_cex = 0.6 * size,
+  val_rnd = 0,
+  col_na = "white",
+  cex_na = 1,
+  pch_na = 4,
+  no_data = FALSE,
+  no_data_txt = "No Data",
+  box_border = "#333333",
+  box_cex = c(1, 1),
+  horiz = FALSE,
+  frame_border,
+  frame = FALSE,
+  bg,
+  fg,
+  size = 1,
+  return_bbox = FALSE,
+  adj = c(0, 0)
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+type + + +type of legend: + +
    +
  • + +prop for proportional symbols, + +
  • +
  • + +choro for choropleth maps, + +
  • +
  • + +cont for continuous maps (e.g. raster), + +
  • +
  • + +typo for typology maps, + +
  • +
  • + +symb for symbols maps, + +
  • +
  • + +prop_line for proportional lines maps, + +
  • +
  • + +grad_line for graduated lines maps. + +
  • +
+
+val + +vector of value(s) (for "prop" and "prop_line", at least c(min, max) for +"cont"), vector of categories (for "symb" and "typo"), break labels (for +"choro" and "grad_line"). +
+pos + +position of the legend. It can be one of ‘topleft’, ‘top’, ‘topright’, +‘right’, ‘bottomright’, ‘bottom’,‘bottomleft’, ‘left’, ‘interactive’ or +a vector of two coordinates in map units (c(x, y)). +
+pal + +a color palette name or a vector of colors +
+alpha + +if pal is a hcl.colors palette name, the alpha-transparency +level in the range \[0,1\] +
+col + +color of the symbols (for "prop") or color of the lines (for "prop_line" +and "grad_line") +
+inches + +size of the largest symbol (radius for circles, half width for squares) +in inches +
+symbol + +type of symbols, ‘circle’ or ‘square’ +
+self_adjust + +if TRUE values are self-adjusted to keep min, max and intermediate +rounded values +
+lwd + +width(s) of the symbols borders (for "prop" and "symb"), width of the +largest line (for "prop_line"), vector of line width (for "grad_line") +
+border + +symbol border color(s) +
+pch + +type(s) of the symbols (0:25) +
+cex + +size(s) of the symbols +
+title + +title of the legend +
+title_cex + +size of the legend title +
+val_cex + +size of the values in the legend +
+val_rnd + +number of decimal places of the values in the legend +
+col_na + +color for missing values +
+cex_na + +size of the symbols for missing values +
+pch_na + +type of the symbols for missing values +
+no_data + +if TRUE a "missing value" box is plotted +
+no_data_txt + +label for missing values +
+box_border + +border color of legend boxes +
+box_cex + +width and height size expansion of boxes, (or offset between circles for +"prop" legends with horiz = TRUE) +
+horiz + +if TRUE plot an horizontal legend +
+frame_border + +border color of the frame +
+frame + +if TRUE the legend is plotted within a frame +
+bg + +background color of the legend +
+fg + +foreground color of the legend +
+size + +size of the legend; 2 means two times bigger +
+return_bbox + +return only bounding box of the legend. No legend is plotted. +
+adj + +adjust the postion of the legend in x and y directions +
+ +## Details + +Some arguments are available for all types of legend: val, +pos, title, title_cex, +val_cex, frame, bg, +fg, size, adj, +return_bbox). + +Relevant arguments for each specific legend types: + +
    +
  • + +mf_legend(type = “prop”, val, inches, symbol, col, lwd, border, +val_rnd, self_adjust, horiz) + +
  • +
  • + +mf_legend(type = “choro”, val, pal, val_rnd, col_na, no_data, +no_data_txt, box_border, horiz) + +
  • +
  • + +mf_legend(type = “cont”, val, pal, val_rnd, col_na, no_data, +no_data_txt, box_border, horiz) + +
  • +
  • + +mf_legend(type = “typo”, val, pal, col_na, no_data, no_data_txt, +box_border) + +
  • +
  • + +mf_legend(type = “symb”, val, pal, pch, cex, lwd, pch_na, cex_na, +col_na, no_data, no_data_txt) + +
  • +
  • + +mf_legend(type = “prop_line”, val, col, lwd, val_rnd) + +
  • +
  • + +mf_legend(type = “grad_line”, val, col, lwd, val_rnd) + +
  • +
+ +## Value + +No value is returned, a legend is displayed (except if +return_bbox is used). + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_legend(type = "prop", pos = "topright", val = c(1, 5, 10), inches = .3) +mf_legend( + type = "choro", pos = "bottomright", val = c(10, 20, 30, 40, 50), + pal = hcl.colors(4, "Reds 2") +) +mf_legend( + type = "typo", pos = "topleft", val = c("A", "B", "C", "D"), + pal = hcl.colors(4, "Dynamic") +) +mf_legend( + type = "symb", pos = "bottomleft", val = c("A", "B", "C"), + pch = 21:23, cex = c(1, 2, 2), + pal = hcl.colors(3, "Dynamic") +) +mf_legend( + type = "grad_line", pos = "top", val = c(1, 2, 3, 4, 10, 15), + lwd = c(0.2, 2, 4, 5, 10) +) +mf_legend(type = "prop_line", pos = "bottom", lwd = 20, val = c(5, 50, 100)) +``` + +![](mf_legend.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..312870b Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-10.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-10.png new file mode 100644 index 0000000..f251b4c Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-10.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-11.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-11.png new file mode 100644 index 0000000..35355e0 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-11.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-12.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-12.png new file mode 100644 index 0000000..199f164 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-12.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-13.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-13.png new file mode 100644 index 0000000..c82049d Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-13.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-14.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-14.png new file mode 100644 index 0000000..2163f8e Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-14.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-15.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-15.png new file mode 100644 index 0000000..0ebffc4 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-15.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-16.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-16.png new file mode 100644 index 0000000..3a0dc08 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-16.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-17.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-17.png new file mode 100644 index 0000000..cd6b44c Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-17.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..62a812e Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..0a83957 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png new file mode 100644 index 0000000..041f4c3 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png new file mode 100644 index 0000000..22afec3 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png new file mode 100644 index 0000000..3d34d95 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png new file mode 100644 index 0000000..6f5e3bb Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-8.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-8.png new file mode 100644 index 0000000..16c0344 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-8.png differ diff --git a/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-9.png b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-9.png new file mode 100644 index 0000000..6770058 Binary files /dev/null and b/docs/man/mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-9.png differ diff --git a/docs/man/mf_map.md b/docs/man/mf_map.md new file mode 100644 index 0000000..db2b6d2 --- /dev/null +++ b/docs/man/mf_map.md @@ -0,0 +1,801 @@ + + +# Plot a map + +## Description + +mf_map() is the main function of the package, it displays +map layers on a georeferenced plot. + +mf_map() has three main arguments: + +
    +
  • + +x, an sf object; + +
  • +
  • + +var, the name(s) of a variable(s) to map; + +
  • +
  • + +type, the map layer type. + +
  • +
+ +Many parameters are available to fine tune symbologies and legends. + +Relevant arguments and default values are different for each map type +and are described in the "Details" section. + +## Usage + +
mf_map(x, var, type = "base",
+       breaks, nbreaks, pal, alpha, rev, inches, val_max, symbol, col,
+       lwd_max, val_order, pch, cex, border, lwd, col_na, cex_na, pch_na,
+       expandBB, add,
+       leg_pos, leg_title, leg_title_cex, leg_val_cex, leg_val_rnd,
+       leg_no_data, leg_frame, leg_frame_border, leg_horiz, leg_adj, leg_bg,
+       leg_fg, leg_size, leg_border, leg_box_border, leg_box_cex, ...)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +object of class sf or sfc +
+var + +name(s) of the variable(s) to plot +
+type + +
    +
  • + +base: base maps + +
  • +
  • + +prop: proportional symbols maps + +
  • +
  • + +choro: choropleth maps + +
  • +
  • + +typo: typology maps + +
  • +
  • + +symb: symbols maps + +
  • +
  • + +grad: graduated symbols maps + +
  • +
  • + +prop_choro: proportional symbols maps with symbols +colors based on a quantitative data classification + +
  • +
  • + +prop_typo: proportional symbols maps with symbols +colors based on qualitative data + +
  • +
  • + +symb_choro: symbols maps with symbols colors based on a +quantitative data classification + +
  • +
+
+breaks + +either a numeric vector with the actual breaks, or a classification +method name (see mf_get_breaks and Details) +
+nbreaks + +number of classes +
+pal + +a set of colors or a palette name (from hcl.colors) +
+alpha + +opacity, in the range \[0,1\] +
+rev + +if pal is a hcl.colors palette name, whether the ordering +of the colors should be reversed (TRUE) or not (FALSE) +
+inches + +size of the biggest symbol (radius for circles, half width for squares) +in inches. +
+val_max + +maximum value used for proportional symbols +
+symbol + +type of symbols, ‘circle’ or ‘square’ +
+col + +color +
+lwd_max + +line width of the largest line +
+val_order + +values order, a character vector that matches var modalities +
+pch + +point type +
+cex + +point size +
+border + +border color +
+lwd + +border width +
+col_na + +color for missing values +
+cex_na + +point size for NA values +
+pch_na + +point type for NA values +
+expandBB + +fractional values to expand the bounding box with, in each direction +(bottom, left, top, right) +
+add + +whether to add the layer to an existing plot (TRUE) or not (FALSE) +
+leg_pos + +position of the legend, one of ‘topleft’, ‘top’,‘topright’, ‘right’, +‘bottomright’, ‘bottom’, ‘bottomleft’, ‘left’ or a vector of two +coordinates in map units (c(x, y)). If leg_pos = NA then the legend is +not plotted. If leg_pos = ‘interactive’ click onthe map to choose the +legend position. +
+leg_title + +legend title +
+leg_title_cex + +size of the legend title +
+leg_val_cex + +size of the values in the legend +
+leg_val_rnd + +number of decimal places of the values in the legend +
+leg_no_data + +label for missing values +
+leg_frame + +whether to add a frame to the legend (TRUE) or not (FALSE) +
+leg_frame_border + +border color of the legend frame +
+leg_horiz + +display the legend horizontally (for proportional symbols and choropleth +types) +
+leg_adj + +adjust the postion of the legend in x and y directions +
+leg_bg + +color of the legend backgournd +
+leg_fg + +color of the legend foreground +
+leg_size + +size of the legend; 2 means two times bigger +
+leg_border + +symbol border color(s) +
+leg_box_border + +border color of legend boxes +
+leg_box_cex + +width and height size expansion of boxes +
+ + +further parameters from plot for sfc objects +
+ +## Details + +

+Relevant arguments and default values for each map types: +

+ +base: displays sf objects geometries. + +
+mf_map(x, col = "grey80", pch = 20, cex = 1, border = "grey20",
+       lwd = 0.7, alpha = NULL, expandBB, add = FALSE, ...)
+       
+ +prop: displays symbols with areas proportional to a +quantitative variable (stocks). inches is used to set +symbols sizes. + +
+mf_map(x, var, type = "prop", inches = 0.3, val_max, symbol = "circle",
+       col = "tomato4", alpha = NULL, lwd_max = 20,
+       border = getOption("mapsf.fg"), lwd = 0.7, expandBB, add = TRUE,
+       leg_pos = mf_get_leg_pos(x), leg_title = var,
+       leg_title_cex = 0.8, leg_val_cex = 0.6, leg_val_rnd = 0,
+       leg_frame = FALSE, leg_frame_border = getOption("mapsf.fg"),
+       leg_horiz = FALSE, leg_adj = c(0, 0),
+       leg_bg = getOption("mapsf.bg"), leg_fg = getOption("mapsf.fg"),
+       leg_size = 1)
+       
+ +choro: areas are shaded according to the variation of a +quantitative variable. Choropleth maps are used to represent ratios or +indices. nbreaks, and breaks allow to set the +variable classification. Colors palettes, defined with pal, +can be created with mf_get_pal() or can use palette names +from hcl.pals(). + +
+mf_map(x, var, type = "choro", breaks = "quantile", nbreaks, pal = "Mint",
+       alpha = NULL, rev = FALSE, pch = 21, cex = 1,
+       border = getOption("mapsf.fg"), lwd = 0.7, col_na = "white",
+       cex_na = 1, pch_na = 4, expandBB, add = FALSE,
+       leg_pos = mf_get_leg_pos(x), leg_title = var, leg_title_cex = 0.8,
+       leg_val_cex = 0.6, leg_val_rnd = 2, leg_no_data = "No data",
+       leg_frame = FALSE, leg_frame_border = getOption("mapsf.fg"),
+       leg_horiz = FALSE, leg_adj = c(0, 0), leg_bg = getOption("mapsf.bg"),
+       leg_fg = getOption("mapsf.fg"), leg_size = 1,
+       leg_box_border = getOption("mapsf.fg"), leg_box_cex = c(1, 1))
+       
+ +typo: displays a typology map of a qualitative +variable. val_order is used to set modalities order in the +legend. + +
+mf_map(x, var, type = "typo", pal = "Dynamic", alpha = NULL, rev = FALSE,
+       val_order,border = getOption("mapsf.fg"), pch = 21, cex = 1,
+       lwd = 0.7, cex_na = 1, pch_na = 4, col_na = "white",
+       leg_pos = mf_get_leg_pos(x), leg_title = var, leg_title_cex = 0.8,
+       leg_val_cex = 0.6, leg_no_data = "No data", leg_frame = FALSE,
+       leg_frame_border = getOption("mapsf.fg"), leg_adj = c(0, 0),
+       leg_size = 1, leg_box_border = getOption("mapsf.fg"),
+       leg_box_cex = c(1, 1), leg_fg = getOption("mapsf.fg"),
+       leg_bg = getOption("mapsf.bg"), add = FALSE)
+       
+ +symb: displays the different modalities of a +qualitative variable as symbols. + +
+mf_map(x, var, type = "symb", pal = "Dynamic", alpha = NULL, rev = FALSE,
+       border = getOption("mapsf.fg"), pch, cex = 1, lwd = 0.7,
+       col_na = "grey", pch_na = 4, cex_na = 1, val_order,
+       leg_pos = mf_get_leg_pos(x), leg_title = var, leg_title_cex = 0.8,
+       leg_val_cex = 0.6, leg_val_rnd = 2, leg_no_data = "No data",
+       leg_frame = FALSE, leg_frame_border = getOption("mapsf.fg"),
+       leg_adj = c(0, 0), leg_fg = getOption("mapsf.fg"),
+       leg_bg = getOption("mapsf.bg"), leg_size = 1, add = TRUE)
+       
+ +grad: displays graduated symbols. Sizes classes are set +with breaks and nbreaks. Symbol sizes are set +with cex. + +
+mf_map(x, var, type = "grad", breaks = "quantile", nbreaks = 3, col = "tomato4",
+       alpha = NULL, border = getOption("mapsf.fg"), pch = 21, cex, lwd,
+       leg_pos = mf_get_leg_pos(x), leg_title = var, leg_title_cex = 0.8,
+       leg_val_cex = 0.6, leg_val_rnd = 2, leg_frame = FALSE,
+       leg_adj = c(0, 0), leg_size = 1, leg_border = border,
+       leg_box_cex = c(1, 1), leg_fg = getOption("mapsf.fg"),
+       leg_bg = getOption("mapsf.bg"), leg_frame_border = getOption("mapsf.fg"),
+       add = TRUE)
+       
+ +prop_choro: displays symbols with sizes proportional to +values of a first variable and colored to reflect the classification of +a second quantitative variable. + +
+mf_map(x, var, type = "prop_choro", inches = 0.3, val_max, symbol = "circle",
+       pal = "Mint", alpha = NULL, rev = FALSE, breaks = "quantile", nbreaks,
+       border = getOption("mapsf.fg"), lwd = 0.7, col_na = "white",
+       leg_pos = mf_get_leg_pos(x, 1), leg_title = var,
+       leg_title_cex = c(0.8, 0.8), leg_val_cex = c(0.6, 0.6),
+       leg_val_rnd = c(0, 2), leg_no_data = "No data",
+       leg_frame = c(FALSE, FALSE), leg_frame_border = getOption("mapsf.fg"),
+       leg_horiz = c(FALSE, FALSE), leg_adj = c(0, 0),
+       leg_fg = getOption("mapsf.fg"), leg_bg = getOption("mapsf.bg"),
+       leg_size = 1, leg_box_border = getOption("mapsf.fg"),
+       leg_box_cex = c(1, 1), add = TRUE)
+       
+ +prop_typo: displays symbols with sizes proportional to +values of a first variable and colored to reflect the modalities of a +second qualitative variable. + +
+mf_map(x, var, type = "prop_typo", inches = 0.3, val_max, symbol = "circle",
+       pal = "Dynamic", alpha = NULL, rev = FALSE, val_order,
+       border = getOption("mapsf.fg"), lwd = 0.7, lwd_max = 15,
+       col_na = "white",
+       leg_pos = mf_get_leg_pos(x, 1), leg_title = var,
+       leg_title_cex = c(0.8, 0.8), leg_val_cex = c(0.6, 0.6),
+       leg_val_rnd = c(0), leg_no_data = "No data", leg_frame = c(FALSE, FALSE),
+       leg_frame_border = getOption("mapsf.fg"), leg_horiz = FALSE,
+       leg_adj = c(0, 0), leg_fg = getOption("mapsf.fg"),
+       leg_bg = getOption("mapsf.bg"), leg_size = 1,
+       leg_box_border = getOption("mapsf.fg"), leg_box_cex = c(1, 1),
+       add = TRUE)
+       
+ +symb_choro: displays the different modalities of a +first qualitative variable as symbols colored to reflect the +classification of a second quantitative variable. + +
+mf_map(x, var, type = "symb_choro", pal = "Mint", alpha = NULL, rev = FALSE,
+       breaks = "quantile", nbreaks, border = getOption("mapsf.fg"),
+       pch, cex = 1, lwd = 0.7, pch_na = 4, cex_na = 1, col_na = "white",
+       val_order,
+       leg_pos = mf_get_leg_pos(x, 1), leg_title = var,
+       leg_title_cex = c(0.8, 0.8), leg_val_cex = c(0.6, 0.6),
+       leg_val_rnd = 2, leg_no_data = c("No data", "No data"),
+       leg_frame = c(FALSE, FALSE), leg_frame_border = getOption("mapsf.fg"),
+       leg_horiz = FALSE, leg_adj = c(0, 0), leg_fg = getOption("mapsf.fg"),
+       leg_bg = getOption("mapsf.bg"), leg_size = 1,
+       leg_box_border = getOption("mapsf.fg"), leg_box_cex = c(1, 1),
+       add = TRUE)
+       
+

+Class boundaries +

+ +Breaks defined by a numeric vector or a classification method are +left-closed: breaks defined by c(2, 5, 10, 15, 20) will be +mapped as \[2 - 5\[, \[5 - 10\[, \[10 - 15\[, \[15 - 20\]. + +## Value + +x is (invisibly) returned. + +## Examples + +``` r +library("mapsf") + +library(mapsf) +mtq <- mf_get_mtq() +# basic examples +# type = "base" +mf_map(mtq) +# type = "prop" +mf_map(mtq) +mf_map(mtq, var = "POP", type = "prop") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +``` r +# type = "choro" +mf_map(mtq, var = "MED", type = "choro") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +``` r +# type = "typo" +mf_map(mtq, "STATUS", "typo") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) + +``` r +# type = "symb" +mf_map(mtq) +mf_map(mtq, "STATUS", "symb") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png) + +``` r +# type = "grad" +mf_map(mtq) +mf_map(mtq, var = "POP", type = "grad") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png) + +``` r +# type = "prop_choro" +mf_map(mtq) +mf_map(mtq, var = c("POP", "MED"), type = "prop_choro") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png) + +``` r +# type = "prop_typo" +mf_map(mtq) +mf_map(mtq, var = c("POP", "STATUS"), type = "prop_typo") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png) + +``` r +# type = "symb_choro +mf_map(mtq) +mf_map(mtq, var = c("STATUS", "MED"), type = "symb_choro") +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-8.png) + +``` r +# detailed examples +# type = "base" +mf_map(mtq, type = "base", col = "lightblue", lwd = 1.5, lty = 2) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-9.png) + +``` r +# type = "prop" +mf_map(mtq) +mf_map( + x = mtq, var = "POP", type = "prop", + inches = .4, symbol = "circle", val_max = 90000, + col = "lightblue", border = "grey", lwd = 1, + leg_pos = "right", leg_title = "Population", + leg_title_cex = 1, leg_val_cex = .8, leg_val_rnd = 0, + leg_frame = TRUE, add = TRUE +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-10.png) + +``` r +# type = "choro" +mtq[6, "MED"] <- NA +mf_map( + x = mtq, var = "MED", type = "choro", + col_na = "grey80", pal = "Cividis", + breaks = "quantile", nbreaks = 4, border = "white", + lwd = .5, leg_pos = "topleft", + leg_title = "Median Income", leg_title_cex = 1.1, + leg_val_cex = 1, leg_val_rnd = -2, leg_no_data = "No data", + leg_frame = TRUE, leg_adj = c(0, -3) +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-11.png) + +``` r +# type = "typo" +mtq[4, "STATUS"] <- NA +mf_map( + x = mtq, var = "STATUS", type = "typo", + pal = c("red", "blue", "yellow"), lwd = 1.1, + val_order = c("Prefecture", "Sub-prefecture", "Simple municipality"), + col_na = "green", border = "brown", + leg_pos = "bottomleft", + leg_title = "Status", leg_title_cex = 1.1, + leg_val_cex = 1, leg_no_data = "No data", + leg_frame = TRUE, add = FALSE +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-12.png) + +``` r +# type = "symb" +mf_map(mtq) +mf_map( + x = mtq, var = "STATUS", type = "symb", + pch = c(21:23), pal = c("red1", "tan1", "khaki1"), + border = "grey20", cex = c(2, 1.5, 1), lwd = .5, + val_order = c("Prefecture", "Sub-prefecture", "Simple municipality"), + pch_na = 24, col_na = "blue", leg_frame = TRUE +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-13.png) + +``` r +# type = "grad" +mf_map(mtq) +mf_map( + x = mtq, var = "POP", type = "grad", + pch = 22, breaks = "quantile", nbreaks = 4, lwd = 2, border = "blue", + cex = c(.75, 1.5, 3, 5), col = "lightgreen" +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-14.png) + +``` r +# type = "prop_choro" +mf_map(mtq) +mf_map( + x = mtq, var = c("POP", "MED"), type = "prop_choro", + inches = .35, border = "tomato4", + val_max = 90000, symbol = "circle", col_na = "white", pal = "Cividis", + breaks = "equal", nbreaks = 4, lwd = 4, + leg_pos = "bottomleft", + leg_title = c("Population", "Median Income"), + leg_title_cex = c(0.8, 1), + leg_val_cex = c(.7, .9), + leg_val_rnd = c(0, 0), + leg_no_data = "No data", + leg_frame = c(TRUE, TRUE), + add = TRUE +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-15.png) + +``` r +# type = "prop_typo" +mf_map(mtq) +mf_map( + x = mtq, var = c("POP", "STATUS"), type = "prop_typo", + inches = .35, border = "tomato4", + val_max = 90000, symbol = "circle", col_na = "white", pal = "Dynamic", + lwd = 2, + leg_pos = c("bottomright", "bottomleft"), + leg_title = c("Population", "Municipality\nstatus"), + leg_title_cex = c(0.9, 0.9), + leg_val_cex = c(.7, .7), + val_order = c("Prefecture", "Sub-prefecture", "Simple municipality"), + leg_no_data = "No dada", + leg_frame = c(TRUE, TRUE), + add = TRUE +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-16.png) + +``` r +# type = "symb_choro" +mf_map(mtq) +mf_map( + x = mtq, c("STATUS", "MED"), type = "symb_choro", + pal = "Reds 3", breaks = "quantile", nbreaks = 4, + pch = 21:23, cex = c(3, 2, 1), + pch_na = 25, cex_na = 1.5, col_na = "blue", + val_order = c( + "Prefecture", + "Sub-prefecture", + "Simple municipality" + ) +) +``` + +![](mf_map.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-17.png) diff --git a/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..835edd0 Binary files /dev/null and b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..93fc622 Binary files /dev/null and b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..bb89129 Binary files /dev/null and b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png new file mode 100644 index 0000000..b1f7196 Binary files /dev/null and b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png differ diff --git a/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png new file mode 100644 index 0000000..9b60801 Binary files /dev/null and b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png differ diff --git a/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png new file mode 100644 index 0000000..3e1dc7e Binary files /dev/null and b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png differ diff --git a/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png new file mode 100644 index 0000000..546ee70 Binary files /dev/null and b/docs/man/mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png differ diff --git a/docs/man/mf_raster.md b/docs/man/mf_raster.md new file mode 100644 index 0000000..4aa8297 --- /dev/null +++ b/docs/man/mf_raster.md @@ -0,0 +1,317 @@ + + +# Plot a raster + +## Description + +Plot a raster object (SpatRaster from terra). + +## Usage + +
mf_raster(
+  x,
+  type,
+  nbreaks,
+  breaks = "equal",
+  val_order,
+  pal,
+  expandBB = rep(0, 4),
+  alpha = NULL,
+  rev = FALSE,
+  leg_pos = "right",
+  leg_title = names(x),
+  leg_title_cex = 0.8,
+  leg_val_cex = 0.6,
+  leg_val_rnd = 1,
+  leg_frame = FALSE,
+  leg_frame_border = getOption("mapsf.fg"),
+  leg_horiz = FALSE,
+  leg_adj = c(0, 0),
+  leg_box_border = "#333333",
+  leg_box_cex = c(1, 1),
+  leg_fg = getOption("mapsf.fg"),
+  leg_bg = getOption("mapsf.bg"),
+  leg_size = 1,
+  add = FALSE,
+  ...
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +a SpatRaster +
+type + +type of raster map, one of "continuous", "classes", or "interval". +Default type for a numeric and categorial raster are "continuous" and +"classes" respectively. +
+nbreaks + +number of classes +
+breaks + +either a numeric vector with the actual breaks (for type = "continuous" +and type = "interval"), or a classification method name (for type = +"interval" only; see mf_get_breaks for classification methods) +
+val_order + +values order, a character vector that matches var modalities +
+pal + +a set of colors or a palette name (from hcl.colors) +
+expandBB + +fractional values to expand the bounding box with, in each direction +(bottom, left, top, right) +
+alpha + +opacity, in the range \[0,1\] +
+rev + +if pal is a hcl.colors palette name, whether the ordering +of the colors should be reversed (TRUE) or not (FALSE) +
+leg_pos + +position of the legend, one of ‘topleft’, ‘top’,‘topright’, ‘right’, +‘bottomright’, ‘bottom’, ‘bottomleft’, ‘left’ or a vector of two +coordinates in map units (c(x, y)). If leg_pos = NA then the legend is +not plotted. If leg_pos = ‘interactive’ click onthe map to choose the +legend position. +
+leg_title + +legend title +
+leg_title_cex + +size of the legend title +
+leg_val_cex + +size of the values in the legend +
+leg_val_rnd + +number of decimal places of the values in the legend +
+leg_frame + +whether to add a frame to the legend (TRUE) or not (FALSE) +
+leg_frame_border + +border color of the legend frame +
+leg_horiz + +display the legend horizontally +
+leg_adj + +adjust the postion of the legend in x and y directions +
+leg_box_border + +border color of legend boxes +
+leg_box_cex + +width and height size expansion of boxes +
+leg_fg + +color of the legend foreground +
+leg_bg + +color of the legend backgournd +
+leg_size + +size of the legend; 2 means two times bigger +
+add + +whether to add the layer to an existing plot (TRUE) or not (FALSE) +
+ + +bgalpha, smooth, maxcell or other arguments passed to be passed to +plotRGB or plot +
+ +## Value + +x is (invisibly) returned. + +## Examples + +``` r +library("mapsf") + +if (require("terra")) { + # multi band + logo <- rast(system.file("ex/logo.tif", package = "terra")) + mf_raster(logo) + + # one band + elev <- rast(system.file("ex/elev.tif", package = "terra")) + + ## continuous + mf_raster(elev) + mf_raster(elev, + pal = "Burg", expandBB = c(.2, 0, 0, 0), + leg_pos = "bottom", leg_horiz = TRUE + ) + + ## continuous with colors and breaks + mf_raster(elev, + type = "continuous", + breaks = c(141, 400, 547), + pal = c("darkseagreen1", "black", "red") + ) + + ## interval + mf_raster(elev, + type = "interval", + nbreaks = 5, breaks = "equal", pal = "Teal" + ) + + ## classes + elev2 <- classify(elev, c(140, 400, 450, 549)) + lev_evel <- data.frame(ID = 0:2, elevation = c("Low", "High", "Super High")) + levels(elev2) <- lev_evel + mf_raster(elev2) + mf_raster(elev2, + pal = c("salmon4", "olivedrab", "yellow3"), + val_order = c("Super High", "High", "Low") + ) +} +``` + +![](mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +![](mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +![](mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) + +![](mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png) + +![](mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png) + +![](mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-6.png) + +![](mf_raster.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-7.png) diff --git a/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..111f61a Binary files /dev/null and b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..9a78055 Binary files /dev/null and b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..9a78055 Binary files /dev/null and b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png new file mode 100644 index 0000000..a86f12b Binary files /dev/null and b/docs/man/mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png differ diff --git a/docs/man/mf_scale.md b/docs/man/mf_scale.md new file mode 100644 index 0000000..0dd5827 --- /dev/null +++ b/docs/man/mf_scale.md @@ -0,0 +1,158 @@ + + +# Plot a scale bar + +## Description + +Plot a scale bar. + +## Usage + +
mf_scale(
+  size,
+  pos = "bottomright",
+  lwd = 1.5,
+  cex = 0.6,
+  col,
+  crs_units = "m",
+  scale_units = "km",
+  x
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+size + +size of the scale bar in scale units (scale_units, default +to km). If size is not set, an automatic size is used (1/10 of the map +width). +
+pos + +position. It can be one of ‘bottomright’, ‘bottomleft’, ‘interactive’ or +a vector of two coordinates in map units (c(x, y)). +
+lwd + +line width of the scale bar +
+cex + +size of the scale bar text +
+col + +color of the scale bar (line and text) +
+crs_units + +units used in the CRS of the currently plotted layer. Possible values +are "m" and "ft" (see Details). +
+scale_units + +units used for the scale bar. Can be "mi" for miles, "ft" for feet, "m" +for meters, or "km" for kilometers (default). +
+x + +object of class crs, sf or sfc. If set, the CRS of x will be used +instead of crs_units to define CRS units. +
+ +## Details + +Most CRS use the meter as unit. Some US CRS use feet or US survey feet. +If unsure of the unit used in the CRS you can use the x argument of the +function. Alternatively, you can use sf::st_crs(zz, parameters = +TRUE)$units_gdal to see which units are used in the +zz layer. + +This scale bar does not work on unprojected (long/lat) maps. + +## Value + +No return value, a scale bar is displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_scale() +``` + +![](mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +``` r +library(sf) +nc <- st_read(system.file("shape/nc.shp", package = "sf"))[1, ] +``` + + Reading layer `nc' from data source `/home/tim/Documents/R/4.4/sf/shape/nc.shp' using driver `ESRI Shapefile' + Simple feature collection with 100 features and 14 fields + Geometry type: MULTIPOLYGON + Dimension: XY + Bounding box: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 + Geodetic CRS: NAD27 + +``` r +nc_foot <- st_transform(nc, 2264) # NC state plane, US foot +mf_map(nc_foot) +mf_scale(size = 5, crs_units = "ft", scale_units = "mi") +``` + +![](mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +``` r +mf_map(nc_foot) +mf_scale(size = 5, x = nc_foot, scale_units = "mi") +``` + +![](mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) + +``` r +nc_meter <- st_transform(nc, 32119) # NC state plane, m +mf_map(nc_meter) +mf_scale(size = 5, crs_units = "m", scale_units = "mi") +mf_scale(size = 5, crs_units = "m", scale_units = "km", pos = "bottomleft") +``` + +![](mf_scale.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png) diff --git a/docs/man/mf_shadow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_shadow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..c2262db Binary files /dev/null and b/docs/man/mf_shadow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_shadow.md b/docs/man/mf_shadow.md new file mode 100644 index 0000000..1ac8726 --- /dev/null +++ b/docs/man/mf_shadow.md @@ -0,0 +1,65 @@ + + +# Plot a shadow + +## Description + +Plot the shadow of a polygon layer. + +## Usage + +
mf_shadow(x, col = "grey50", cex = 1, add = FALSE)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + +
+x + +an sf or sfc polygon object +
+col + +shadow color +
+cex + +shadow extent +
+add + +whether to add the layer to an existing plot (TRUE) or not (FALSE) +
+ +## Value + +x is (invisibly) returned. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_shadow(mtq) +mf_map(mtq, add = TRUE) +``` + +![](mf_shadow.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..a7f5a13 Binary files /dev/null and b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..9581a68 Binary files /dev/null and b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..350a032 Binary files /dev/null and b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png new file mode 100644 index 0000000..bc23349 Binary files /dev/null and b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png differ diff --git a/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png new file mode 100644 index 0000000..9550fa3 Binary files /dev/null and b/docs/man/mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png differ diff --git a/docs/man/mf_theme.md b/docs/man/mf_theme.md new file mode 100644 index 0000000..22be0e9 --- /dev/null +++ b/docs/man/mf_theme.md @@ -0,0 +1,216 @@ + + +# Set a theme + +## Description + +This function set a map theme. The parameters set by this function are +the figure margins, background and foreground colors and some mf_title +options. Use mf_theme(NULL) or +mf_theme(‘default’) to reset to default theme settings. + +## Usage + +
mf_theme(x, bg, fg, mar, tab, pos, inner, line, cex, font)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +name of a map theme. One of "default", "brutal", "ink", "dark", +"agolalight", "candy", "darkula", "iceberg", "green", "nevermind", +"jsk", "barcelona". +
+bg + +background color +
+fg + +foreground color +
+mar + +margins +
+tab + +if TRUE the title is displayed as a ‘tab’ +
+pos + +title position, one of ‘left’, ‘center’, ‘right’ +
+inner + +if TRUE the title is displayed inside the plot area. +
+line + +number of lines used for the title +
+cex + +cex of the title +
+font + +font of the title +
+ +## Details + +It is also possible to set a custom theme using a list of arguments (see +Examples). mf_theme() returns the current theme settings. + +## Value + +The (invisible) list of theme parameters is returned. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() + +# Choosing a theme by name: +mf_theme("default") +mf_map(mtq) +mf_title() +``` + +![](mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +``` r +# Specifying some values directly: +mf_theme(bg = "darkslategrey", fg = "lightgrey") +mf_map(mtq) +mf_title() +``` + +![](mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +``` r +# Using a mix of the above: +mf_theme("brutal", fg = "lightgreen", pos = "center", font = 2, tab = FALSE) +mf_map(mtq) +mf_title() +``` + +![](mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) + +``` r +# Specifying a list with theme values: +theme <- mf_theme("default") +theme$mar <- c(1, 1, 3, 1) +theme$line <- 2 +theme$cex <- 1.5 +mf_theme(theme) +mf_map(mtq) +mf_title() +``` + +![](mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-4.png) + +``` r +# or +theme <- list( + bg = "green", + fg = "red", + mar = c(2, 2, 2, 2), + tab = TRUE, + pos = "center", + inner = TRUE, + line = 2, + cex = 1.5, + font = 3 +) +mf_theme(theme) +mf_map(mtq) +mf_title() +``` + +![](mf_theme.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-5.png) + +``` r +# Obtaining a list of parameters for the current theme: +mf_theme() +``` + + $bg + [1] "green" + + $fg + [1] "red" + + $mar + [1] 2 2 2 2 + + $tab + [1] TRUE + + $pos + [1] "center" + + $inner + [1] TRUE + + $line + [1] 2 + + $cex + [1] 1.5 + + $font + [1] 3 + +``` r +# Removing the current theme: +mf_theme(NULL) +# or +mf_theme("default") +``` diff --git a/docs/man/mf_title.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_title.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..a7f5a13 Binary files /dev/null and b/docs/man/mf_title.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_title.md b/docs/man/mf_title.md new file mode 100644 index 0000000..f61301d --- /dev/null +++ b/docs/man/mf_title.md @@ -0,0 +1,105 @@ + + +# Plot a title + +## Description + +Plot a title + +## Usage + +
mf_title(txt = "Map Title", pos, tab, bg, fg, cex, line, font, inner)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+txt + +title text +
+pos + +position, one of ‘left’, ‘center’, ‘right’ +
+tab + +if TRUE the title is displayed as a ‘tab’ +
+bg + +background of the title +
+fg + +foreground of the title +
+cex + +cex of the title +
+line + +number of lines used for the title +
+font + +font of the title +
+inner + +if TRUE the title is displayed inside the plot area. +
+ +## Value + +No return value, a title is displayed. + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_map(mtq) +mf_title() +``` + +![](mf_title.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) diff --git a/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png b/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png new file mode 100644 index 0000000..53437fc Binary files /dev/null and b/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png differ diff --git a/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png b/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png new file mode 100644 index 0000000..407e1a4 Binary files /dev/null and b/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png differ diff --git a/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png b/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png new file mode 100644 index 0000000..4d68533 Binary files /dev/null and b/docs/man/mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png differ diff --git a/docs/man/mf_worldmap.md b/docs/man/mf_worldmap.md new file mode 100644 index 0000000..f280dd5 --- /dev/null +++ b/docs/man/mf_worldmap.md @@ -0,0 +1,127 @@ + + +# Plot a point on a world map + +## Description + +Plot a point on a world map. + +## Usage + +
mf_worldmap(
+  x,
+  lon,
+  lat,
+  water_col = "lightblue",
+  land_col = "grey60",
+  border_col = "grey40",
+  border_lwd = 0.8,
+  ...
+)
+
+ +## Arguments + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+x + +object of class sf or sfc +
+lon + +longitude +
+lat + +latitude +
+water_col + +color of the water +
+land_col + +color of the land +
+border_col + +color of the borders +
+border_lwd + +width of the borders +
+ + +further parameters related to the plotted point aspect (cex, pch, col…) +
+ +## Value + +No return value, a world map is displayed. + +## Note + +The main part of the code is stolen from @fzenoni +(https://gist.github.com/fzenoni/ef23faf6d1ada5e4a91c9ef23b0ba2c1). + +## Examples + +``` r +library("mapsf") + +mtq <- mf_get_mtq() +mf_worldmap(mtq) +``` + +![](mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-1.png) + +``` r +mf_worldmap(lon = 24, lat = 39) +``` + +![](mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-2.png) + +``` r +mf_worldmap( + lon = 106, lat = 26, + pch = 4, lwd = 3, cex = 2, col = "tomato4", + water_col = "#232525", land_col = "#A9B7C6", + border_col = "white", border_lwd = 1 +) +``` + +![](mf_worldmap.markdown_strict_files/figure-markdown_strict/unnamed-chunk-1-3.png) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml new file mode 100644 index 0000000..930db35 --- /dev/null +++ b/docs/pkgdown.yml @@ -0,0 +1,4 @@ +urls: + reference: https:/riatelab.github.io/mapsf/man + article: https:/riatelab.github.io/mapsf/vignettes + diff --git a/docs/preamble_man_qmd.yml b/docs/preamble_man_qmd.yml new file mode 100644 index 0000000..cd2e598 --- /dev/null +++ b/docs/preamble_man_qmd.yml @@ -0,0 +1,6 @@ +--- +format: + md: + prefer-html: true +--- + diff --git a/docs/preamble_vignettes_qmd.yml b/docs/preamble_vignettes_qmd.yml new file mode 100644 index 0000000..1436a9e --- /dev/null +++ b/docs/preamble_vignettes_qmd.yml @@ -0,0 +1,6 @@ +--- +format: + md: + prefer_html: true +default-image-extension: "" +--- diff --git a/docs/preamble_vignettes_rmd.yml b/docs/preamble_vignettes_rmd.yml new file mode 100644 index 0000000..b47a68a --- /dev/null +++ b/docs/preamble_vignettes_rmd.yml @@ -0,0 +1,4 @@ +--- +always_allow_html: yes +--- + diff --git a/docs/vignettes/.gitignore b/docs/vignettes/.gitignore new file mode 100644 index 0000000..097b241 --- /dev/null +++ b/docs/vignettes/.gitignore @@ -0,0 +1,2 @@ +*.html +*.R diff --git a/docs/vignettes/cheat_sheet.Rmd b/docs/vignettes/cheat_sheet.Rmd new file mode 100644 index 0000000..18999ef --- /dev/null +++ b/docs/vignettes/cheat_sheet.Rmd @@ -0,0 +1,16 @@ +--- +title: "Cheat Sheet" +author: "Ronan Ysebaert & Timothée Giraud" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Cheat Sheet} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + + +![](fig/mapsf_cheatsheet.png) + + +[Download PDF version](https://raw.githubusercontent.com/riatelab/mapsf/master/vignettes/web_only/img/mapsf_cheatsheet.pdf) diff --git a/docs/vignettes/cheat_sheet.md b/docs/vignettes/cheat_sheet.md new file mode 100644 index 0000000..1261fce --- /dev/null +++ b/docs/vignettes/cheat_sheet.md @@ -0,0 +1,8 @@ +# Cheat Sheet +Ronan Ysebaert & Timothée Giraud +2025-01-22 + +![](fig/mapsf_cheatsheet.png) + +[Download PDF +version](https://raw.githubusercontent.com/riatelab/mapsf/master/vignettes/web_only/img/mapsf_cheatsheet.pdf) diff --git a/docs/vignettes/fig/maplayout.png b/docs/vignettes/fig/maplayout.png new file mode 100644 index 0000000..ca99a67 Binary files /dev/null and b/docs/vignettes/fig/maplayout.png differ diff --git a/docs/vignettes/fig/mapsf_cheatsheet.pdf b/docs/vignettes/fig/mapsf_cheatsheet.pdf new file mode 100644 index 0000000..579ce18 Binary files /dev/null and b/docs/vignettes/fig/mapsf_cheatsheet.pdf differ diff --git a/docs/vignettes/fig/mapsf_cheatsheet.png b/docs/vignettes/fig/mapsf_cheatsheet.png new file mode 100644 index 0000000..d33fbb4 Binary files /dev/null and b/docs/vignettes/fig/mapsf_cheatsheet.png differ diff --git a/docs/vignettes/fig/mapsf_cheatsheet.svg b/docs/vignettes/fig/mapsf_cheatsheet.svg new file mode 100644 index 0000000..b9ff099 --- /dev/null +++ b/docs/vignettes/fig/mapsf_cheatsheet.svg @@ -0,0 +1,12039 @@ + + + +ConnectorExit to or entry from another part of chart.Thematic maps with mapsf :: CHEAT SHEETBase mapMap layoutlibrary(mapsf)# import the sample datasetmtq <- mf_get_mtq()# display a base mapmf_map(mtq, col = "orange", border = "white")# display symbologymf_map(mtq, var = "POP", type = "prop", leg_title = "Population", add = TRUE)# map layoutmf_layout(title = "Martinique", credits = "Source:IGN, 2018")Colorsmf_get_pal(n = c(7, 2), pal = c("Burg", "Mint")mapsf can use color palettes from hcl.colors()mf_get_pal() is useful to create well-balanced asymetric diverging palettesSymbologyx should be an sf object of polygons, lines, or points.Customization of tha layout designChoropleth (ratios)mf_map(x = mtq, var = "var", type = "choro", breaks = "quantile")Typology (categories)mf_map(x = mtq, var = "var", type = "typo")Proportional Symbols (stocks)mf_map(x = mtq, var = "var", type = "prop", inches = .3, symbol = "circle")Graduated Symbols (stocks)mf_map(x = mtq, var = "var", type = "grad", pch = 24)Symbols (categories)mf_map(x = mtq, var = "var", type = "symb", pch = 21:23)Choropleth Proportional Symbols (stocks - ratios)mf_map(x = mtq, var = c("var1", "var2"), type = "prop_choro")Colorized Proportional Symbols (stocks - categ.)mf_map(x = mtq, var = c("var1", "var2"), type = "prop_typo")Choropleth Symbols (stocks - categ.)mf_map(x = mtq, var = c("var1", "var2"), type = "symb_choro")Raster (single/multi band, continuous, classes, intervals)mf_raster(x = raster, type = "continuous")mapsf - CRAN.R-project.org/package=mapsf - R. Ysebaert & T. Giraud - 2024/12LegendsDefault legends are plotted with each map.One can use mf_legend() or the maplegend package for more customization options. 21Set a map theme1mf_theme(bg = "#aad3df", mar = c(0, 0, 0, 0))Create a shadow effect2mf_shadow(...)4Display a title4mf_title(...)56More ?> How to use themes> How to export maps > How to create inset maps> How to create faceted maps> how to use a custom font family3Create a map inset3mf_inset_on(mtq)mf_map(mtq)mf_inset_off()Use mf_inset_on(x = "worldmap") and mf_worldmap() to display a globeVignettes on the website:89Display labels5mf_label(...)Display an annotation6mf_annotation(...)North arrow7mf_arrow(...)Scale bar8mf_scale(...)Credits9mf_credits(...)7 Class intervalsmf_get_breaks() uses classInt and additional methods (e.g., "Q6", "geom", "arith", "msd" or "ckmeans") to classify continuous variables. mf_distr() can help to selecta method for creating class intervalsmf_export(mtq, width = 3, filename = "map.svg")mf_map(mtq, add = TRUE)dev.off()Export mapsmf_export() exports mapsin PNG and SVG formats.The width/height ratio of theexported figure will match the one of a spatial object. width : 3 in.(inferred) height : 3.5 in. diff --git a/docs/vignettes/fig/mf_base.png b/docs/vignettes/fig/mf_base.png new file mode 100644 index 0000000..66a852b Binary files /dev/null and b/docs/vignettes/fig/mf_base.png differ diff --git a/docs/vignettes/fig/mf_base.svg b/docs/vignettes/fig/mf_base.svg new file mode 100644 index 0000000..aa6d85f --- /dev/null +++ b/docs/vignettes/fig/mf_base.svg @@ -0,0 +1,77 @@ + + + + diff --git a/docs/vignettes/fig/mf_choro.svg b/docs/vignettes/fig/mf_choro.svg new file mode 100644 index 0000000..7b5361c --- /dev/null +++ b/docs/vignettes/fig/mf_choro.svg @@ -0,0 +1,48 @@ + + + + diff --git a/docs/vignettes/fig/mf_grad.svg b/docs/vignettes/fig/mf_grad.svg new file mode 100644 index 0000000..2a8cdc5 --- /dev/null +++ b/docs/vignettes/fig/mf_grad.svg @@ -0,0 +1,98 @@ + + + + diff --git a/docs/vignettes/fig/mf_prop.svg b/docs/vignettes/fig/mf_prop.svg new file mode 100644 index 0000000..ba5e395 --- /dev/null +++ b/docs/vignettes/fig/mf_prop.svg @@ -0,0 +1,108 @@ + + + + diff --git a/docs/vignettes/fig/mf_prop_choro.svg b/docs/vignettes/fig/mf_prop_choro.svg new file mode 100644 index 0000000..73b6d4a --- /dev/null +++ b/docs/vignettes/fig/mf_prop_choro.svg @@ -0,0 +1,123 @@ + + + + diff --git a/docs/vignettes/fig/mf_prop_typo.svg b/docs/vignettes/fig/mf_prop_typo.svg new file mode 100644 index 0000000..adb9c8f --- /dev/null +++ b/docs/vignettes/fig/mf_prop_typo.svg @@ -0,0 +1,148 @@ + + + + diff --git a/docs/vignettes/fig/mf_raster.svg b/docs/vignettes/fig/mf_raster.svg new file mode 100644 index 0000000..306b01e --- /dev/null +++ b/docs/vignettes/fig/mf_raster.svg @@ -0,0 +1,49 @@ + + + + diff --git a/docs/vignettes/fig/mf_symb.svg b/docs/vignettes/fig/mf_symb.svg new file mode 100644 index 0000000..cfbe73e --- /dev/null +++ b/docs/vignettes/fig/mf_symb.svg @@ -0,0 +1,94 @@ + + + + diff --git a/docs/vignettes/fig/mf_symb_choro.svg b/docs/vignettes/fig/mf_symb_choro.svg new file mode 100644 index 0000000..b582738 --- /dev/null +++ b/docs/vignettes/fig/mf_symb_choro.svg @@ -0,0 +1,94 @@ + + + + diff --git a/docs/vignettes/fig/mf_typo.svg b/docs/vignettes/fig/mf_typo.svg new file mode 100644 index 0000000..a0a8c05 --- /dev/null +++ b/docs/vignettes/fig/mf_typo.svg @@ -0,0 +1,48 @@ + + + + diff --git a/docs/vignettes/fig/wo_export_fixed_height_centered.png b/docs/vignettes/fig/wo_export_fixed_height_centered.png new file mode 100644 index 0000000..8b9fafe Binary files /dev/null and b/docs/vignettes/fig/wo_export_fixed_height_centered.png differ diff --git a/docs/vignettes/fig/wo_export_fixed_width.png b/docs/vignettes/fig/wo_export_fixed_width.png new file mode 100644 index 0000000..ba930e0 Binary files /dev/null and b/docs/vignettes/fig/wo_export_fixed_width.png differ diff --git a/docs/vignettes/fig/wo_export_fixed_width.svg b/docs/vignettes/fig/wo_export_fixed_width.svg new file mode 100644 index 0000000..a015885 --- /dev/null +++ b/docs/vignettes/fig/wo_export_fixed_width.svg @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/vignettes/fig/wo_export_fixed_width_expand.png b/docs/vignettes/fig/wo_export_fixed_width_expand.png new file mode 100644 index 0000000..73014a0 Binary files /dev/null and b/docs/vignettes/fig/wo_export_fixed_width_expand.png differ diff --git a/docs/vignettes/fig/wo_export_unnamed-chunk-9-1.png b/docs/vignettes/fig/wo_export_unnamed-chunk-9-1.png new file mode 100644 index 0000000..8a93d26 Binary files /dev/null and b/docs/vignettes/fig/wo_export_unnamed-chunk-9-1.png differ diff --git a/docs/vignettes/fig/wo_facet_unnamed-chunk-2-1.png b/docs/vignettes/fig/wo_facet_unnamed-chunk-2-1.png new file mode 100644 index 0000000..d995a65 Binary files /dev/null and b/docs/vignettes/fig/wo_facet_unnamed-chunk-2-1.png differ diff --git a/docs/vignettes/fig/wo_facet_unnamed-chunk-3-1.png b/docs/vignettes/fig/wo_facet_unnamed-chunk-3-1.png new file mode 100644 index 0000000..4bddeb4 Binary files /dev/null and b/docs/vignettes/fig/wo_facet_unnamed-chunk-3-1.png differ diff --git a/docs/vignettes/fig/wo_font_a-1.png b/docs/vignettes/fig/wo_font_a-1.png new file mode 100644 index 0000000..0244a82 Binary files /dev/null and b/docs/vignettes/fig/wo_font_a-1.png differ diff --git a/docs/vignettes/fig/wo_inset_unnamed-chunk-2-1.png b/docs/vignettes/fig/wo_inset_unnamed-chunk-2-1.png new file mode 100644 index 0000000..b1307c9 Binary files /dev/null and b/docs/vignettes/fig/wo_inset_unnamed-chunk-2-1.png differ diff --git a/docs/vignettes/fig/wo_inset_unnamed-chunk-3-1.png b/docs/vignettes/fig/wo_inset_unnamed-chunk-3-1.png new file mode 100644 index 0000000..8771e50 Binary files /dev/null and b/docs/vignettes/fig/wo_inset_unnamed-chunk-3-1.png differ diff --git a/docs/vignettes/fig/wo_inset_unnamed-chunk-4-1.png b/docs/vignettes/fig/wo_inset_unnamed-chunk-4-1.png new file mode 100644 index 0000000..7be4de3 Binary files /dev/null and b/docs/vignettes/fig/wo_inset_unnamed-chunk-4-1.png differ diff --git a/docs/vignettes/fig/wo_inset_unnamed-chunk-5-1.png b/docs/vignettes/fig/wo_inset_unnamed-chunk-5-1.png new file mode 100644 index 0000000..b2bcfe0 Binary files /dev/null and b/docs/vignettes/fig/wo_inset_unnamed-chunk-5-1.png differ diff --git a/docs/vignettes/fig/wo_inset_unnamed-chunk-6-1.png b/docs/vignettes/fig/wo_inset_unnamed-chunk-6-1.png new file mode 100644 index 0000000..b111db5 Binary files /dev/null and b/docs/vignettes/fig/wo_inset_unnamed-chunk-6-1.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-1.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-1.png new file mode 100644 index 0000000..a1bf200 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-1.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-10.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-10.png new file mode 100644 index 0000000..c496366 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-10.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-11.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-11.png new file mode 100644 index 0000000..3d8ba95 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-11.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-2.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-2.png new file mode 100644 index 0000000..7671e7c Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-2.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-3.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-3.png new file mode 100644 index 0000000..e75f7b3 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-3.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-4.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-4.png new file mode 100644 index 0000000..730310a Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-4.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-5.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-5.png new file mode 100644 index 0000000..c674c68 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-5.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-6.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-6.png new file mode 100644 index 0000000..845fa87 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-6.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-7.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-7.png new file mode 100644 index 0000000..348e8a7 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-7.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-8.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-8.png new file mode 100644 index 0000000..b14d536 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-8.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-2-9.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-9.png new file mode 100644 index 0000000..7575ce3 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-2-9.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-5-1.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-5-1.png new file mode 100644 index 0000000..39c32ce Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-5-1.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-6-1.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-6-1.png new file mode 100644 index 0000000..00f7c9e Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-6-1.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-7-1.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-7-1.png new file mode 100644 index 0000000..ad526fd Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-7-1.png differ diff --git a/docs/vignettes/fig/wo_theme_unnamed-chunk-7-2.png b/docs/vignettes/fig/wo_theme_unnamed-chunk-7-2.png new file mode 100644 index 0000000..7ad8115 Binary files /dev/null and b/docs/vignettes/fig/wo_theme_unnamed-chunk-7-2.png differ diff --git a/docs/vignettes/how_to_create_faceted_maps.Rmd b/docs/vignettes/how_to_create_faceted_maps.Rmd new file mode 100644 index 0000000..0fac60d --- /dev/null +++ b/docs/vignettes/how_to_create_faceted_maps.Rmd @@ -0,0 +1,61 @@ +--- +title: "How to Create Faceted Maps" +author: "Timothée Giraud" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{How to Create Faceted Maps} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.width = 7, + fig.height = 4, + fig.path = "fig/wo_facet_", + eval = TRUE + +) +``` + +To plot several maps on the same figure, the user can use the `mfrow` argument of the `par()` function before plotting the maps. +For example, use `par(mfrow = c(1, 2))` (i.e. 1 row, 2 columns) to plot two maps side by side). + +```{r, fig.height=4, fig.width=7, results = FALSE} +library(mapsf) +mtq <- mf_get_mtq() +# define the figure layout (1 row, 2 columns) +par(mfrow = c(1, 2)) +# first map +mf_map(mtq) +mf_map(mtq, "POP", "prop") +mf_title("Population") +# second map +mf_map(mtq, "MED", "choro") +mf_title("Median Income") +``` + + +When relevant the user can use a `for` loop. +```{r, fig.height = 8, fig.width = 7, results = FALSE} +# define the figure layout (6 rows and 6 columns) +par(mfrow = c(6, 6)) +for (i in seq_len(nrow(mtq))) { + # center the map on a targeted municipality and its + # neighborhood (with mf_map(..., col = NA, border = NA) and its expandBB arg) + mf_map(mtq[i, ], col = NA, border = NA, expandBB = c(.3, .3, .3, .3)) + # plot the municpalities + mf_map(mtq, border = "white", lwd = .5, add = TRUE) + # plot the shadow of the targeted municpality + mf_shadow(mtq[i, ], cex = .75, col = "grey60", add = TRUE) + # plot the targeted municipality + mf_map(mtq[i, ], col = "tomato1", border = "grey60", add = TRUE) + # add a title + mf_title(mtq[[i, "LIBGEO"]]) +} +``` + diff --git a/docs/vignettes/how_to_create_faceted_maps.md b/docs/vignettes/how_to_create_faceted_maps.md new file mode 100644 index 0000000..1711d10 --- /dev/null +++ b/docs/vignettes/how_to_create_faceted_maps.md @@ -0,0 +1,46 @@ +# How to Create Faceted Maps +Timothée Giraud +2025-01-22 + +To plot several maps on the same figure, the user can use the `mfrow` +argument of the `par()` function before plotting the maps. For example, +use `par(mfrow = c(1, 2))` (i.e. 1 row, 2 columns) to plot two maps side +by side). + +``` r +library(mapsf) +mtq <- mf_get_mtq() +# define the figure layout (1 row, 2 columns) +par(mfrow = c(1, 2)) +# first map +mf_map(mtq) +mf_map(mtq, "POP", "prop") +mf_title("Population") +# second map +mf_map(mtq, "MED", "choro") +mf_title("Median Income") +``` + +![](fig/wo_facet_unnamed-chunk-2-1.png) + +When relevant the user can use a `for` loop. + +``` r +# define the figure layout (6 rows and 6 columns) +par(mfrow = c(6, 6)) +for (i in seq_len(nrow(mtq))) { + # center the map on a targeted municipality and its + # neighborhood (with mf_map(..., col = NA, border = NA) and its expandBB arg) + mf_map(mtq[i, ], col = NA, border = NA, expandBB = c(.3, .3, .3, .3)) + # plot the municpalities + mf_map(mtq, border = "white", lwd = .5, add = TRUE) + # plot the shadow of the targeted municpality + mf_shadow(mtq[i, ], cex = .75, col = "grey60", add = TRUE) + # plot the targeted municipality + mf_map(mtq[i, ], col = "tomato1", border = "grey60", add = TRUE) + # add a title + mf_title(mtq[[i, "LIBGEO"]]) +} +``` + +![](fig/wo_facet_unnamed-chunk-3-1.png) diff --git a/docs/vignettes/how_to_create_inset_maps.Rmd b/docs/vignettes/how_to_create_inset_maps.Rmd new file mode 100644 index 0000000..be1f50e --- /dev/null +++ b/docs/vignettes/how_to_create_inset_maps.Rmd @@ -0,0 +1,186 @@ +--- +title: "How to Create Inset Maps" +author: "Timothée Giraud" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{How to Create Inset Maps} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "fig/wo_inset_" +) +``` + + + + +**`mf_inset*()`** functions create map insets. +`mf_inset_on()` starts the inset and `mf_inset_off()` closes it. + + +If map layers have to be plotted after the inset (i.e after `mf_inset_off()`), please use `add = TRUE`. +It is not possible to plot an inset within an inset. +It is possible to plot anything (base plots) within the inset, not only map layers. + + + +## Size and Position + +There is 2 solutions for defining the size and position of an inset. + +The first solution is based on `x`, `pos` and `cex` arguments: + +- `x` is an sf object, the width/height ratio of the inset will match the width/height ratio of `x` bounding box; +- `pos` must be one of "bottomleft", "left", "topleft", "top", "bottom", "bottomright", "right" or"topright"; +- `cex` defines the share of the map width covered by the inset (0.5 means 50%). + +In the following example we create an inset for a specific municipality in the topright corner of the map. + +```{r, fig.height=5.71, fig.width=6, results = FALSE} +library(mapsf) +# set a theme +mf_theme("default", mar = c(0, 0, 0, 0)) +# data import +mtq <- mf_get_mtq() +# Selection of a target municipality to display in the inset +mtq_target <- mtq[c(26), ] +# Display the base map +mf_map(mtq, expandBB = c(0, 0, 0, .25)) +# display the target on the main map +mf_map(mtq_target, add = TRUE, col = "tomato") +# open the inset +mf_inset_on(x = mtq_target, pos = "topright", cex = .3) +# display the target municipality +mf_map(mtq_target, add = FALSE, col = "tomato") +# close the inset +mf_inset_off() +``` + +Once an inset is opened, map elements can be added to it. +Here we add a title, a shadow, a scale bar, other Martinique municipalities and a frame. + +```{r, fig.height=5.71, fig.width=6, results = FALSE} +# set a theme +mf_theme("dark") +# Selection of a target municipality to display in the inset +mtq_target <- mtq[c(26), ] +# Display the base map +mf_map(mtq, expandBB = c(0, 0, 0, .25)) +# display the target on the main map +mf_map(mtq_target, add = TRUE, col = "tomato") +# open the inset +mf_inset_on(x = mtq_target, pos = "topright", cex = .3) +# center on on the target munucipality +mf_map(mtq_target, col = NA, border = NA) +# display all municipalities +mf_map(mtq, add = TRUE) +# display the target municipality shadow +mf_shadow(mtq_target, add = TRUE) +# display the target municipality +mf_map(mtq_target, add = TRUE, col = "tomato") +# display a title +mf_title("Saint-Anne", + pos = "left", tab = TRUE, + cex = .9, line = 1, inner = TRUE +) +# display a scale bar +mf_scale(size = 2) +# dispaly a frame around the inset +box() +# close the inset +mf_inset_off() +# display the map layout of the main map +mf_title("Martinique Municipalities") +# display a scale bar +mf_scale(size = 5) +# display credits +mf_credits(txt = "T. Giraud, 2021") +``` + +The second solution to set the size and position of an inset is to use the `fig` argument. +`fig` coordinates (xmin, xmax, ymin, ymax) are expressed as fractions of the mapping space (i.e. excluding margins). +`mf_inset_on(fig = c(0, 0.25, 0, 0.25))` will create an inset on the bottomleft corner of the map and will cover a quarter of the map in width and height. + +In the following example we create an inset for a specific municipality in the bottom left corner of the map. + +```{r, fig.height=6, fig.width=5, results = FALSE} +# set a theme +mf_theme("default", mar = c(0, 0, 0, 0)) +# Display the base map +mf_map(mtq) +# open the inset +mf_inset_on(fig = c(0, 0.25, 0, 0.25)) +# display a municipality +mf_map(mtq[9, ]) +# add a frame +box() +# close the inset +mf_inset_off() +``` + + +## World Map Inset + +It is easy to create an inset with a world map (see `mf_worldmap()`) using `x = "worldmap"`. + +```{r, fig.height=6, fig.width=5, results = FALSE} +mf_map(mtq) +mf_inset_on(x = "worldmap") +mf_worldmap(mtq) +mf_inset_off() +``` + + + +## Non-cartographic Insets +Insets can be used for regular plots. In the next map we create an inset with an histogram of the median income distribution using the map classification. + +```{r, fig.height=7.58, fig.width=6.25, results = FALSE} +# create classes +bks <- mf_get_breaks(x = mtq$MED, nbreaks = 5, breaks = "quantile") +bks <- round(bks, digits = -2) +# define a color palette +pal <- hcl.colors(n = 5, palette = "Dark Mint", rev = TRUE) +# set a theme +mf_theme("candy") +fg <- getOption("mapsf.fg") +# Create the map +mf_map( + x = mtq, var = "MED", type = "choro", + pal = pal, breaks = bks, leg_pos = NA +) +# start the inset +mf_inset_on(fig = c(0.75, .95, 0.84, .99)) +# draw the histogram +par(mar = c(0, 0, 1.7, 0)) +hist(mtq$MED, + breaks = bks, col = pal, border = fg, axes = FALSE, labels = "", + xlab = "", ylab = "", main = "" +) +axis( + side = 1, at = bks, las = 2, tick = FALSE, line = -.9, + cex.axis = .7, col.axis = fg +) +title("Median Income\nin euros", + cex.main = .8, col.main = fg, + font.main = 1, adj = 0 +) +# close the inset +mf_inset_off() +# Add map layout +mf_title("Wealth in Martinique, 2015", pos = "left") +mf_scale(5) +mf_credits(paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", packageVersion("mapsf") +)) +``` + diff --git a/docs/vignettes/how_to_create_inset_maps.md b/docs/vignettes/how_to_create_inset_maps.md new file mode 100644 index 0000000..7e4509e --- /dev/null +++ b/docs/vignettes/how_to_create_inset_maps.md @@ -0,0 +1,185 @@ +# How to Create Inset Maps +Timothée Giraud +2025-01-22 + +**`mf_inset*()`** functions create map insets. `mf_inset_on()` starts +the inset and `mf_inset_off()` closes it. + +If map layers have to be plotted after the inset (i.e after +`mf_inset_off()`), please use `add = TRUE`. +It is not possible to plot an inset within an inset. +It is possible to plot anything (base plots) within the inset, not only +map layers. + +## Size and Position + +There is 2 solutions for defining the size and position of an inset. + +The first solution is based on `x`, `pos` and `cex` arguments: + +- `x` is an sf object, the width/height ratio of the inset will match + the width/height ratio of `x` bounding box; +- `pos` must be one of “bottomleft”, “left”, “topleft”, “top”, + “bottom”, “bottomright”, “right” or”topright”; +- `cex` defines the share of the map width covered by the inset (0.5 + means 50%). + +In the following example we create an inset for a specific municipality +in the topright corner of the map. + +``` r +library(mapsf) +# set a theme +mf_theme("default", mar = c(0, 0, 0, 0)) +# data import +mtq <- mf_get_mtq() +# Selection of a target municipality to display in the inset +mtq_target <- mtq[c(26), ] +# Display the base map +mf_map(mtq, expandBB = c(0, 0, 0, .25)) +# display the target on the main map +mf_map(mtq_target, add = TRUE, col = "tomato") +# open the inset +mf_inset_on(x = mtq_target, pos = "topright", cex = .3) +# display the target municipality +mf_map(mtq_target, add = FALSE, col = "tomato") +# close the inset +mf_inset_off() +``` + +![](fig/wo_inset_unnamed-chunk-2-1.png) + +Once an inset is opened, map elements can be added to it. +Here we add a title, a shadow, a scale bar, other Martinique +municipalities and a frame. + +``` r +# set a theme +mf_theme("dark") +# Selection of a target municipality to display in the inset +mtq_target <- mtq[c(26), ] +# Display the base map +mf_map(mtq, expandBB = c(0, 0, 0, .25)) +# display the target on the main map +mf_map(mtq_target, add = TRUE, col = "tomato") +# open the inset +mf_inset_on(x = mtq_target, pos = "topright", cex = .3) +# center on on the target munucipality +mf_map(mtq_target, col = NA, border = NA) +# display all municipalities +mf_map(mtq, add = TRUE) +# display the target municipality shadow +mf_shadow(mtq_target, add = TRUE) +# display the target municipality +mf_map(mtq_target, add = TRUE, col = "tomato") +# display a title +mf_title("Saint-Anne", + pos = "left", tab = TRUE, + cex = .9, line = 1, inner = TRUE +) +# display a scale bar +mf_scale(size = 2) +# dispaly a frame around the inset +box() +# close the inset +mf_inset_off() +# display the map layout of the main map +mf_title("Martinique Municipalities") +# display a scale bar +mf_scale(size = 5) +# display credits +mf_credits(txt = "T. Giraud, 2021") +``` + +![](fig/wo_inset_unnamed-chunk-3-1.png) + +The second solution to set the size and position of an inset is to use +the `fig` argument. +`fig` coordinates (xmin, xmax, ymin, ymax) are expressed as fractions of +the mapping space (i.e. excluding margins). +`mf_inset_on(fig = c(0, 0.25, 0, 0.25))` will create an inset on the +bottomleft corner of the map and will cover a quarter of the map in +width and height. + +In the following example we create an inset for a specific municipality +in the bottom left corner of the map. + +``` r +# set a theme +mf_theme("default", mar = c(0, 0, 0, 0)) +# Display the base map +mf_map(mtq) +# open the inset +mf_inset_on(fig = c(0, 0.25, 0, 0.25)) +# display a municipality +mf_map(mtq[9, ]) +# add a frame +box() +# close the inset +mf_inset_off() +``` + +![](fig/wo_inset_unnamed-chunk-4-1.png) + +## World Map Inset + +It is easy to create an inset with a world map (see `mf_worldmap()`) +using `x = "worldmap"`. + +``` r +mf_map(mtq) +mf_inset_on(x = "worldmap") +mf_worldmap(mtq) +mf_inset_off() +``` + +![](fig/wo_inset_unnamed-chunk-5-1.png) + +## Non-cartographic Insets + +Insets can be used for regular plots. In the next map we create an inset +with an histogram of the median income distribution using the map +classification. + +``` r +# create classes +bks <- mf_get_breaks(x = mtq$MED, nbreaks = 5, breaks = "quantile") +bks <- round(bks, digits = -2) +# define a color palette +pal <- hcl.colors(n = 5, palette = "Dark Mint", rev = TRUE) +# set a theme +mf_theme("candy") +fg <- getOption("mapsf.fg") +# Create the map +mf_map( + x = mtq, var = "MED", type = "choro", + pal = pal, breaks = bks, leg_pos = NA +) +# start the inset +mf_inset_on(fig = c(0.75, .95, 0.84, .99)) +# draw the histogram +par(mar = c(0, 0, 1.7, 0)) +hist(mtq$MED, + breaks = bks, col = pal, border = fg, axes = FALSE, labels = "", + xlab = "", ylab = "", main = "" +) +axis( + side = 1, at = bks, las = 2, tick = FALSE, line = -.9, + cex.axis = .7, col.axis = fg +) +title("Median Income\nin euros", + cex.main = .8, col.main = fg, + font.main = 1, adj = 0 +) +# close the inset +mf_inset_off() +# Add map layout +mf_title("Wealth in Martinique, 2015", pos = "left") +mf_scale(5) +mf_credits(paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", packageVersion("mapsf") +)) +``` + +![](fig/wo_inset_unnamed-chunk-6-1.png) diff --git a/docs/vignettes/how_to_export_maps.Rmd b/docs/vignettes/how_to_export_maps.Rmd new file mode 100644 index 0000000..d1f3ce0 --- /dev/null +++ b/docs/vignettes/how_to_export_maps.Rmd @@ -0,0 +1,112 @@ +--- +title: "How to Export Maps" +author: "Timothée Giraud" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{How to Export Maps} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + + + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.width = 4, + fig.height = 4, + eval = FALSE +) +``` + + +**`mf_export()`** exports maps in PNG or SVG formats. +The exported map width/height ratio will match the one of a spatial object. +If `width` is specified, then `height` is deduced from the width/height ratio of `x` and some theme parameters (figure margins and title size). +If `height` is specified, then `width` is deduced from the width/height ratio of `x`and some theme parameters (figure margins and title size). +Additionally, `mf_export()` (and `mf_map()`) can be used to extend the map space on one or several side of the figure, or to center a map on a specific area. + + +## Simple Export + +In this example we only set the `width` of the exported figure. + +```{r, results="hide"} +library(mapsf) +mtq <- mf_get_mtq() +mf_export( + x = mtq, + filename = "fixed_width.png", + width = 500 +) +mf_map(mtq, add = TRUE) +mf_title(txt = "PNG export: width=500px, height=605px (deduced)") +dev.off() +``` + +![](fig/wo_export_fixed_width.png) + +**Note that we have to set `add = TRUE` to the first layer plotted.** Internally, `mf_export()` start a device (PNG or SVG) with a specific dimension (figure size) and extent (`x` extent). + + +## Export with Extra Space on the Figure + +Here we have added some space on the right side of the plot (50% of `x` width). + +```{r, results="hide"} +mf_theme("dark") +mf_export( + x = mtq, + filename = "fixed_width_expand.png", + width = 500, + expandBB = c(0, 0, 0, .5), +) +mf_map(mtq, add = TRUE) +mf_title(txt = "PNG export: width=500px, height=432px (deduced)") +dev.off() +mf_theme(NULL) +``` +![](fig/wo_export_fixed_width_expand.png) + +**Note that `mf_export()` uses the current theme. If a theme is set between an `mf_export()` call and a `dev.off()` call it will not be correctly applied.** + + +## Center the Map on a Specific Area +In this export, the map is focused on a specific spatial object. `height` is fixed and `width` is deduced. + +```{r, results="hide"} +target <- mtq[5, ] +mf_export(x = target, filename = "fixed_height_centered.png", height = 600) +mf_map(mtq, add = TRUE) +mf_shadow(target, add = TRUE) +mf_map(target, add = TRUE) +mf_title(txt = "PNG export: height=600px, width=433px (deduced)") +mf_scale(1, pos = "bottomleft") +dev.off() +``` +![](fig/wo_export_fixed_height_centered.png) + +## Other Parameters +`mf_export()` can produce SVG figures (with `export = "svg"`) and use other parameters of `png()` or `svg()` functions (e.g. `res`, `bg` or `family`). + +```{r, results="hide"} +mf_theme("nevermind") +mf_export( + x = mtq, + filename = "fixed_width.svg", + width = 5, + bg = "black" +) +mf_map(mtq, add = TRUE) +mf_title(txt = "SVG export: bg = 'black'") +dev.off() +mf_theme(NULL) +``` + +![](fig/wo_export_fixed_width.svg) + + + + diff --git a/docs/vignettes/how_to_export_maps.md b/docs/vignettes/how_to_export_maps.md new file mode 100644 index 0000000..5782b86 --- /dev/null +++ b/docs/vignettes/how_to_export_maps.md @@ -0,0 +1,103 @@ +# How to Export Maps +Timothée Giraud +2025-01-22 + +**`mf_export()`** exports maps in PNG or SVG formats. +The exported map width/height ratio will match the one of a spatial +object. +If `width` is specified, then `height` is deduced from the width/height +ratio of `x` and some theme parameters (figure margins and title +size). +If `height` is specified, then `width` is deduced from the width/height +ratio of `x`and some theme parameters (figure margins and title size). +Additionally, `mf_export()` (and `mf_map()`) can be used to extend the +map space on one or several side of the figure, or to center a map on a +specific area. + +## Simple Export + +In this example we only set the `width` of the exported figure. + +``` r +library(mapsf) +mtq <- mf_get_mtq() +mf_export( + x = mtq, + filename = "fixed_width.png", + width = 500 +) +mf_map(mtq, add = TRUE) +mf_title(txt = "PNG export: width=500px, height=605px (deduced)") +dev.off() +``` + +![](fig/wo_export_fixed_width.png) + +**Note that we have to set `add = TRUE` to the first layer plotted.** +Internally, `mf_export()` start a device (PNG or SVG) with a specific +dimension (figure size) and extent (`x` extent). + +## Export with Extra Space on the Figure + +Here we have added some space on the right side of the plot (50% of `x` +width). + +``` r +mf_theme("dark") +mf_export( + x = mtq, + filename = "fixed_width_expand.png", + width = 500, + expandBB = c(0, 0, 0, .5), +) +mf_map(mtq, add = TRUE) +mf_title(txt = "PNG export: width=500px, height=432px (deduced)") +dev.off() +mf_theme(NULL) +``` + +![](fig/wo_export_fixed_width_expand.png) + +**Note that `mf_export()` uses the current theme. If a theme is set +between an `mf_export()` call and a `dev.off()` call it will not be +correctly applied.** + +## Center the Map on a Specific Area + +In this export, the map is focused on a specific spatial object. +`height` is fixed and `width` is deduced. + +``` r +target <- mtq[5, ] +mf_export(x = target, filename = "fixed_height_centered.png", height = 600) +mf_map(mtq, add = TRUE) +mf_shadow(target, add = TRUE) +mf_map(target, add = TRUE) +mf_title(txt = "PNG export: height=600px, width=433px (deduced)") +mf_scale(1, pos = "bottomleft") +dev.off() +``` + +![](fig/wo_export_fixed_height_centered.png) + +## Other Parameters + +`mf_export()` can produce SVG figures (with `export = "svg"`) and use +other parameters of `png()` or `svg()` functions (e.g. `res`, `bg` or +`family`). + +``` r +mf_theme("nevermind") +mf_export( + x = mtq, + filename = "fixed_width.svg", + width = 5, + bg = "black" +) +mf_map(mtq, add = TRUE) +mf_title(txt = "SVG export: bg = 'black'") +dev.off() +mf_theme(NULL) +``` + +![](fig/wo_export_fixed_width.svg) diff --git a/docs/vignettes/how_to_use_a_custom_font_family.Rmd b/docs/vignettes/how_to_use_a_custom_font_family.Rmd new file mode 100644 index 0000000..d19d06d --- /dev/null +++ b/docs/vignettes/how_to_use_a_custom_font_family.Rmd @@ -0,0 +1,55 @@ +--- +title: "How to Use a Custom Font Family" +author: "Timothée Giraud" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{How to Use a Custom Font Family} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + + +To use a custom font family, the user can use the `family` argument of the `par()` function before plotting the map. +For example, use `par(family = "Fira Code")` to use the **Fira Code** font. +Note that the font has to be installed on your system and recognized by R. + + +```{r a, fig.width = 6, fig.height = 7, cache=FALSE, dpi=110, eval = FALSE, fig.path="fig/wo_font_"} +library(mapsf) +library(sf) +# Import the sample data set +mtq <- mf_get_mtq() +# population density (inhab./km2) using sf::st_area() +mtq$POPDENS <- 1e6 * mtq$POP / st_area(mtq) +# Define the font family +# !! Select a font already installed on your system !! +par(family = "Fira Code") +# set a theme +mf_theme("green") +# plot population density +mf_map( + x = mtq, + var = "POPDENS", + type = "choro", + breaks = "q6", + nbreaks = 4, + pal = "Greens", + border = "grey60", + lwd = 0.5, + leg_val_rnd = 0, + leg_pos = "topright", + leg_title = "Population Density\n(people per km2)" +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +![](fig/wo_font_a-1.png) diff --git a/docs/vignettes/how_to_use_a_custom_font_family.md b/docs/vignettes/how_to_use_a_custom_font_family.md new file mode 100644 index 0000000..b24542b --- /dev/null +++ b/docs/vignettes/how_to_use_a_custom_font_family.md @@ -0,0 +1,48 @@ +# How to Use a Custom Font Family +Timothée Giraud +2025-01-22 + +To use a custom font family, the user can use the `family` argument of +the `par()` function before plotting the map. For example, use +`par(family = "Fira Code")` to use the **Fira Code** font. +Note that the font has to be installed on your system and recognized by +R. + +``` r +library(mapsf) +library(sf) +# Import the sample data set +mtq <- mf_get_mtq() +# population density (inhab./km2) using sf::st_area() +mtq$POPDENS <- 1e6 * mtq$POP / st_area(mtq) +# Define the font family +# !! Select a font already installed on your system !! +par(family = "Fira Code") +# set a theme +mf_theme("green") +# plot population density +mf_map( + x = mtq, + var = "POPDENS", + type = "choro", + breaks = "q6", + nbreaks = 4, + pal = "Greens", + border = "grey60", + lwd = 0.5, + leg_val_rnd = 0, + leg_pos = "topright", + leg_title = "Population Density\n(people per km2)" +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +![](fig/wo_font_a-1.png) diff --git a/docs/vignettes/how_to_use_themes.Rmd b/docs/vignettes/how_to_use_themes.Rmd new file mode 100644 index 0000000..ed5a5e2 --- /dev/null +++ b/docs/vignettes/how_to_use_themes.Rmd @@ -0,0 +1,102 @@ +--- +title: "How to Use Themes" +author: "Timothée Giraud" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{How to Use Themes} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.width = 4, + fig.height = 4, + fig.path = "fig/wo_theme_" +) +``` + + +**`mf_theme()`** sets a map theme. A theme is a set of graphical parameters that are applied to maps created with `mapsf`. These parameters are the figure margins, background and foreground colors and `mf_title()` options. `mapsf` offers some builtin themes. It's possible to modify an existing theme or to start a theme from scratch. +Themes are persistent across maps produced by `mapsf` (e.g. they survive a `dev.off()` call). + +## Builtin themes + +Here are the builtin themes. We have added a grey background color to make the margins more visible. +```{r, echo = FALSE} +par(bg = "grey") +suppressPackageStartupMessages(library(mapsf)) +themes <- c( + "default", "ink", "dark", "agolalight", "candy", + "darkula", "iceberg", "green", "nevermind", "jsk", "barcelona" +) +mtq <- mf_get_mtq() +for (i in themes) { + mf_theme(i) + mf_map(mtq) + mf_title(paste0('"', i, '"')) + box(which = "figure", col = "white") +} +``` + +The following table displays the parameters of these themes. + +```{r, echo = FALSE} +a <- NULL +for (i in themes) { + ax <- mf_theme(i) + a <- rbind(a, paste0(ax)) +} +a <- as.data.frame(a, row.names = themes) +names(a) <- c("bg", "fg", "mar", "tab", "pos", "inner", "line", "cex", "font") +# pipe tables by default +knitr::kable(a) +``` + +## How to modify an existing theme + +It is possible to modify an existing theme. In this example we use the "default" theme and modify some title parameters. +```{r, echo = FALSE} +par(bg = "grey") +``` +```{r} +library(mapsf) +mtq <- mf_get_mtq() +mf_theme("default", tab = FALSE, font = 4) +mf_map(mtq) +mf_title('Mofified "default" theme') +``` + +## How to create a new theme + +It is possible to create a new theme. + +```{r} +mf_theme( + bg = "lightblue", fg = "tomato1", mar = c(0, 2, 0, 2), + tab = TRUE, inner = TRUE, line = 1.3, pos = "center", + cex = 1.1, font = 3 +) +mf_map(mtq) +mf_title("New theme") +``` + + +It is also possible to assign a theme to a variable. + + +```{r} +blue_theme <- mf_theme("dark", bg = "lightblue") +green_theme <- mf_theme("default", bg = "lightgreen") +mf_theme(blue_theme) +mf_map(mtq) +mf_title("Blue Theme") +mf_theme(green_theme) +mf_map(mtq) +mf_title("Green Theme") +``` + + diff --git a/docs/vignettes/how_to_use_themes.md b/docs/vignettes/how_to_use_themes.md new file mode 100644 index 0000000..8e93d14 --- /dev/null +++ b/docs/vignettes/how_to_use_themes.md @@ -0,0 +1,254 @@ +# How to Use Themes +Timothée Giraud +2025-01-22 + +**`mf_theme()`** sets a map theme. A theme is a set of graphical +parameters that are applied to maps created with `mapsf`. These +parameters are the figure margins, background and foreground colors and +`mf_title()` options. `mapsf` offers some builtin themes. It’s possible +to modify an existing theme or to start a theme from scratch. Themes are +persistent across maps produced by `mapsf` (e.g. they survive a +`dev.off()` call). + +## Builtin themes + +Here are the builtin themes. We have added a grey background color to +make the margins more visible. + +![](fig/wo_theme_unnamed-chunk-2-1.png) + +![](fig/wo_theme_unnamed-chunk-2-2.png) + +![](fig/wo_theme_unnamed-chunk-2-3.png) + +![](fig/wo_theme_unnamed-chunk-2-4.png) + +![](fig/wo_theme_unnamed-chunk-2-5.png) + +![](fig/wo_theme_unnamed-chunk-2-6.png) + +![](fig/wo_theme_unnamed-chunk-2-7.png) + +![](fig/wo_theme_unnamed-chunk-2-8.png) + +![](fig/wo_theme_unnamed-chunk-2-9.png) + +![](fig/wo_theme_unnamed-chunk-2-10.png) + +![](fig/wo_theme_unnamed-chunk-2-11.png) + +The following table displays the parameters of these themes. + + ++++++++++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
bgfgmartabposinnerlinecexfont
default#f7f7f7#333333c(0.5, 0.5, 1.7, 0.5)TRUEleftFALSE1.211
ink#FFDEAD#0000FFc(0, 0, 1.2, 0)FALSEleftFALSE1.20.92
dark#2E3947#7E848Cc(0.5, 0.5, 2, 0.5)FALSEleftFALSE1.511
agolalight#EDF4F5#82888Ac(0, 0, 2, 0)FALSEleftFALSE21.53
candy#FDFCFE#6B1767c(0, 0, 2, 0)FALSEcenterFALSE21.52
darkula#232525#A9B7C6c(0.5, 0.5, 0.5, 0.5)TRUErightTRUE1.514
iceberg#0B0E0E#BDD6DBc(0.5, 0.5, 0.5, 0.5)TRUErightTRUE1.514
green#1B1D16#D7FF68c(0.5, 0.5, 2, 0.5)FALSEcenterFALSE1.512
nevermind#4DB8DA#121725c(2, 2, 3.5, 2)FALSEcenterFALSE1.51.41
jsk#ffdc11#0c973cc(0, 0, 1.5, 0)FALSEleftFALSE1.512
barcelona#160808#d73e23c(0, 0, 1.2, 0)TRUEleftFALSE1.212
+ +## How to modify an existing theme + +It is possible to modify an existing theme. In this example we use the +“default” theme and modify some title parameters. + +``` r +library(mapsf) +mtq <- mf_get_mtq() +mf_theme("default", tab = FALSE, font = 4) +mf_map(mtq) +mf_title('Mofified "default" theme') +``` + +![](fig/wo_theme_unnamed-chunk-5-1.png) + +## How to create a new theme + +It is possible to create a new theme. + +``` r +mf_theme( + bg = "lightblue", fg = "tomato1", mar = c(0, 2, 0, 2), + tab = TRUE, inner = TRUE, line = 1.3, pos = "center", + cex = 1.1, font = 3 +) +mf_map(mtq) +mf_title("New theme") +``` + +![](fig/wo_theme_unnamed-chunk-6-1.png) + +It is also possible to assign a theme to a variable. + +``` r +blue_theme <- mf_theme("dark", bg = "lightblue") +green_theme <- mf_theme("default", bg = "lightgreen") +mf_theme(blue_theme) +mf_map(mtq) +mf_title("Blue Theme") +``` + +![](fig/wo_theme_unnamed-chunk-7-1.png) + +``` r +mf_theme(green_theme) +mf_map(mtq) +mf_title("Green Theme") +``` + +![](fig/wo_theme_unnamed-chunk-7-2.png) diff --git a/docs/vignettes/mapsf.Rmd b/docs/vignettes/mapsf.Rmd new file mode 100644 index 0000000..19f2247 --- /dev/null +++ b/docs/vignettes/mapsf.Rmd @@ -0,0 +1,463 @@ +--- +title: 'mapsf' +author: "Timothée Giraud" +date: '`r Sys.Date()`' +output: + rmarkdown::html_vignette: + fig_width: 8 + toc: true + toc_depth: 1 + number_sections: true +vignette: > + %\VignetteIndexEntry{mapsf} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.width = 5, + fig.height = 6 +) +``` + +# Introduction + +The aim of `mapsf` is to obtain thematic maps with the visual quality of those build with a classical mapping or GIS software. +`mapsf` uses [`sf`](https://CRAN.R-project.org/package=sf) objects to produce `base` graphics. +`mapsf` functions can be classified in the following categories: + +- **Symbology**\ +`mf_map()` is the main function of the package, it displays map layers on a georeferenced plot. Many parameters are available to fine tune the cartographic representations. These parameters are the common ones found in GIS and automatic cartography tools (e.g. classification and color palettes used in choropleth maps, symbols sizes used in proportional symbols maps...). + +- **Map Layout**\ +Along with the cartographic functions, some other functions are dedicated to layout design (e.g. legends, scale bar, north arrow, title, credits...). + +- **Utility Functions**\ + A set of functions is dedicated to the creation of spatial objects (e.g. links creation) or other utility tasks (e.g. color palette management, class intervals extraction, sample dataset import...). + + + +# Main Features + +## Symbology + +`mf_map()` has three main arguments: + +* `x` an sf object +* `var` the name(s) of a variable(s) to map +* `type` the map layer type + +The following map types are available: + +* ![](fig/mf_base.svg) **base**: displays sf objects geometries +* ![](fig/mf_prop.svg) **prop**: displays symbols with areas proportional to a quantitative variable (stocks) +* ![](fig/mf_choro.svg) **choro**: areas are shaded according to the variation of a quantitative variable +* ![](fig/mf_typo.svg) **typo**: displays a typology map of a qualitative variable +* ![](fig/mf_symb.svg) **symb**: displays the different modalities of a qualitative variable as symbols +* ![](fig/mf_grad.svg) **grad**: displays graduated symbols +* ![](fig/mf_prop_choro.svg) **prop_choro**: displays symbols with sizes proportional to values of a first variable and colored to reflect the classification of a second quantitative variable +* ![](fig/mf_prop_typo.svg) **prop_typo**: displays symbols with sizes proportional to values of a first variable and and colored to reflect the modalities of a second qualitative variable +* ![](fig/mf_symb_choro.svg) **symb_choro**: displays the different modalities of a first qualitative variable as symbols colored to reflect the classification of a second quantitative variable + + +Additionaly, `mf_raster()` can be used to displays raster objects (single/multi band, continuous, classes, intervals). + + + + + +## Map Layout + +These functions are dedicated to the map layout design. + + +![](fig/maplayout.png) + +| | | +|--------|----------------------| +| ① `mf_title()` | Title of the map | +| ② `mf_arrow()` | North arrow | +| ③ `mf_credits()` | Author, sources... | +| ④ `mf_scale()` | Scale bar | +| ⑤ `mf_annotation()` | Annotations | +| ⑥ `mf_label()` | Labels | +| ⑦ `mf_shadow()` | Shadow | + + +## Themes + +`mf_theme()` sets a map theme. A theme is a set of graphical parameters that are applied to maps created with `mapsf`. These parameters are the figure margins, background and foreground colors and `mf_title()` options. `mapsf` offers some builtin themes. It’s possible to modify an existing theme or to start a theme from scratch. Themes are persistent across maps produced by mapsf (e.g. they survive a `dev.off()` call). + +🔗 See the online vignette: [How to use themes](https://riatelab.github.io/mapsf/articles/web_only/how_to_use_themes.html) + +## Export + +`mf_export()` exports maps in PNG or SVG formats. +The exported map width/height ratio will match the one of a spatial object. +If width is specified, then height is deduced from the width/height ratio of x and some theme parameters (figure margins and title size). +If height is specified, then width is deduced from the width/height ratio of xand some theme parameters (figure margins and title size). + +🔗 See the online vignette: [How to export maps](https://riatelab.github.io/mapsf/articles/web_only/how_to_export_maps.html) + +## Datasets + +Several datasets are embedded in the package: + +- A [GeoPackage](https://www.geopackage.org/) of Martinique municipalities can be imported with `mf_get_mtq()` (or via `sf::st_read()`). + - Sources: [Base comparateur de territoires](https://www.insee.fr/fr/statistiques/2521169) (data, upload date: 2018-09-25) & ADMIN EXPRESS-COG (geometry, 2018 edition). + - Citation: Insee and IGN, 2018 + - Fields: + - **INSEE_COM**: Municipality identifier + - **STATUS**: Municipality administrative status + - **LIBGEO**: Municipality name + - **POP**: Total population, 2015 + - **MED**: Median disposable income adjusted per equivalent household member, in euros, 2015 + - **CHOM**: Unemployed population, 2015 + - **ACT**: Active population, 2015 + +- A csv file of professional mobility flows between Martinique municipalities. + - Sources: [Flux de mobilité - déplacements domicile-lieu de travail](https://www.insee.fr/fr/statistiques/3566477) (upload date: 2018-08-01) + - Citation: Insee, 2018 + - Fields: + - **i**: Municipality of residence identifier + - **j**: Municipality of workplace identifier + - **fij**: Flows of workers (employed population, 15 y.o. or more, 2015, only flows \> 100) + - **sj**: Administrative status of the workplace municipality + +# Examples of thematic maps + +## Base map + +`mf_theme()` allows to apply a theme to the map. + +`mf_shadow()` plots the shadow of a polygon layer. + +`mf_map(x, type = "base")` displays `sf` objects geometries. + +`mf_layout()` add a complete layout to the map (title, credits, north arrow, scale bar). Each layout elements can also be set separately (with `mf_title()`, `mf_credits()`, `mf_arrow()` and `mf_scale()`). + +```{r mf_basemap, message=FALSE, warning=FALSE} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set a theme +mf_theme("iceberg") +# plot a shadow +mf_shadow(mtq) +# plot municipalities +mf_map(mtq, type = "base", add = TRUE) +# layout +mf_layout( + title = "Martinique", + credits = paste0( + "Sources: IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +## Proportional Symbols + +`mf_map(x, var, type = "prop")` displays symbols with areas proportional to a quantitative variable (stocks). The `inches` argument is used to customize the symbols sizes. + +```{r mf_prop, message=FALSE, warning=FALSE} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set a theme +mf_theme("darkula") +# plot a shadow +mf_shadow(mtq) +# plot municipalities +mf_map(mtq, add = TRUE) +# plot population +mf_map( + x = mtq, + var = "POP", + type = "prop", + inches = 0.25, + col = "brown4", + leg_pos = "topright", + leg_adj = c(0, -3), + leg_title = "Total population" +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +## Choropleth Map + +In choropleth maps, areas are shaded according to the variation of a quantitative variable. They are used to represent ratios or indices.\ +`mf_map(x, var, type = "choro")` displays choropleth maps . Arguments `nbreaks`, and `breaks` allow to customize the variable classification. `mf_get_breaks()` allows to classify data outside of the function itself. Colors palettes, defined with `pal`, can be created with `mf_get_pal()` or you can use palette names from `hcl.pals()`. + +Use `mf_theme()` to set a theme without plotting anything. + +```{r mf_map_c} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# population density (inhab./km2) using sf::st_area() +mtq$POPDENS <- 1e6 * mtq$POP / sf::st_area(mtq) +# set a theme +mf_theme("green") +# plot population density +mf_map( + x = mtq, + var = "POPDENS", + type = "choro", + breaks = "geom", + nbreaks = 5, + pal = "Greens", + border = "white", + lwd = 0.5, + leg_pos = "bottomleft", + leg_adj = c(0, 3), + leg_title = "Population Density\n(inh. / km2)" +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +## Typology Map + +`mf_map(x, var, type = "typo")` displays a typology map of a qualitative variable. `val_order` is used to set the modalities order in the legend. + +`mf_label()` displays labels on the map. + +```{r mf_map_t} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +mf_theme("dark") +# plot administrative status +mf_map( + x = mtq, + var = "STATUS", + type = "typo", + pal = c("aquamarine4", "yellow3", "wheat"), + lwd = .5, + val_order = c( + "Prefecture", + "Sub-prefecture", + "Simple municipality" + ), + leg_pos = "topright", + leg_adj = c(0, 1), + leg_title = "" +) +# labels for a few municipalities +mf_label( + x = mtq[mtq$STATUS != "Simple municipality", ], var = "LIBGEO", + cex = 0.9, halo = TRUE, r = 0.15 +) +# layout +mf_layout( + title = "Administrative Status", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +## Proportional Symbols using Choropleth Coloration + +`mf_map(x, var, type = "prop_choro")` creates a map of symbols that are proportional to values of a first variable and colored to reflect the classification of a second variable. + +`expandBB` argument in `mf_map()` allows to expand the map space. Here, we increase the space available on the right of the map to avoid overlaps between the legends and the map. + +```{r mf_map_pc, fig.width=5} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +mf_theme("candy") +# Plot the municipalities and expand the map space on the right +mf_map(x = mtq, expandBB = c(0, 0, 0, .15)) +# Plot symbols with choropleth coloration +mf_map( + x = mtq, + var = c("POP", "MED"), + type = "prop_choro", + border = "grey50", + lwd = 1, + leg_pos = c("topright"), + leg_title = c("Population", "Median Income\n(in euros)"), + breaks = "equal", + nbreaks = 4, + pal = "Greens", + leg_val_rnd = c(0, -2), + leg_frame = TRUE +) +# layout +mf_layout( + title = "Population & Wealth in Martinique, 2015", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ), + frame = TRUE +) +``` + +## Proportional Symbols using Typology Coloration + +`mf_map(x, var, type = "prop_typo")` creates a map of symbols that are proportional to values of a first variable and colored to reflect the modalities of a second qualitative variable. + +```{r mf_map_pt, fig.width=5} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +mf_theme("ink") +# plot the municipalities and expand the map space on the right +mf_map(x = mtq, expandBB = c(0, 0, 0, .15)) +# plot symbols with choropleth coloration +mf_map( + x = mtq, + var = c("POP", "STATUS"), + type = "prop_typo", + symbol = "square", + border = "white", + lwd = .5, + leg_pos = "topright", + leg_title = c("Population", "Administrative\nStatus"), + val_order = c( + "Prefecture", "Sub-prefecture", + "Simple municipality" + ) +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +## Label Map + +`mf_label()` is dedicated to the display of labels on a map. The `overlap = FALSE` argument displays non overlapping labels. + +In this example we have built a custom theme with `mf_theme()`. + +```{r mf_label} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +my_theme <- list( + name = "mytheme", + bg = "lightblue1", + fg = "darkseagreen4", + mar = c(0, 0, 0, 0), + tab = TRUE, + pos = "left", + inner = TRUE, + line = 1, + cex = .9, + font = 3 +) +mf_theme(my_theme) +# plot municipalities +mf_map(mtq, col = "#e4e9de", border = "darkseagreen4") +# plot labels +mf_label( + x = mtq, + var = "LIBGEO", + col = "black", + cex = 0.7, + font = 4, + halo = TRUE, + bg = "white", + r = 0.1, + overlap = FALSE, + lines = FALSE +) +# layout +mf_layout( + title = "Municipalities of Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ), + arrow = FALSE +) +# north arrow +mf_arrow(pos = "topright") +``` + +## Links Map + +`mf_get_links()` creates a link layer from an `sf` object and a link `data.frame` (long format). + +`mf_map(x, var, type = "grad")` displays graduated links. + + +```{r mf_grad} +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# import the csv file embedded in mapsf +mob <- read.csv(system.file("csv/mob.csv", package = "mapsf")) +# Select links from Fort-de-France (97209)) +mob_97209 <- mob[mob$i == 97209, ] +# create an sf object of links +mob_links <- mf_get_links(x = mtq, df = mob_97209) +# set theme +mf_theme("jsk") +# Plot the municipalities +mf_map(mtq) +# plot graduated links +mf_map( + x = mob_links, + var = "fij", + type = "grad", + breaks = c(100, 500, 1000, 4679.0), + lwd = c(1, 4, 8), + leg_pos = "topright", + leg_title = "Nb. of\nCommuters", + leg_val_rnd = 0, + col = "red4", + leg_frame = TRUE +) +# map layout +mf_layout( + title = "Commuting to Fort-de-France", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ), + arrow = FALSE +) +``` + +```{r, echo = FALSE} +mf_theme("default") +``` diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_basemap-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_basemap-1.png new file mode 100644 index 0000000..73866ac Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_basemap-1.png differ diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_grad-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_grad-1.png new file mode 100644 index 0000000..7e5f5ff Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_grad-1.png differ diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_label-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_label-1.png new file mode 100644 index 0000000..7ffab7c Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_label-1.png differ diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_c-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_c-1.png new file mode 100644 index 0000000..581adbc Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_c-1.png differ diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pc-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pc-1.png new file mode 100644 index 0000000..9d54ff9 Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pc-1.png differ diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pt-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pt-1.png new file mode 100644 index 0000000..46336b5 Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pt-1.png differ diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_t-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_t-1.png new file mode 100644 index 0000000..34f41f1 Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_map_t-1.png differ diff --git a/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_prop-1.png b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_prop-1.png new file mode 100644 index 0000000..e33d7e1 Binary files /dev/null and b/docs/vignettes/mapsf.markdown_strict_files/figure-markdown_strict/mf_prop-1.png differ diff --git a/docs/vignettes/mapsf.md b/docs/vignettes/mapsf.md new file mode 100644 index 0000000..f536cee --- /dev/null +++ b/docs/vignettes/mapsf.md @@ -0,0 +1,525 @@ +# mapsf +Timothée Giraud +2025-01-22 + +# Introduction + +The aim of `mapsf` is to obtain thematic maps with the visual quality of +those build with a classical mapping or GIS software. +`mapsf` uses [`sf`](https://CRAN.R-project.org/package=sf) objects to +produce `base` graphics. +`mapsf` functions can be classified in the following categories: + +- **Symbology** + `mf_map()` is the main function of the package, it displays map + layers on a georeferenced plot. Many parameters are available to + fine tune the cartographic representations. These parameters are the + common ones found in GIS and automatic cartography tools + (e.g. classification and color palettes used in choropleth maps, + symbols sizes used in proportional symbols maps…). + +- **Map Layout** + Along with the cartographic functions, some other functions are + dedicated to layout design (e.g. legends, scale bar, north arrow, + title, credits…). + +- **Utility Functions** + A set of functions is dedicated to the creation of spatial objects + (e.g. links creation) or other utility tasks (e.g. color palette + management, class intervals extraction, sample dataset import…). + +# Main Features + +## Symbology + +`mf_map()` has three main arguments: + +- `x` an sf object +- `var` the name(s) of a variable(s) to map +- `type` the map layer type + +The following map types are available: + +- ![](fig/mf_base.svg) **base**: displays sf objects geometries +- ![](fig/mf_prop.svg) **prop**: displays symbols with areas + proportional to a quantitative variable (stocks) +- ![](fig/mf_choro.svg) **choro**: areas are shaded according to the + variation of a quantitative variable +- ![](fig/mf_typo.svg) **typo**: displays a typology map of a + qualitative variable +- ![](fig/mf_symb.svg) **symb**: displays the different modalities of + a qualitative variable as symbols +- ![](fig/mf_grad.svg) **grad**: displays graduated symbols +- ![](fig/mf_prop_choro.svg) **prop_choro**: displays symbols with + sizes proportional to values of a first variable and colored to + reflect the classification of a second quantitative variable +- ![](fig/mf_prop_typo.svg) **prop_typo**: displays symbols with sizes + proportional to values of a first variable and and colored to + reflect the modalities of a second qualitative variable +- ![](fig/mf_symb_choro.svg) **symb_choro**: displays the different + modalities of a first qualitative variable as symbols colored to + reflect the classification of a second quantitative variable + +Additionaly, `mf_raster()` can be used to displays raster objects +(single/multi band, continuous, classes, intervals). + +## Map Layout + +These functions are dedicated to the map layout design. + +![](fig/maplayout.png) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
mf_title()Title of the map
mf_arrow()North arrow
mf_credits()Author, sources…
mf_scale()Scale bar
mf_annotation()Annotations
mf_label()Labels
mf_shadow()Shadow
+ +## Themes + +`mf_theme()` sets a map theme. A theme is a set of graphical parameters +that are applied to maps created with `mapsf`. These parameters are the +figure margins, background and foreground colors and `mf_title()` +options. `mapsf` offers some builtin themes. It’s possible to modify an +existing theme or to start a theme from scratch. Themes are persistent +across maps produced by mapsf (e.g. they survive a `dev.off()` call). + +🔗 See the online vignette: [How to use +themes](https://riatelab.github.io/mapsf/articles/web_only/how_to_use_themes.html) + +## Export + +`mf_export()` exports maps in PNG or SVG formats. The exported map +width/height ratio will match the one of a spatial object. +If width is specified, then height is deduced from the width/height +ratio of x and some theme parameters (figure margins and title size). +If height is specified, then width is deduced from the width/height +ratio of xand some theme parameters (figure margins and title size). + +🔗 See the online vignette: [How to export +maps](https://riatelab.github.io/mapsf/articles/web_only/how_to_export_maps.html) + +## Datasets + +Several datasets are embedded in the package: + +- A [GeoPackage](https://www.geopackage.org/) of Martinique + municipalities can be imported with `mf_get_mtq()` (or via + `sf::st_read()`). + - Sources: [Base comparateur de + territoires](https://www.insee.fr/fr/statistiques/2521169) + (data, upload date: 2018-09-25) & ADMIN EXPRESS-COG (geometry, + 2018 edition). + - Citation: Insee and IGN, 2018 + - Fields: + - **INSEE_COM**: Municipality identifier + - **STATUS**: Municipality administrative status + - **LIBGEO**: Municipality name + - **POP**: Total population, 2015 + - **MED**: Median disposable income adjusted per equivalent + household member, in euros, 2015 + - **CHOM**: Unemployed population, 2015 + - **ACT**: Active population, 2015 +- A csv file of professional mobility flows between Martinique + municipalities. + - Sources: [Flux de mobilité - déplacements domicile-lieu de + travail](https://www.insee.fr/fr/statistiques/3566477) (upload + date: 2018-08-01) + - Citation: Insee, 2018 + - Fields: + - **i**: Municipality of residence identifier + - **j**: Municipality of workplace identifier + - **fij**: Flows of workers (employed population, 15 y.o. or + more, 2015, only flows \> 100) + - **sj**: Administrative status of the workplace municipality + +# Examples of thematic maps + +## Base map + +`mf_theme()` allows to apply a theme to the map. + +`mf_shadow()` plots the shadow of a polygon layer. + +`mf_map(x, type = "base")` displays `sf` objects geometries. + +`mf_layout()` add a complete layout to the map (title, credits, north +arrow, scale bar). Each layout elements can also be set separately (with +`mf_title()`, `mf_credits()`, `mf_arrow()` and `mf_scale()`). + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set a theme +mf_theme("iceberg") +# plot a shadow +mf_shadow(mtq) +# plot municipalities +mf_map(mtq, type = "base", add = TRUE) +# layout +mf_layout( + title = "Martinique", + credits = paste0( + "Sources: IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_basemap-1.png) + +## Proportional Symbols + +`mf_map(x, var, type = "prop")` displays symbols with areas proportional +to a quantitative variable (stocks). The `inches` argument is used to +customize the symbols sizes. + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set a theme +mf_theme("darkula") +# plot a shadow +mf_shadow(mtq) +# plot municipalities +mf_map(mtq, add = TRUE) +# plot population +mf_map( + x = mtq, + var = "POP", + type = "prop", + inches = 0.25, + col = "brown4", + leg_pos = "topright", + leg_adj = c(0, -3), + leg_title = "Total population" +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_prop-1.png) + +## Choropleth Map + +In choropleth maps, areas are shaded according to the variation of a +quantitative variable. They are used to represent ratios or indices. +`mf_map(x, var, type = "choro")` displays choropleth maps . Arguments +`nbreaks`, and `breaks` allow to customize the variable classification. +`mf_get_breaks()` allows to classify data outside of the function +itself. Colors palettes, defined with `pal`, can be created with +`mf_get_pal()` or you can use palette names from `hcl.pals()`. + +Use `mf_theme()` to set a theme without plotting anything. + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# population density (inhab./km2) using sf::st_area() +mtq$POPDENS <- 1e6 * mtq$POP / sf::st_area(mtq) +# set a theme +mf_theme("green") +# plot population density +mf_map( + x = mtq, + var = "POPDENS", + type = "choro", + breaks = "geom", + nbreaks = 5, + pal = "Greens", + border = "white", + lwd = 0.5, + leg_pos = "bottomleft", + leg_adj = c(0, 3), + leg_title = "Population Density\n(inh. / km2)" +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_map_c-1.png) + +## Typology Map + +`mf_map(x, var, type = "typo")` displays a typology map of a qualitative +variable. `val_order` is used to set the modalities order in the legend. + +`mf_label()` displays labels on the map. + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +mf_theme("dark") +# plot administrative status +mf_map( + x = mtq, + var = "STATUS", + type = "typo", + pal = c("aquamarine4", "yellow3", "wheat"), + lwd = .5, + val_order = c( + "Prefecture", + "Sub-prefecture", + "Simple municipality" + ), + leg_pos = "topright", + leg_adj = c(0, 1), + leg_title = "" +) +# labels for a few municipalities +mf_label( + x = mtq[mtq$STATUS != "Simple municipality", ], var = "LIBGEO", + cex = 0.9, halo = TRUE, r = 0.15 +) +# layout +mf_layout( + title = "Administrative Status", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_map_t-1.png) + +## Proportional Symbols using Choropleth Coloration + +`mf_map(x, var, type = "prop_choro")` creates a map of symbols that are +proportional to values of a first variable and colored to reflect the +classification of a second variable. + +`expandBB` argument in `mf_map()` allows to expand the map space. Here, +we increase the space available on the right of the map to avoid +overlaps between the legends and the map. + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +mf_theme("candy") +# Plot the municipalities and expand the map space on the right +mf_map(x = mtq, expandBB = c(0, 0, 0, .15)) +# Plot symbols with choropleth coloration +mf_map( + x = mtq, + var = c("POP", "MED"), + type = "prop_choro", + border = "grey50", + lwd = 1, + leg_pos = c("topright"), + leg_title = c("Population", "Median Income\n(in euros)"), + breaks = "equal", + nbreaks = 4, + pal = "Greens", + leg_val_rnd = c(0, -2), + leg_frame = TRUE +) +# layout +mf_layout( + title = "Population & Wealth in Martinique, 2015", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ), + frame = TRUE +) +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pc-1.png) + +## Proportional Symbols using Typology Coloration + +`mf_map(x, var, type = "prop_typo")` creates a map of symbols that are +proportional to values of a first variable and colored to reflect the +modalities of a second qualitative variable. + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +mf_theme("ink") +# plot the municipalities and expand the map space on the right +mf_map(x = mtq, expandBB = c(0, 0, 0, .15)) +# plot symbols with choropleth coloration +mf_map( + x = mtq, + var = c("POP", "STATUS"), + type = "prop_typo", + symbol = "square", + border = "white", + lwd = .5, + leg_pos = "topright", + leg_title = c("Population", "Administrative\nStatus"), + val_order = c( + "Prefecture", "Sub-prefecture", + "Simple municipality" + ) +) +# layout +mf_layout( + title = "Population Distribution in Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ) +) +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_map_pt-1.png) + +## Label Map + +`mf_label()` is dedicated to the display of labels on a map. The +`overlap = FALSE` argument displays non overlapping labels. + +In this example we have built a custom theme with `mf_theme()`. + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# set theme +my_theme <- list( + name = "mytheme", + bg = "lightblue1", + fg = "darkseagreen4", + mar = c(0, 0, 0, 0), + tab = TRUE, + pos = "left", + inner = TRUE, + line = 1, + cex = .9, + font = 3 +) +mf_theme(my_theme) +# plot municipalities +mf_map(mtq, col = "#e4e9de", border = "darkseagreen4") +# plot labels +mf_label( + x = mtq, + var = "LIBGEO", + col = "black", + cex = 0.7, + font = 4, + halo = TRUE, + bg = "white", + r = 0.1, + overlap = FALSE, + lines = FALSE +) +# layout +mf_layout( + title = "Municipalities of Martinique", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ), + arrow = FALSE +) +# north arrow +mf_arrow(pos = "topright") +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_label-1.png) + +## Links Map + +`mf_get_links()` creates a link layer from an `sf` object and a link +`data.frame` (long format). + +`mf_map(x, var, type = "grad")` displays graduated links. + +``` r +library(mapsf) +# import the sample data set +mtq <- mf_get_mtq() +# import the csv file embedded in mapsf +mob <- read.csv(system.file("csv/mob.csv", package = "mapsf")) +# Select links from Fort-de-France (97209)) +mob_97209 <- mob[mob$i == 97209, ] +# create an sf object of links +mob_links <- mf_get_links(x = mtq, df = mob_97209) +# set theme +mf_theme("jsk") +# Plot the municipalities +mf_map(mtq) +# plot graduated links +mf_map( + x = mob_links, + var = "fij", + type = "grad", + breaks = c(100, 500, 1000, 4679.0), + lwd = c(1, 4, 8), + leg_pos = "topright", + leg_title = "Nb. of\nCommuters", + leg_val_rnd = 0, + col = "red4", + leg_frame = TRUE +) +# map layout +mf_layout( + title = "Commuting to Fort-de-France", + credits = paste0( + "Sources: Insee and IGN, 2018\n", + "mapsf ", + packageVersion("mapsf") + ), + arrow = FALSE +) +``` + +![](mapsf.markdown_strict_files/figure-markdown_strict/mf_grad-1.png)