diff --git a/.Rbuildignore b/.Rbuildignore index 91114bf..6d4bf17 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,2 +1,7 @@ ^.*\.Rproj$ ^\.Rproj\.user$ +^LICENSE\.md$ +^pkgdown$ +^docs$ +^man-roxygen$ +^index\.html$ diff --git a/DESCRIPTION b/DESCRIPTION index 45faa74..653bf47 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,20 +1,32 @@ Package: statR Title: statR -Version: 0.0.0.9000 +Version: 2.0.0 Authors@R: as.person(c( "Andrea Schnell [aut]", - "Thomas Lo Russo [aut,cre]")) -Description: statR bundles a variety of functions that allow to generate ready-to-publish plots (ggplot2-theme & colorpalettes) as well as saving data in formated excel-tables. The generated outputs are aligned with the corporate design of the Canton Zurich. + "Thomas Lo Russo [aut,cre]", + "Michelle Donzallaz [ctb]")) +Description: statR beinhaltet eine Reihe von Funktionen mit denen unter anderem publikationsfertige Visualisierungen (mittels ggplot2-themes und Farbpaletten) und formatierte Excel-Tabellen erstellt werden können. Die generierten Visualisierungen und Tabellen sind an das Corporate Design des Kantons Zürich angepasst. Depends: R (>= 3.3.0) -License: What license is it under? +License: GPL-3 Encoding: UTF-8 LazyData: true -RoxygenNote: 6.0.1 +RoxygenNote: 7.1.1 Imports: dplyr, + ggrepel, ggplot2, - openxlsx, - magrittr + openxlsx, + magrittr, + stats, + grDevices, + RColorBrewer, + gridExtra, + rlang, + scales, + stringr, + tidyr, + dichromat, + purrr URL: https://statistikzh.github.io/statR/ BugReports: https://github.com/statistikZH/statR/issues Suggests: diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..7649f3d --- /dev/null +++ b/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) 2021 Statistisches Amt des Kantons Zürich + + 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: + + statR Copyright (C) 2021 Statistisches Amt des Kantons Zürich + 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/NAMESPACE b/NAMESPACE index 07543a0..275e469 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,11 +1,29 @@ # Generated by roxygen2: do not edit by hand +export(datasetsXLSX) export(display) export(display.statcol.all) export(insert_worksheet) export(interpolate2) export(quickXLSX) +export(quick_sum) export(splitXLSX) -export(stattheme_data) export(theme_stat) export(zhpal) +importFrom(dplyr,"%>%") +importFrom(dplyr,group_by) +importFrom(dplyr,n) +importFrom(dplyr,summarize) +importFrom(dplyr,ungroup) +importFrom(ggplot2,continuous_scale) +importFrom(ggplot2,element_blank) +importFrom(ggplot2,element_line) +importFrom(ggplot2,ggplotGrob) +importFrom(ggplot2,theme) +importFrom(ggplot2,theme_minimal) +importFrom(ggplot2,unit) +importFrom(grDevices,"colorRampPalette") +importFrom(graphics,"rect") +importFrom(stats,median) +importFrom(stats,quantile) +importFrom(stats,sd) diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..5bcf47f --- /dev/null +++ b/NEWS.md @@ -0,0 +1,8 @@ +# statR 2.0.0 + +* An R Markdown template `ZH report` for .html-reports is now available. +* New function `datasetsXLSX()`: several datasets and/or figures can now be exported from R to a single .xlsx-file. The function creates an overview sheet and separate sheets for each dataset/figure. +* Additional function arguments for `quickXLSX()`, `splitXLSX()`, and `datasetsXLSX()` have been implemented, for example the author's initials and individual contact details can be specified and the logo of the canton of Zurich can be added. +* The column widths in the output of `quickXLSX()`, `splitXLSX()`, and `datasetsXLSX()` are set automatically and the first row no longer freezes. +* The documentation has been extended. +* `theme_stat()` has been revised and a couple of theme arguments have been added for increased flexibility (e.g., axis ticks, position of axis labels) diff --git a/R/col_stat.R b/R/col_stat.R index 92009e3..c48cc89 100644 --- a/R/col_stat.R +++ b/R/col_stat.R @@ -7,7 +7,7 @@ library(scales) #' Data used by the stat zh palettes #' #' @format A \code{list}. -#' @export +#' @noRd #' stattheme_data <- { @@ -197,193 +197,19 @@ stattheme_data <- { #' #' Stat ZH scales #' @keywords stattheme_pal -#' @examples -#' stattheme_pal() +#' @noRd #' #Funktion für Palettenauswahl (ord./kat.) stattheme_pal <- function(palette = "default") { if (palette %in% names(x$stattheme_data)) { - manual_pal(unname( x$stattheme_data[[palette]])) + scales::manual_pal(unname( x$stattheme_data[[palette]])) } else { stop(sprintf("palette %s not a valid statZH palette.", palette)) } } -# scale_fill_stat() - -#' scale_fill_stat() -#' -#' Stat ZH scales -#' @param -#' @keywords scale_fill_stat -#' @examples -#' scale_fill_stat() -#' -# Funktion für Palettenauswahl (ord./kat.) - -scale_fill_stat <- function(palette = "zh",...) { - - discrete_scale("fill", "stat", stattheme_pal(palette), ...) - -} - -# scale_colour_stat() - -#' scale_colour_stat() -#' -#' Stat ZH scales -#' @keywords scale_colour_stat -#' @examples -#' scale_colour_stat() -#' -# Funktion für Palettenauswahl (ord./kat.) - -scale_color_stat <- scale_colour_stat <- function(palette = "zh",...) { - - discrete_scale("colour", "stat", stattheme_pal(palette), ...) - -} - -#' scale_seq_gradient() -#' -#' Stat ZH scales -#' @param -#' @keywords scale_seq_gradient -#' @examples -#' scale_seq_gradient() -#' -# Funktion für sequentielle Paletten - -stat_seq_gradient_pal <- function(palette = "zhblue", space = "Lab") { - if (palette %in% names(x$stattheme_data[["sequential"]])) { - manual_pal(unname(x$stattheme_data[["sequential"]][[palette]])) - } else { - stop(sprintf("palette %s not a valid statZH palette.", palette)) - } - pal <- x$stattheme_data[["sequential"]][[palette]] - seq_gradient_pal(low = pal["low"], high = pal["high"] - ) -} - -#' scale_color_gradient_stat() -#' -#' Stat ZH scales -#' @param -#' @keywords scale_color_gradient_stat -#' @examples -#' scale_color_gradient_stat() -#' -# Funktion für sequentielle Paletten - -scale_color_gradient_stat<- scale_colour_gradient_stat <- function(palette = "zhblueseq", - ..., - space = "Lab", - na.value = "grey50", - guide = "colourbar") { - continuous_scale("colour", "stat", - stat_seq_gradient_pal(palette, space), - na.value = na.value, - guide = guide, - ...) -} - -#' scale_fill_gradient_stat() -#' -#' Stat ZH scales -#' @param -#' @keywords scale_fill_gradient_stat -#' @examples -#' scale_fill_gradient_stat() -#' -# Funktion für sequentielle Paletten - -scale_fill_gradient_stat<- function(palette = "zhblueseq", - ..., space = "Lab", - na.value = "grey50", - guide = "colourbar") { - continuous_scale("fill", "stat", - stat_seq_gradient_pal(palette, space), - na.value = na.value, - guide = guide, - ...) -} - -#' mid_rescaler() -#' -#' Stat ZH scales -#' @param -#' @keywords mid_rescaler -#' @examples -#' mid_rescaler() -#' -# Function to define midpoint (diverging scales) - -mid_rescaler <- function(mid) { - function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) { - rescale_mid(x, to, from, mid) - } -} - -#' stat_div_gradient_pal() -#' -#' Stat ZH scales -#' @param -#' @keywords stat_div_gradient_pal -#' @examples -#' stat_div_gradient_pal() -#' -# Function to define midpoint (diverging scales) - -stat_div_gradient_pal <- function(palette = "zhbluered", space = "Lab") { - if (palette %in% names(x$stattheme_data[["diverging"]])) { - manual_pal(unname(x$stattheme_data[["diverging"]][[palette]])) - } else { - stop(sprintf("palette %s not a valid statZH palette.", palette)) - } - - pal <- x$stattheme_data[["diverging"]][[palette]] - div_gradient_pal(low = pal["low"], mid = pal["mid"], high = pal["high"], - space = space) -} - -#' scale_color_gradient2_stat() -#' -#' Stat ZH scales -#' @param -#' @keywords scale_color_gradient2_stat -#' @examples -#' scale_color_gradient2_stat() -#' -# Function for diverging scales - -scale_color_gradient2_stat <- scale_colour_gradient2_stat <- function(palette = "zhbluered", - ..., space = "Lab", - na.value = "grey50", - guide = "colourbar", - midpoint=0) { - continuous_scale("colour", "stat2", - stat_div_gradient_pal(palette, space), - na.value = na.value, - guide = guide, - rescaler = mid_rescaler(mid = midpoint), - ...) -} - - -scale_fill_gradient2_stat <- function(palette = "zhbluered", - ..., space = "Lab", - na.value = "grey50", - guide = "colourbar", midpoint=0) { - continuous_scale("fill", "stat2", - stat_div_gradient_pal(palette, space), - na.value = na.value, - guide = guide, - rescaler = mid_rescaler(mid = midpoint), - ...) -} - #' Data used by the stat zh palettes #' @@ -392,36 +218,3 @@ scale_fill_gradient2_stat <- function(palette = "zhbluered", #' zhpal <- x$stattheme_data - - -#' scale_color_gradientn_stat() -#' -#' Stat ZH scales -#' @param -#' @keywords scale_color_gradientn_stat -#' @examples -#' scale_color_gradientn_stat() -#' -# Function for customized scales with multiple hues - - -scale_color_gradientn_stat <- scale_colour_gradientn_stat <- function(..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", colors) { - - if(missing(colours)) colours <- c("#FFE16F","#56BFB9","#003B5E") - - colours <- if (missing(colours)) colors else colours - - continuous_scale("colour", "gradientn", - gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...) -} - - -scale_fill_gradientn_stat <- function(..., colours, values = NULL, space = "Lab", na.value = "grey50", guide = "colourbar", colors) { - - if(missing(colours)) colours <- c("#FFE16F","#56BFB9","#003B5E") - - colours <- if (missing(colours)) colors else colours - - continuous_scale("fill", "gradientn", - gradient_n_pal(colours, values, space), na.value = na.value, guide = guide, ...) -} diff --git a/R/datasetsXLSX.R b/R/datasetsXLSX.R new file mode 100644 index 0000000..cd611c9 --- /dev/null +++ b/R/datasetsXLSX.R @@ -0,0 +1,429 @@ +#' datasetsXLSX() +#' +#' Function to export several datasets and/or figures from R to an .xlsx-file. The function creates an overview sheet and separate sheets +#' for each dataset/figure. +#' +#' When including figures, the heights and widths need to be specified as a vector. For example, say you have two datasets and one figure +#' that you would like to export. widths = c(0,0,5) then suggests that the figure will be 5 inches wide and placed in the third (and last) sheet of the file. +#' The same logic applies to the specification of `startrows` and `startcols`. +#' To include a ggplot2-plot, put a print statement around the ggplot2-object: list(..., ..., print(plot)). +#' +#' @param file file name of the spreadsheet. The extension ".xlsx" is added automatically. +#' @param maintitle Title to be put on the first (overview) sheet. +#' @param datasets datasets or plots to be included. +#' @param widths width of figure in inch (1 inch = 2.54 cm). See details. +#' @param heights height of figure in inch (1 inch = 2.54 cm). See details. +#' @param startrows row where upper left corner of figure should be placed. See details. +#' @param startcols column where upper left corner of figure should be placed. See details. +#' @param sheetnames names of the sheet tabs. +#' @param titles titles of the different sheets. +#' @param logo file path to the logo to be included in the index-sheet. Can be "statzh" or "zh". Defaults to "statzh". +#' @param titlesource source to be mentioned on the title sheet beneath the title +#' @param sources source of the data. Defaults to "statzh". +#' @param metadata1 metadata information to be included. Defaults to NA. +#' @param auftrag_id order number. +#' @param contact contact information on the title sheet. Defaults to "statzh" +#' @param homepage web address to be put on the title sheet. Default to "statzh" +#' @param openinghours openinghours written on the title sheet. Defaults to Data Shop +#' @keywords datasetsXLSX +#' @export +#' @examples +#'\donttest{ +#' \dontrun{ +#' +#' +#'# Example with two datasets and no figure +#'dat1 <- mtcars +#'dat2 <- PlantGrowth +#' +#'datasetsXLSX(file="twoDatasets", # '.xlsx' wird automatisch hinzugefügt +#' maintitle = "Autos und Pflanzen", +#' datasets = list(dat1, dat2), +#' logo = "statzh", +#' sheetnames = c("Autos","Blumen"), +#' titles = c("mtcars-Datensatz","PlantGrowth-Datensatz"), +#' sources = c("Source: Henderson and Velleman (1981). +#' Building multiple regression models interactively. Biometrics, 37, 391–411.", +#' "Dobson, A. J. (1983) An Introduction to Statistical +#' Modelling. London: Chapman and Hall."), +#' metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", +#' "Bemerkungen zum PlantGrowth-Datensatz: x"), +#' auftrag_id="A2021_0000") +#' +#'# Example with two datasets and one figure +#' +#'dat1 <- mtcars +#'dat2 <- PlantGrowth +#'fig <- hist(mtcars$disp) +#' +#'datasetsXLSX(file="twoDatasetsandFigure", +#' maintitle = "Autos und Pflanzen", # '.xlsx' wird automatisch hinzugefügt +#' datasets = list(dat1, dat2, fig), +#' widths = c(0,0,5), +#' heights = c(0,0,5), +#' startrows = c(0,0,3), +#' startcols = c(0,0,3), +#' sheetnames = c("Autos","Blumen", "Histogramm"), +#' titles = c("mtcars-Datensatz","PlantGrowth-Datensatz", "Histogramm"), +#' sources = c("Source: Henderson and Velleman (1981). +#' Building multiple regression models interactively. Biometrics, 37, 391–411.", +#' "Source: Dobson, A. J. (1983) An Introduction to +#' Statistical Modelling. London: Chapman and Hall."), +#' metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", +#' "Bemerkungen zum PlantGrowth-Datensatz: x"), +#' auftrag_id="A2021_0000") +#'} +#'} + + +# function datasetsXLSX + +datasetsXLSX <- function(file, + maintitle, + datasets, + widths = NULL, + heights = NULL, + startrows = NULL, + startcols = NULL, + sheetnames, + titles, + logo="statzh", + titlesource = "statzh", + sources= "statzh", + metadata1=NA, + auftrag_id = NULL, + contact = "statzh", + homepage = "statzh", + openinghours = "statzh" +){ + + wb <- openxlsx::createWorkbook("data") + + i<-0 + + for (dataset in datasets){ + + i <- i+1 + + sheetnames_def <- if(length(sheetnames)>1) { + sheetnames[i] + } else {i + } + + title_def <- if(length(titles)>1) { + titles[i] + } else {titles + } + + source_def <- if(length(sources)>1) { + sources[i] + } else {sources + } + + metadata_def <- if(length(metadata1)>1) { + metadata1[i] + } else {metadata1 + } + + + # #dynamisch mit sheetvar! + # statR::insert_worksheet2(data=dataset, + # workbook=wb, + # sheetname = sheetnames_def, + # title = title_def, + # source = source_def, + # metadata = metadata_def + # ) + + #dynamisch mit sheetvar! + if(is.data.frame(dataset)){ + insert_worksheet_nh(data=dataset + ,workbook=wb + ,sheetname = sheetnames_def + ,title = title_def + ,source = source_def + ,metadata = metadata_def + ) + }else{ # image + insert_worksheet_image(dataset, + wb, + sheetnames_def, + width = widths[i], + height = heights[i], + startrow = startrows[i], + startcol = startcols[i]) + } + + } + + + # Create index sheet + openxlsx::addWorksheet(wb,"Inhalt") + + # hide gridlines + openxlsx::showGridLines(wb + ,sheet = "Inhalt" + ,showGridLines = F + ) + + # set col widths + openxlsx::setColWidths(wb + ,"Inhalt" + ,cols = 1 + ,widths = 1 + ) + + # insert logo + + if(!is.null(logo)){ + + if(logo=="statzh") { + + logo <- paste0(.libPaths(),"/statR/extdata/Stempel_STAT-01.png") + + # + logo <- logo[file.exists(paste0(.libPaths(),"/statR/extdata/Stempel_STAT-01.png"))] + + openxlsx::insertImage(wb, + "Inhalt", + file=logo, + startRow = 2, + startCol = 2, + width = 2.5, + height = 0.9, + units = "in") + + } else if(logo == "zh"){ + + logo <- paste0(.libPaths(),"/statR/extdata/Stempel_Kanton_ZH.png") + + # + logo <- logo[file.exists(paste0(.libPaths(),"/statR/extdata/Stempel_Kanton_ZH.png"))] + + openxlsx::insertImage(wb, + "Inhalt", + file=logo, + startRow = 2, + startCol = 2, + width = 2.5, + height = 0.9, + units = "in") + + + } else if(file.exists(logo)) { + + openxlsx::insertImage(wb, i, logo, width = 2.145, height = 0.7865, + units = "in") + } + if(!file.exists(logo)) { + + message("no logo found and / or added") + } + + } + + # contact + + if(!is.null(contact)){ + if(any(grepl(contact, pattern = "statzh"))) { + contact <- c("Datashop" + ,"Tel.: +41 43 259 75 00", + "datashop@statistik.zh.ch") + openxlsx::writeData(wb + ,sheet = "Inhalt" + ,contact + ,xy = c("O", 2) + ) + } else { + openxlsx::writeData(wb + ,sheet = "Inhalt" + ,contact + ,xy = c("O", 2)) + } + + } + + + if(!is.null(homepage)){ + + if(any(grepl(homepage, pattern = "statzh"))) { + + homepage <- "http://www.statistik.zh.ch" + class(homepage) <- 'hyperlink' + openxlsx::writeData(wb + ,"Inhalt" + ,x = homepage + ,xy = c("O", 5)) + } else { + class(homepage) <- 'hyperlink' + openxlsx::writeData(wb + ,"Inhalt" + ,x = homepage + ,xy = c("O", 5)) + } + + } + + + + if(!is.null(openinghours)){ + + if(any(grepl(openinghours, pattern = "statzh"))) { + + openinghours <- c("Bürozeiten" + ,"Montag bis Freitag" + ,"09:00 bis 12:00" + ,"13:00 bis 16:00") + + openxlsx::writeData(wb + ,sheet = "Inhalt" + ,openinghours + ,xy = c("R", 2) + + ) + + } else { + + openxlsx::writeData(wb + ,sheet = "Inhalt" + ,openinghours + ,xy = c("R", 2)) + + } + + } + + + # headerline + headerline <- openxlsx::createStyle(border="Bottom", borderColour = "#009ee0",borderStyle = getOption("openxlsx.borderStyle", "thick")) + openxlsx::addStyle(wb + ,"Inhalt" + ,headerline + ,rows = 6 + ,cols = 1:20 + ,gridExpand = TRUE + ,stack = TRUE + ) + + #Erstellungsdatum + openxlsx::writeData(wb + ,"Inhalt" + ,paste("Erstellt am " + ,format(Sys.Date(), format="%d.%m.%Y")) + ,xy = c("O", 8) + ) + + + if (!is.null(auftrag_id)){ + # Auftragsnummer + openxlsx::writeData(wb + ,sheet = "Inhalt" + ,paste("Auftragsnr.:", auftrag_id) + ,xy = c("O", 9) + ) + } + + # title + titleStyle <- openxlsx::createStyle(fontSize=20, textDecoration="bold",fontName="Arial", halign = "left") + openxlsx::addStyle(wb + ,"Inhalt" + ,titleStyle + ,rows = 10 + ,cols = 3 + ,gridExpand = TRUE + ) + + openxlsx::writeData(wb + ,"Inhalt" + ,x = maintitle + ,headerStyle=titleStyle + ,xy = c("C", 10) + ) + + + if(any(grepl(titlesource, pattern = "statzh"))){ + + # source + openxlsx::writeData(wb + ,"Inhalt" + ,"Quelle: Statistisches Amt des Kantons Zürich" + ,xy = c("C", 11) + ) + + }else { + + openxlsx::writeData(wb + ,"Inhalt" + , titlesource + ,xy = c("C", 11)) + + } + + + + + # subtitle + subtitleStyle <- openxlsx::createStyle(fontSize=11, textDecoration="bold",fontName="Arial", halign = "left") + openxlsx::addStyle(wb + ,sheet = "Inhalt" + ,subtitleStyle + ,rows = 14 + ,cols = 3 + ,gridExpand = TRUE + ) + + openxlsx::writeData(wb + ,sheet = "Inhalt" + ,x = "Inhalt" + ,headerStyle=subtitleStyle + ,xy = c("C", 13) + ) + + ## writing internal hyperlinks + openxlsx::writeFormula(wb + ,sheet = "Inhalt" + ,x = openxlsx::makeHyperlinkString(sheet = sheetnames + #,row = 1 + #,col = 1 + ,text = titles # soll arguments titles entsprechen + ) + ,xy = c("C", 15) + ) + + + openxlsx::worksheetOrder(wb) <- c(length(names(wb)),1:(length(names(wb))-1)) + + + if(missing(metadata1)) { + metadata1 <- "" + } + + + openxlsx::saveWorkbook(wb, paste(file, ".xlsx", sep = "")) + +} + + + +# # # example +# pacman::p_load(tidyverse,tmap) +# data("World") +# # create map +# map <- tm_shape(World) + +# tm_polygons("HPI") +# +# datasetsXLSX(file="datasetsXLSX" +# ,maintitle = "nice datasets" +# ,datasets = list(head(mtcars),tail(mtcars),map) +# ,sheetnames = c("data1","data2","map") +# ,widths = c(0,0,10) +# ,heights = c(0,0,8.5) +# ,startrows = c(0,0,10) +# ,startcols = c(0,0,8) +# ,titles = c("Title","Title", "Map") +# ,sources = c("Quelle: STATENT", "Quelle: Strukturerhebung", "Quelle: Strukturerhebung") +# ,metadata1 = c("Bemerkungen: bla", "Bemerkungen: blabla", "Bemerkungen: blablabla") +# ,auftrag_id="A2020_0200" +# ) + + diff --git a/R/display.R b/R/display.R index 1e1c364..3b8be77 100644 --- a/R/display.R +++ b/R/display.R @@ -4,7 +4,11 @@ #' #' preview colors in console #' @param col a vector of hex-code colors to be displayed +#' @param border border color +#' @param ... further arguments that can be passed to the plot()-function #' @keywords display +#' @importFrom grDevices "colorRampPalette" +#' @importFrom graphics "rect" #' @export #' @examples #' #display can be used to preview all the palettes included in the 'zhpal'-list: diff --git a/R/display.statcol.all.R b/R/display.statcol.all.R index dceab75..153d169 100644 --- a/R/display.statcol.all.R +++ b/R/display.statcol.all.R @@ -7,23 +7,32 @@ #' @export #' @examples #' display.statcol.all() -#' +#' # Function display.statcol.all<-function() { - + df <- data.frame(unlist(x$stattheme_data)) - - df$pal <- row.names(df) - - colnames(df) <- c("col","palette") - - df$palette<-gsub('(.mid|.low|.high|.high|\\d$)','', df$palette) + + df$pal_col <- row.names(df) + + colnames(df) <- c("col","pal_col") + + df$palette<-gsub('(.mid|.low|.high|.high|\\d$)','', df$pal_col) + df$palette<-gsub('\\d$','', df$palette) - - gg1<-ggplot(df, aes(x=seq_along(col), y=0, color=col))+geom_point(size=20,shape=15)+facet_wrap(~palette, ncol=3,scales="free")+guides(color=FALSE)+scale_color_manual(values = levels(df$col))+theme_minimal()+theme(axis.ticks=element_blank(),axis.text=element_blank(),axis.title=element_blank(), panel.grid =element_blank()) - - gg1 - + + gg1 <- ggplot2::ggplot(df, ggplot2::aes(x=pal_col, y=0, color=I(col)))+ + ggplot2::geom_point(size=20,shape=15)+ + ggplot2::facet_wrap(~palette, ncol=3,scales="free")+ + ggplot2::guides(color=FALSE)+ + ggplot2::theme_minimal()+ + ggplot2::theme(axis.ticks=ggplot2::element_blank(), + axis.text=ggplot2::element_blank()) + + ggplot2::xlab("") + + ggplot2::ylab("") + + print(gg1) + } diff --git a/R/flush_left.r b/R/flush_left.r new file mode 100644 index 0000000..b292985 --- /dev/null +++ b/R/flush_left.r @@ -0,0 +1,27 @@ +# flush_left: schiebt title, subtitle und caption an den linken Grafikrand + +#' flush_left +#' +#' Function to flush title, subtitle and caption to the lefthand side of the graphics device +#' @param g ggplot object +#' @keywords flush left +#' @importFrom ggplot2 ggplotGrob +#' @examples +#'\dontrun{ +#' flush_left(ggplot(mtcars, aes( x = cyl))+ +#' geom_bar()+ +#' labs(title = "Titel", subtitle = "Untertitel", caption = "Datenquelle")) +#' } + + +flush_left <- function(g){ + + xout <- ggplot2::ggplotGrob(g) + + xout$layout$l[xout$layout$name == "title"] <- 1 + xout$layout$l[xout$layout$name == "subtitle"] <- 1 + xout$layout$l[xout$layout$name == "caption"] <- 1 + + gridExtra::grid.arrange(xout) +} + diff --git a/R/insert_image.R b/R/insert_image.R new file mode 100644 index 0000000..82f24e0 --- /dev/null +++ b/R/insert_image.R @@ -0,0 +1,67 @@ +# insert an image into a single worksheet +#' insert_image +#' +#' @param image image or plot +#' @param workbook workbook object to write new worksheet in +#' @param sheetname name of the sheet tab +#' @param startrow row coordinate of upper left corner of figure +#' @param startcol column coordinate of upper left corner of figure +#' @param width width of figure +#' @param height height of figure +#' @noRd +#' @examples +#' # example +#' \dontrun{ +#' export <- openxlsx::createWorkbook("export") +#' +#' insert_worksheet_image(image=plot(x = mtcars$wt, y = mtcars$mpg), +#' export, +#' "image", +#' startrow=2, +#' startcol=2, +#' width=3.5, +#' height=5.5 +#' ) +#'openxlsx::saveWorkbook(export,"insert_worksheet_image.xlsx") +#' +#'} + +insert_worksheet_image = function(image, + workbook, + sheetname, + startrow, + startcol, + width, + height){ + + openxlsx::addWorksheet(workbook, + sheetname, + gridLines = FALSE + ) + + # print(image) + + openxlsx::insertPlot(workbook, + sheetname, + width = width, + height = height, + startRow = startrow, + startCol = startcol, + fileType = "png", + units = "in" + ) +} + +# # example +# export <- openxlsx::createWorkbook("export") +# +# insert_worksheet_image(image=plot(x = mtcars$wt, y = mtcars$mpg) +# ,export +# ,"image" +# ,startrow=2 +# ,startcol=2 +# ,width=3.5 +# ,height=5.5 +# ) +# +# openxlsx::saveWorkbook(export,"insert_worksheet_image.xlsx") diff --git a/R/insert_worksheet.R b/R/insert_worksheet.R index 80125b1..54bd04c 100644 --- a/R/insert_worksheet.R +++ b/R/insert_worksheet.R @@ -1,41 +1,37 @@ -# insert_worksheet: add formatted worksheets to an existing Workbook - -#' insert_worksheet +#' insert_worksheet() #' -#' Function to create formatted spreadsheets automatically -#' @param data data to be included in the XLSX-table. -#' @param workbook workbook object to write new worksheet in. -#' @param title title of the table and the sheet -#' @param sheetname name of the sheet-tab. +#' Function to add formatted worksheets to an existing .xlsx-workbook. +#' @param data data to be included. +#' @param workbook workbook object to add new worksheet to. +#' @param title title to be put above the data. +#' @param sheetname name of the sheet tab. #' @param source source of the data. Defaults to "statzh". -#' @param metadata metadata-information to be included. Defaults to NA. +#' @param metadata metadata information to be included. Defaults to NA. #' @param logo path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh" -#' @param contactdetails contactdetails of the data publisher. Defaults to "statzh". +#' @param contactdetails contact details of the data publisher. Defaults to "statzh". #' @param grouplines defaults to FALSE. Can be used to separate grouped variables visually. +#' @param author defaults to the last two letters (initials) or numbers of the internal user name. +#' @importFrom dplyr "%>%" #' @keywords insert_worksheet #' @export #' @examples -#' # Generation of a spreadsheet with four worksheets (one per 'carb'-category). -#' # Can be used to generate worksheets for multiple years. #' -#' # create workbook +#' # Generation of a spreadsheet #' wb <- openxlsx::createWorkbook("hello") #' -#' insert_worksheet(mtcars[c(1:10),],wb,"mtcars",c(1:4),carb,grouplines=c(1,5,6)) - -# Function - -#TO DO - insert name of the worksheet dynamicaly, insert warning if WB is not a workbook-object +#' insert_worksheet(data = mtcars[c(1:10),], workbook = wb, title = "mtcars", sheetname = "carb") -#remove points? -insert_worksheet <- function(data, workbook, sheetname="data",title="Title", source="statzh", metadata = NA, logo=NULL, grouplines = FALSE, contactdetails="statzh") { +insert_worksheet <- function(data, workbook, sheetname="data",title="Title", + source="statzh", metadata = NA, logo= "statzh", + grouplines = FALSE, contactdetails="statzh", + author = "user") { # Metadata - remarks <- if (is.na(metadata)) { + remarks <- if (any(is.na(metadata))) { "Bemerkungen:" } - else if (metadata == "HAE") { + else if (any(metadata == "HAE")) { "Die Zahlen der letzten drei Jahre sind provisorisch." } else { @@ -44,7 +40,7 @@ insert_worksheet <- function(data, workbook, sheetname="data",title="Title", sou #Zahlenformat: Tausendertrennzeichen - options("openxlsx.numFmt" = "#,###0") + # options("openxlsx.numFmt" = "#,###0") #extrahiere colname # col_name <- rlang::enquo(sheetvar) @@ -52,13 +48,22 @@ insert_worksheet <- function(data, workbook, sheetname="data",title="Title", sou wb<-workbook # data-container from row 5 - datenbereich = 14 + n_metadata <- length(metadata) - #define width of the area in which data is contained for formating + datenbereich = 9 + n_metadata + 3 + + #define width of the area in which data is contained for formatting spalten = ncol(data) + # increase width of colnames for better auto-fitting of column width + colnames(data) <- paste0(colnames(data), " ", sep = "") + #position of contact details - contact = if(spalten>4){spalten-2}else{3} + contact = if(spalten>=6){ + spalten-2 + } else { + 4 + } #styles titleStyle <- openxlsx::createStyle(fontSize=14, textDecoration="bold",fontName="Arial") @@ -95,7 +100,9 @@ insert_worksheet <- function(data, workbook, sheetname="data",title="Title", sou if(nchar(sheetname)>31){warning("sheetname is cut to 31 characters (limit imposed by MS-Excel)")} ## Add worksheet - openxlsx::addWorksheet(wb,paste(substr(sheetname,0,31))) + # openxlsx::addWorksheet(wb,paste(substr(sheetname,0,31))) + + suppressWarnings(openxlsx::addWorksheet(wb,paste(substr(sheetname,0,31)))) i <- paste(substr(sheetname,0,31)) @@ -109,32 +116,38 @@ insert_worksheet <- function(data, workbook, sheetname="data",title="Title", sou #Logo -statzh <- paste0(.libPaths(),"/statR/data/Stempel_STAT-01.png") - - # file.exists(paste0(.libPaths(),"/statR/data/Stempel_STAT-01.png")) + if(!is.null(logo)){ + if(logo == "statzh") { - if(is.character(logo)){statzh <- paste0(logo)} + statzh <- paste0(.libPaths(),"/statR/extdata/Stempel_STAT-01.png") + openxlsx::insertImage(wb, i, statzh[1], width = 2.145, height = 0.7865, + units = "in") + } else if(logo == "zh"){ + zh <- paste0(.libPaths(),"/statR/extdata/Stempel_Kanton_ZH.png") - if (file.exists(statzh)) { + openxlsx::insertImage(wb, i, zh[1], width = 2.145, height = 0.7865, + units = "in") + } else if((logo != "statzh" | logo != "zh") & file.exists(logo)) { - # message("logo found and added") + openxlsx::insertImage(wb, i, logo, width = 2.145, height = 0.7865, + units = "in") + } else { + message("no logo found and / or added") + } + } - openxlsx::insertImage(wb, i, statzh, width = 2.145, height = 0.7865, - units = "in") - } else { - message("no logo found and / or added")} #standard contactdetails if(contactdetails=="statzh"){ contactdetails <- c("Datashop, Tel: 0432597500", - "datashop@statistik.ji.zh.ch", - "http://www.statistik.zh.ch") + "datashop@statistik.ji.zh.ch", + "http://www.statistik.zh.ch") }else {contactdetails} @@ -151,20 +164,22 @@ statzh <- paste0(.libPaths(),"/statR/data/Stempel_STAT-01.png") + #Titel + openxlsx::writeData(wb, sheet = i,title, headerStyle=titleStyle,startRow = 7) - # if (file.exists("L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/Stempel_STAT-01.png")) { - # openxlsx::insertImage(wb, paste(sheetname), "L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/Stempel_STAT-01.png",width=2.145, height=0.7865, units="in") - # } + ##Metadata + openxlsx::writeData(wb, sheet = i, metadata, headerStyle=subtitle, startRow = 8) - #Titel - openxlsx::writeData(wb, sheet = i,title, headerStyle=titleStyle,startRow = 7) ##Quelle - openxlsx::writeData(wb, sheet = i, source, headerStyle=subtitle, startRow = 8) + openxlsx::writeData(wb, sheet = i, source, headerStyle=subtitle, startRow = 8+n_metadata) + + # Metadaten zusammenmergen + purrr::walk(7:(7+length(metadata)+length(source)), ~openxlsx::mergeCells(wb, sheet = i, cols = 1:26, rows = .)) + # Kontaktdaten zusammenmergen + purrr::walk(2:5, ~openxlsx::mergeCells(wb, sheet = i, cols = contact:26, rows = .)) - ##Metadata - openxlsx::writeData(wb, sheet = i, metadata, headerStyle=subtitle, startRow = 9) #Kontakt openxlsx::writeData(wb, sheet = i, @@ -173,14 +188,27 @@ statzh <- paste0(.libPaths(),"/statR/data/Stempel_STAT-01.png") startRow = 2, startCol = contact) + # User-Kürzel für Kontaktinformationen + if(author == "user"){ + # für das lokale R + if(Sys.getenv("USERNAME")!="") { + contactperson <- stringr::str_sub(Sys.getenv("USERNAME"), start = 6, end = 7) + } else { + # für den R-server + contactperson <- stringr::str_sub(Sys.getenv("USER"), start = 6, end = 7) + } + } else { + contactperson <- author + } + #Aktualisierungsdatum openxlsx::writeData(wb, sheet = i, paste("Aktualisiert am ", - format(Sys.Date(), format="%d.%m.%Y"), " durch: ", - stringr::str_sub(Sys.getenv("USERNAME"),-2)), - headerStyle=subtitle, startRow = 5, startCol=contact) + format(Sys.Date(), format="%d.%m.%Y"), + " durch: ", contactperson), + headerStyle=subtitle, startRow = 5, startCol=contact) # Daten abfüllen - openxlsx::writeData(wb, sheet = i, as.data.frame(data%>%ungroup()), rowNames = FALSE, startRow = datenbereich, withFilter = FALSE) + openxlsx::writeData(wb, sheet = i, as.data.frame(data%>%dplyr::ungroup()), rowNames = FALSE, startRow = datenbereich, withFilter = FALSE) #Füge Formatierungen ein @@ -202,11 +230,16 @@ statzh <- paste0(.libPaths(),"/statR/data/Stempel_STAT-01.png") #Friere oberste Zeilen ein - openxlsx::freezePane(wb, sheet=i , firstActiveRow = datenbereich+2) + openxlsx::freezePane(wb, sheet=i , firstActiveRow = datenbereich+1) # bodyStyle <- createStyle(border="TopBottom", borderColour = "#4F81BD") # addStyle(wb, sheet = 1, bodyStyle, rows = 2:6, cols = 1:11, gridExpand = TRUE) - openxlsx::setColWidths(wb, i, cols=4:spalten, widths = "auto") ## set column width for row names column + + # minmale Spaltenbreite definieren + options("openxlsx.minWidth" = 5) + + # automatische Zellenspalten + openxlsx::setColWidths(wb, sheet = i, cols=1:spalten, widths = "auto", ignoreMergedCells = TRUE) ## set column width for row names column # newworkbook<<-wb diff --git a/R/insert_worksheet_nh.R b/R/insert_worksheet_nh.R new file mode 100644 index 0000000..ed7ad0d --- /dev/null +++ b/R/insert_worksheet_nh.R @@ -0,0 +1,223 @@ +# insert_worksheet_nh: add formatted worksheets without header to an existing Workbook + +#' insert_worksheet_nh +#' +#' Function to create formatted spreadsheets automatically +#' @param data data to be included in the XLSX-table. +#' @param workbook workbook object to write new worksheet in. +#' @param title title of the table and the sheet +#' @param sheetname name of the sheet-tab. +#' @param source source of the data. Defaults to "statzh". +#' @param metadata metadata-information to be included. Defaults to NA. +#' @param grouplines defaults to FALSE. Can be used to separate grouped variables visually. +#' @keywords insert_worksheet +#' @importFrom dplyr "%>%" +#' @noRd +#' @examples +#' # insertion of two worksheets in a existing workbook +#' +#' # create workbook +#' wb <- openxlsx::createWorkbook("hello") +#' +#' insert_worksheet_nh(mtcars[c(1:10),],wb,"mtcars",c(1:4),"carb",grouplines=c(1,5,6)) +#' +#' # create workbook +#' export <- openxlsx::createWorkbook("export") +#' +#' # insert a new worksheet +#' insert_worksheet_nh(head(mtcars) +#' ,export +#' ,"data1" +#' ,title = "Title" +#' ,source = "Quelle: Statistisches Amt Kanton Zürich" +#' ,metadata = "Bemerkung: ...") +#' +#' # insert a further worksheet +#' insert_worksheet_nh(tail(mtcars) +#' ,export +#' ,"data2" +#' ,title = "Title" +#' ,source = "Quelle: Statistisches Amt Kanton Zürich" +#' ,metadata = "Bemerkung: ...") +#'\dontrun{ +#' # save workbook +#' openxlsx::saveWorkbook(export,"example.xlsx") +#'} + +# Function + +insert_worksheet_nh <- function(data, + workbook, + sheetname="data", + title="Title", + source="statzh", + metadata = NA, + grouplines = FALSE +) { + + # Metadata + remarks <- if (is.na(metadata)) { + "Bemerkungen:"} + else if (metadata == "HAE") {"Die Zahlen der letzten drei Jahre sind provisorisch."} + else {metadata} + + + #Zahlenformat: Tausendertrennzeichen + # options("openxlsx.numFmt" = "#,###0") + + #extrahiere colname + # col_name <- rlang::enquo(sheetvar) + + wb <- workbook + + # data-container from row 5 + n_metadata <- length(metadata) + + datenbereich = 2 + n_metadata + 3 + + #define width of the area in which data is contained for formating + spalten = ncol(data) + + # increase width of colnames for better auto-fitting of column width + colnames(data) <- paste0(colnames(data), " ", sep = "") + + # #position of contact details + # contact = if(spalten>4){spalten-2}else{3} + + + # header1 <- createStyle(fontSize = 14, fontColour = "#FFFFFF", halign = "center", + # fgFill = "#3F98CC", border="TopBottom", borderColour = "#4F81BD") + + # header2 <- createStyle(fontSize = 12, fontColour = "#FFFFFF", halign = "center", + # fgFill = "#407B9F", border="TopBottom", borderColour = "#4F81BD") + + # headerline <- openxlsx::createStyle(border="Bottom", borderColour = "#009ee0",borderStyle = getOption("openxlsx.borderStyle", "thick")) + + #Linien + bottomline <- openxlsx::createStyle(border="Bottom", borderColour = "#009ee0") + + leftline <- openxlsx::createStyle(border="Left", borderColour = "#4F81BD") + + #wrap + wrap <- openxlsx::createStyle(wrapText = TRUE) + + # warning if sheetname is longer than the limit imposed by excel (31 characters) + if(nchar(sheetname)>31){warning("sheetname is cut to 31 characters (limit imposed by MS-Excel)")} + + ## Add worksheet + openxlsx::addWorksheet(wb,paste(substr(sheetname,0,31))) + + i <- paste(substr(sheetname,0,31)) + + + #styles + titleStyle <- openxlsx::createStyle(fontSize=14, textDecoration="bold",fontName="Arial") + + subtitle <- openxlsx::createStyle(fontSize=11, fontName="Calibri") + + header <- openxlsx::createStyle(fontSize = 12, fontName="Calibri", fontColour = "#000000", halign = "left", border="Bottom", borderColour = "#009ee0",textDecoration = "bold") + + + #Titel + openxlsx::addStyle(wb + ,sheet = i + ,titleStyle + ,rows = 2 + ,cols = 1 + #,gridExpand = TRUE + ) + openxlsx::writeData(wb + ,sheet = i + ,title + ,headerStyle=titleStyle + ,startRow = 2 + ) + + + ##Quelle + if(source=="statzh"){ + + source <- "Quelle: Statistisches Amt des Kantons Zürich" + + } else {source} + + + openxlsx::addStyle(wb + ,sheet = i + ,subtitle + ,rows = 3 + ,cols = 1 + ,gridExpand = TRUE + ) + openxlsx::writeData(wb + ,sheet = i + ,source + ,headerStyle=subtitle + ,startRow = 3 + ) + + + + ##Metadata + openxlsx::addStyle(wb + ,sheet = i + ,subtitle + ,rows = 4 + ,cols = 1 + ,gridExpand = TRUE + ) + openxlsx::writeData(wb + ,sheet = i + ,metadata + ,headerStyle=subtitle + ,startRow = 4 + ) + + + # Metadaten zusammenmergen + purrr::walk(1:(4+length(metadata)), ~openxlsx::mergeCells(wb, sheet = i, cols = 1:26, rows = .)) + + # Daten abfüllen + openxlsx::writeData(wb, + sheet = i + # ,as.data.frame(dpylr::ungroup()) + ,as.data.frame(dplyr::ungroup(data)) + ,rowNames = FALSE + ,startRow = datenbereich + ,withFilter = FALSE + ) + + #Füge Formatierungen ein + + openxlsx::addStyle(wb + ,sheet = i + ,header + ,rows = datenbereich + ,cols = 1:spalten + ,gridExpand = TRUE + ,stack = TRUE + ) + + if (!is.null(grouplines)){ + + datenbereich_end <-nrow(data)+datenbereich + + openxlsx::addStyle(wb + ,sheet = i + ,leftline + ,rows=datenbereich:datenbereich_end + ,cols = grouplines + ,gridExpand = TRUE + ,stack = TRUE + ) + + } + + # minmale Spaltenbreite definieren + options("openxlsx.minWidth" = 5) + + # automatische Spaltenbreite + openxlsx::setColWidths(wb, sheet = i, cols=1:spalten, widths = "auto", ignoreMergedCells = TRUE) + + +} diff --git a/R/interpolate.R b/R/interpolate.R index 7cffbf0..8fb0a46 100644 --- a/R/interpolate.R +++ b/R/interpolate.R @@ -1,34 +1,32 @@ -# interpolate2() #'interpolate2() #' -#' generate new palettes by interpolation -#' @param palette a vector of colors to be interpolated to the same degree with the same color to generate uniform color palettes -#' @param color a single color (hex-code) to be mixed with the colors in the 'palette'. +#' Function to generate new color palettes by interpolation. +#' @param palette a vector of colors to be interpolated +#' @param color color (hex-code) to be mixed with the colors in the 'palette'. #' @param degree degree of interpolation, range: 1 (slight interpolation) - 7 (strong interpolation). -#' @param number number of colours to be generated. +#' @param number number of colors to be generated. #' @keywords interpolate2 #' @export #' @examples -#' #interpolate the 'zhblue'-palette with black and generate 11 new hues. -#' interpolate2(zhpal$zhblue,"#000000",3,11) -#' +#' #interpolate the 'zhblue'-palette with black and generate 7 new ones +#' interpolate2(palette = zhpal$zhblue, color = c("#000000"), degree = 3, number = 7) +#' # Function - #interpolate function interpolate2<-function(palette, color = color, degree=degree,number=number){ newpalette <- c() for (i in palette) { intcols <-c(i,color) - pal = colorRampPalette(intcols) + pal = grDevices::colorRampPalette(intcols) # plotColors(pal, 7) intcols<- pal(7) newpalette[i] <- intcols[degree] - } - pal = colorRampPalette((newpalette),space="Lab") - show_col(pal(number)) + } + pal = grDevices::colorRampPalette((newpalette),space="Lab") + scales::show_col(pal(number)) pal(number) } diff --git a/R/quickXLSX.R b/R/quickXLSX.R index 274db12..1c013b9 100644 --- a/R/quickXLSX.R +++ b/R/quickXLSX.R @@ -1,40 +1,52 @@ -# quickXLSX: Function to create formatted spreadsheet with a single worksheet automatically - -#' quickXLSX +#' quickXLSX() #' -#' Function to create a formated single-worksheet XLSX automatically -#' @param data data to be included in the XLSX-table. -#' @param file filename of the xlsx-file. No Default. -#' @param title title of the table in the worksheet, defaults to "Titel". -#' @param source source of the data. Defaults to "statzh". -#' @param metadata metadata-information to be included. Defaults to NA. -#' @param logo path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh" -#' @param contactdetails contactdetails of the data publisher. Defaults to "statzh". -#' @param grouplines columns to be separated visually by vertical lines. +#' Function to export data from R to a formatted .xlsx-spreadsheet. +#' @param data data to be exported. +#' @param file file name of the xlsx-file. The extension ".xlsx" is added automatically. +#' @param title title to be put above the data in the worksheet. +#' @template shared_parameters #' @keywords quickXLSX #' @export #' @examples -#' quickXLSX(head(mtcars), "mtcars") +#' # Beispiel anhand des Datensatzes 'mtcars' +#'dat <- mtcars #' -#' #example with own logo, a custom filename, lines separating selected columns and some remarks +#'quickXLSX(data = dat, +#' title = "Motor trend car road tests", +#' file = "motor_trend_car_road_tests", # '.xlsx' is automatically added +#' source = "Source: Henderson and Velleman (1981). Building multiple +#' regression models interactively. +#' Biometrics, 37, 391–411.", +#' metadata = c("The data was extracted from the 1974 Motor Trend US +#' magazine and comprises fuel +#' consumption and 10 aspects of automobile design and performance +#' for 32 automobiles (1973–74 models)."), +#' contactdetails = "statzh", +#' grouplines = FALSE, +#' logo = "statzh", +#' author = "user") #' -#' quickXLSX(head(mtcars), file="filename", title="your title", source="alternative source",contactdetails="blavla", grouplines = c(1,2,3), metadata = "remarks:",logo="L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/nacht_map.png") - -quickXLSX <-function (data, file, ...) { +quickXLSX <-function (data, + file, + title="Title", + source="statzh", + metadata = NA, + logo="statzh", + grouplines = FALSE, + contactdetails="statzh", + author = "user") { #create workbook wb <- openxlsx::createWorkbook(paste(file)) #insert data - insert_worksheet(data, wb, ...) + insert_worksheet(data, wb, title=title, source=source, metadata = metadata, logo=logo, grouplines = grouplines, contactdetails=contactdetails, author = author) #save workbook openxlsx::saveWorkbook(wb, paste(file, ".xlsx", sep = ""), overwrite = TRUE) - # rm(newworkbook,envir = .GlobalEnv) - } diff --git a/R/quick_sum.r b/R/quick_sum.r new file mode 100644 index 0000000..336eb89 --- /dev/null +++ b/R/quick_sum.r @@ -0,0 +1,78 @@ +#' quick_sum() +#' +#' Function for simple (grouped) descriptive analyses. +#' +#' If stats is set to "all" (the default), the following descriptive statistics are computed per category of the grouping variable(s): mean, standard deviation, +#' 10\%-quantile, 25\%-quantile, median, 75\%-quantile, 90\%-quantile. +#' If stats is set to "base", the mean, 25\%-quantile, median, and 75\%-quantile are returned. +#' stats = "mean" computes the mean and the standard deviation. +#' +#' If protect is set to TRUE, the mean and the median is only computed for variables/variable categories with four or more observations. For <4 observations, the function returns NA for the respective variable/category. The other descriptives are only computed if there are at least 6 observations per variable (category). +#' +#' @param df dataframe +#' @param var variables to be aggregated +#' @param ... grouping variables +#' @param stats Which descriptive statistics should be computed? Can be "all", "base", or "mean". See details. +#' @param protect Apply data protection, can be TRUE or FALSE. See details. +#' @keywords quick_sum +#' @importFrom dplyr ungroup summarize group_by n +#' @importFrom stats median quantile sd +#' @export +#' @examples +#' +#' quick_sum(df=mtcars, var=cyl, mpg, vs, stats="all", protect=FALSE) + + +quick_sum <- function(df, var, ..., stats="all", protect=FALSE) { + grps <- rlang::quos(...) + var <- rlang::enquo(var) + + mean_name <- paste0("mean_", rlang::quo_name(var)) + sd_name <- paste0("sd_", rlang::quo_name(var)) + q10_name <- paste0("q10_", rlang::quo_name(var)) + q25_name <- paste0("q25_", rlang::quo_name(var)) + med_name <- paste0("med_", rlang::quo_name(var)) + q75_name <- paste0("q75_", rlang::quo_name(var)) + q90_name <- paste0("q90_", rlang::quo_name(var)) + + if(protect==TRUE){ + n1 <- 3 + n2 <- 5 + }else{ + n1 <- 0 + n2 <- 0 + } + + if(stats%in%c("base")){df %>% + dplyr::group_by(!!!grps) %>% + dplyr::summarise( + Anzahl=dplyr::n(), + !!mean_name := ifelse(Anzahl<=n1,NA,mean(!!var, na.rm = T)), + !!q25_name := ifelse(Anzahl<=n2,NA,quantile(!!var, probs=0.25, na.rm = T)), + !!med_name := ifelse(Anzahl<=n1,NA,median(!!var, probs=0.5, na.rm = T)), + !!q75_name := ifelse(Anzahl<=n2,NA,quantile(!!var, probs=0.75, na.rm = T)) + )%>% + dplyr::ungroup()} + else if(stats%in%c("all")){df %>% + dplyr::group_by(!!!grps) %>% + dplyr::summarise( + Anzahl=dplyr::n(), + !!mean_name := ifelse(Anzahl<=n1,NA,mean(!!var, na.rm = T)), + !!sd_name := ifelse(Anzahl<=n2,NA,sd(!!var, na.rm = T)), + !!q10_name := ifelse(Anzahl<=n2,NA,quantile(!!var, probs=0.1, na.rm = T)), + !!q25_name := ifelse(Anzahl<=n2,NA,quantile(!!var, probs=0.25, na.rm = T)), + !!med_name := ifelse(Anzahl<=n1,NA,median(!!var, probs=0.5, na.rm = T)), + !!q75_name := ifelse(Anzahl<=n2,NA,quantile(!!var, probs=0.75, na.rm = T)), + !!q90_name := ifelse(Anzahl<=n2,NA,quantile(!!var, probs=0.9, na.rm = T)) + )%>% + dplyr::ungroup()} + else if(stats%in%c("mean")){df %>% + dplyr::group_by(!!!grps) %>% + dplyr::summarise( + Anzahl=dplyr::n(), + !!mean_name := ifelse(Anzahl<=n1,NA,mean(!!var, na.rm = T)), + !!sd_name := ifelse(Anzahl<=n2,NA,sd(!!var, na.rm = T)) + )%>% + dplyr::ungroup()} + else {print("Please choose one of the following stats arguments: all, base, mean")} +} diff --git a/R/splitXLSX.R b/R/splitXLSX.R index ce53cb3..3aaf926 100644 --- a/R/splitXLSX.R +++ b/R/splitXLSX.R @@ -1,51 +1,71 @@ -# splitXLSX: Function to create formatted with multiple worksheets spreadsheets automatically - -#' splitXLSX +#' splitXLSX() #' -#' Function to create formatted spreadsheets automatically -#' @param data data to be included in the XLSX-table. -#' @param file filename of the xlsx-file. No Default. -#' @param title title of the table in the worksheet, defaults to "Titel" + the value of the variable used to split the dataset across sheets. -#' @param sheetvar variable which contains the variable to be used to split the data across several sheets. -#' @param source source of the data. Defaults to "statzh". -#' @param metadata metadata-information to be included. Defaults to NA. -#' @param logo path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh" -#' @param contactdetails contactdetails of the data publisher. Defaults to "statzh". -#' @param grouplines columns to be separated visually by vertical lines. +#' Function to export data from R as formatted .xlsx-file and spread them over several worksheets based on a grouping variable (e.g., year). +#' @param data data to be exported. +#' @param file file name of the xlsx-file. The extension ".xlsx" is added automatically. +#' @param sheetvar name of the variable used to split the data and spread them over several sheets. +#' @param title title to be put above the data in the worksheet. the sheetvar subcategory is added in brackets. +#' @template shared_parameters #' @keywords splitXLSX #' @export #' @examples -#' # Generation of a spreadsheet with four worksheets (one per 'carb'-category). -#' # Can be used to generate worksheets for multiple years. #' -#' splitXLSX(mtcars[c(1:10),],"mtcars",carb,grouplines=c(1,5,6)) +#' dat <- mtcars #' -#' splitXLSX(head(mtcars),carb, file="filename",grouplines = c(1,2,3), metadata = "remarks: ....",source="canton of zurich",logo="L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/nacht_map.png") +#'splitXLSX(data = dat, +#' title = "Motor trend car road tests", +#' file = "motor_trend_car_road_tests", # '.xlsx' automatically added +#' sheetvar = cyl, +#' source = "Source: Henderson and Velleman (1981), +#' Building multiple regression models interactively. +#' Biometrics, 37, 391–411.", +#' metadata = c("The data was extracted from the 1974 +#' Motor Trend US magazine and comprises fuel consumption and +#' 10 aspects of automobile design and performance for +#' 32 automobiles (1973–74 models)."), +#' contactdetails = "statzh", +#' grouplines = FALSE, +#' logo = "statzh", +#' author = "user") # Function -splitXLSX <- function(data, file, sheetvar, ...) { - +splitXLSX <- function (data, + file, + sheetvar, + title="Titel", + source="statzh", + metadata = NA, + logo="statzh", + grouplines = FALSE, + contactdetails="statzh", + author = "user") +{ data <- as.data.frame(data) - #extract colname + # extract column name col_name <- rlang::enquo(sheetvar) # create workbook wb <- openxlsx::createWorkbook(file) + # get values of the variable that is used to split the data + sheetvalues <- unique(data[, c(deparse(substitute(sheetvar)))]) + # loop to split values of the variable used to split the data + for (sheetvalue in sheetvalues) { - #get values of the variable that is used to split the data - sheetvalues <- unique(data[,c(deparse(substitute(sheetvar)))]) - - #Loop to split data across multiple worksheets ------- - - for (sheetvalue in sheetvalues){ - - #get data into workheets - insert_worksheet(as.data.frame(data %>% dplyr::filter((!!col_name) == sheetvalue)%>%ungroup()), - wb, sheetname = paste(deparse(substitute(sheetvar)), sheetvalue,sep=","), ...) + # get data into worksheets + insert_worksheet(as.data.frame(data %>% dplyr::filter((!!col_name) == + sheetvalue) %>% ungroup()), wb, sheetname = sheetvalue, + #shared params + title=paste0(title, " (", deparse(substitute(sheetvar)), ": ", sheetvalue, ")"), + source=source, + metadata = metadata, + logo=logo, + grouplines = grouplines, + contactdetails=contactdetails, + author = author) } @@ -63,3 +83,6 @@ splitXLSX <- function(data, file, sheetvar, ...) { + + + diff --git a/R/theme_stat.r b/R/theme_stat.r index cf06ee5..8bae950 100644 --- a/R/theme_stat.r +++ b/R/theme_stat.r @@ -1,77 +1,184 @@ +#' theme_stat() +#' +#' This ggplot2 theme is based on ggplot2::theme_minimal(). It controls the non-data related characteristics of a plot (e.g., the font type). +#' On top of that, the font size, the presence (or absence) of minor grid lines, axis lines, axis ticks and the axis label positions can be specified. +#' +#' To use this theme in a R Markdown generated PDF document, insert `dev="cairo_pdf"` into `knitr::opts_chunk$set()`. +#' @inheritParams ggplot2::theme_bw +#' @param axis.label.pos position of x and y-axis labels, can be set to "top", "center", or "bottom". +#' @param axis.lines presence of axis lines, can be set to "x", "y", or "both". +#' @param ticks presence of axis ticks, can be set to "x", "y", or "both". +#' @param minor.grid.lines presence of minor grid lines on the y-axis, can be set to TRUE or FALSE. +#' @keywords theme_stat +#' @export +#' @importFrom ggplot2 theme_minimal theme element_blank element_line unit continuous_scale +#' @examples +#'\donttest{ +#' \dontrun{ +#' library(ggplot2) +#' library(statR) +#' +#' ggplot(mpg, aes(class)) + +#' geom_bar() + +#' theme_stat() + +#' labs(title = "Title") +#' }} +theme_stat <- function(base_size = 11, axis.label.pos = "top", axis.lines = "x", + ticks = "x", minor.grid.lines = FALSE){ -# ---------------------- BASIEREND AUF THEME_MINIMAL ----------------------- -library(RColorBrewer) -library(ggplot2) -library(grid) -# windowsFonts(arial=windowsFont("Arial Fett")) + palette <- RColorBrewer::brewer.pal("Greys", n=9) + color.grid = palette[5] + color.title = palette[9] + color.axis = palette[7] + theme_var <- ggplot2::theme_minimal(base_family = "arial") + + # TEXTE + ggplot2::theme( + text = ggplot2::element_text(size = base_size, color = color.axis, face = "plain", family = "arial"), -palette <- brewer.pal("Greys", n=9) -color.grid = palette[5] -color.title = palette[9] -color.axis = palette[7] + plot.title = ggplot2::element_text(size = base_size*4/3, colour = color.title, face = "bold", family="arialblack"), + plot.subtitle = ggplot2::element_text(size = base_size, color = color.title, face = "plain", family = "arial"), + plot.caption = ggplot2::element_text(size = base_size, color = color.title, face = "plain", family = "arial", hjust = 0), -txt <- element_text(size = 11, colour = color.axis, face = "plain") -bold_txt <- element_text(size = 11, colour = color.axis, face = "bold") + strip.text = ggplot2::element_text(size = base_size, color = color.axis, face = "plain", family = "arial"), -# theme_stat + axis.title = ggplot2::element_text(size = base_size, color = color.axis, face = "plain", family = "arial"), + axis.text = ggplot2::element_text(size = base_size, color = color.axis, face = "plain", family = "arial"), -#' theme_stat() -#' -#' Stat ZH Theme for ggplot2 -#' @inheritParams ggplot2::theme_bw -#' @keywords theme_stat -#' @export -#' @examples -#' theme_stat() -#' - -# Function -theme_stat <- function(base_size = 11 - # , base_family = "arial" - ){ - theme_minimal(base_size = base_size - # , base_family = base_family - ) + - theme( - legend.key = element_blank(), - strip.background = element_blank(), - - legend.position = "bottom", - - text = txt, - plot.title = element_text(size = 14, colour = color.title, face = "bold"), - strip.text = txt, - - axis.title = txt, - axis.text = txt, - - legend.title = bold_txt, - legend.text = txt ) + - - # ACHSEN - theme( - axis.title.x = element_text(color=color.axis, vjust= 0), - axis.title.y = element_text(color=color.axis, vjust= 1.25), - axis.line = element_line(colour = color.axis, size = 0.5), - axis.line.x = element_line(colour = color.axis, size = 0.5), - axis.line.y = element_blank(), - axis.ticks = element_line(colour = color.axis, size = 0.5), - axis.ticks.x = element_line(colour = color.axis, size = 0.5), - axis.ticks.y = element_blank(), - # axis.ticks.x = element_line(colour = color.axis, size = 0.8), - axis.ticks.length = unit(0.15, "cm") - ) + - # theme(plot.title = element_text(hjust = -1))+ - - # GITTERNETZLINIEN - theme(panel.grid.minor = element_line(colour = color.grid, linetype = "dotted", size = 0.4), - panel.grid.major = element_line(colour = color.grid, linetype = "dotted", size = 0.4) - , panel.grid.major.x = element_blank(), panel.grid.minor.x = element_blank() - ) + - - # Plot margins - theme(plot.margin = unit(c(0.3, 0.3, 0.3, 0.3), "cm") ) + legend.title = ggplot2::element_text(size = base_size, color = color.axis, face = "plain", family = "arial"), + legend.text = ggplot2::element_text(size = base_size, color = color.axis, face = "plain", family = "arial") + ) + + # ACHSEN + + ## Achsenposition + if(axis.label.pos == "top") { + vjust.x <- 0 + hjust.x <- 1 + vjust.y <- 1 + hjust.y <- 1 + } else if(axis.label.pos == "center") { + vjust.x <- 0 + hjust.x <- 0.5 + vjust.y <- 1 + hjust.y <- 0.5 + } else if(axis.label.pos == "bottom"){ + vjust.x <- 0 + hjust.x <- 0 + vjust.y <- 1 + hjust.y <- 0 + } + + theme_var <- theme_var + + ggplot2::theme(axis.title.x = ggplot2::element_text(color=color.axis, vjust= vjust.x, hjust = hjust.x), + axis.title.y = ggplot2::element_text(color=color.axis, vjust= vjust.y, hjust = hjust.y)) + + ## Achsenlinien + + if(axis.lines == "both") { + theme_var <- theme_var + + ggplot2::theme( + axis.line = ggplot2::element_line(colour = color.axis, size = 0.2), + axis.line.x = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.line.y = ggplot2::element_line(colour = color.axis, size = 0.25) + ) + } + + if (axis.lines == "x") { + theme_var <- theme_var + + ggplot2::theme( + axis.line = ggplot2::element_line(colour = color.axis, size = 0.2), + axis.line.x = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.line.y = ggplot2::element_blank() + ) + } + + if (axis.lines == "y") { + theme_var <- theme_var + + ggplot2::theme( + axis.line = ggplot2::element_line(colour = color.axis, size = 0.2), + axis.line.y = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.line.x = ggplot2::element_blank(), + ) + } + + ## Achsenticks + + if(ticks == "x") { + theme_var <- theme_var + + ggplot2::theme( + axis.ticks = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.ticks.x = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.ticks.y = ggplot2::element_blank(), + axis.ticks.length = unit(0.1, "cm") + ) + + } + + if(ticks == "y") { + theme_var <- theme_var + + ggplot2::theme( + axis.ticks = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.ticks.y = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.ticks.x = ggplot2::element_blank(), + axis.ticks.length = unit(0.1, "cm") + ) + + } + + if(ticks == "both") { + theme_var <- theme_var + + ggplot2::theme( + axis.ticks = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.ticks.x = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.ticks.y = ggplot2::element_line(colour = color.axis, size = 0.25), + axis.ticks.length = unit(0.1, "cm") + ) + + } + + + # GITTERNETZLINIEN + + if(minor.grid.lines == TRUE) { + theme_var <- theme_var + + ggplot2::theme( + panel.grid.minor = ggplot2::element_line(colour = color.grid, size = 0.1), + panel.grid.major = ggplot2::element_line(colour = color.grid, size = 0.2), + panel.grid.major.x = ggplot2::element_blank(), panel.grid.minor.x = ggplot2::element_blank() + ) + + } else { + theme_var <- theme_var + + ggplot2::theme( + panel.grid.minor = ggplot2::element_blank(), + panel.grid.major = ggplot2::element_line(colour = color.grid, size = 0.2), + panel.grid.major.x = ggplot2::element_blank(), panel.grid.minor.x = ggplot2::element_blank() + + ) + } + + # PANELS + theme_var + + ggplot2::theme( + panel.spacing.x = unit(15, "pt"), + panel.spacing.y = unit(15, "pt"), + strip.background = ggplot2::element_blank() + + )+ + # LEGEND + ggplot2::theme( + legend.box.spacing = unit(0, "cm"), + legend.box.margin = ggplot2::margin(0, 0, 1, -1, "mm"), + legend.position = "top", + legend.justification = "left", + # legend.spacing = unit(c(0, 0, 0, 0), "mm"), + legend.key.width = unit(4, "mm"), + legend.key.height = unit(3, "mm") + )+ + + # PLOT MARGINS + ggplot2::theme(plot.margin = unit(c(0.3, 0.3, 0.3, 0.3), "cm")) } diff --git a/README.md b/README.md index 9e06b6c..a303e41 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,34 @@ -# statR +# statR -This is the github-repository for the **statR** package - the Corporate Design Toolbox for R of the statistical office of the canton of Zurich for corporate design conforming graphics and spreadsheets. It contains: +

+ -- *generic colour palettes for any kind of data-visualization* +Mit dem `statR`-Package können mit dem Corporate Design des Kantons Zürich konforme Visualisierungen, Excel-Tabellen und Html-Berichte in `R` erstellt werden. Das Package beinhaltet: -- *ggplot2-theme* -- *templates for saving data in CD-conforming formated xlsx-spreadsheets* +- Funktionen, mit denen Datensätze aus R als XLSX-Datei abgespeichert werden können (inkl. Quellenangaben und weiteren Zusatzinformationen). -statR is a complement to the [**statRmd**](https://github.com/statistikZH/statRmd) package, which can be used to generate nicely formatted, ready-to-publish .pdf reports. +- generische Farbpaletten für Datenvisualisierungen -For examples and instructions please consult the vignette: +- ein `ggplot2` theme -https://statistikzh.github.io/statR/ +- ein Template für Html-Berichte + + +# Installation + +Die development-Version des Package liegt auf GitHub. Sie kann auf zwei Arten installiert werden: + +``` +# Variante 1 + +library(downloader) +download("https://github.com/statistikZH/statR/archive/dev.tar.gz", "statR.tar.gz") +install.packages("statR.tar.gz", repos = NULL, type = "source") + + +# Variante 2 + +library(devtools) +devtools::install_github("statistikZH/statR",ref="dev") +``` diff --git a/docs/404.html b/docs/404.html new file mode 100644 index 0000000..5e50d2f --- /dev/null +++ b/docs/404.html @@ -0,0 +1,177 @@ + + + + + + + + +Page not found (404) • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+
+ + + + +
+ +
+
+ + +Content not found. Please use links in the navbar. + +
+ + + +
+ + + +
+ + + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + + + diff --git a/docs/LICENSE.html b/docs/LICENSE.html new file mode 100644 index 0000000..2387cc9 --- /dev/null +++ b/docs/LICENSE.html @@ -0,0 +1,399 @@ + + + + + + + + +GNU General Public License • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
+ +

Version 3, 29 June 2007
Copyright © 2007 Free Software Foundation, Inc. <http://fsf.org/>

+

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.

+
+ +
+

+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.

+
<one line to give the program's name and a brief idea of what it does.>
+Copyright (C) 2021 Statistisches Amt des Kantons Zürich
+
+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 <http://www.gnu.org/licenses/>.
+

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:

+
statR Copyright (C) 2021 Statistisches Amt des Kantons Zürich
+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 <http://www.gnu.org/licenses/>.

+

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 <http://www.gnu.org/philosophy/why-not-lgpl.html>.

+
+
+ +
+ + + +
+ + + +
+ + + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + + + diff --git a/docs/articles/Excel-Tabellen.html b/docs/articles/Excel-Tabellen.html new file mode 100644 index 0000000..8f8c3a8 --- /dev/null +++ b/docs/articles/Excel-Tabellen.html @@ -0,0 +1,262 @@ + + + + + + + +Excel-Tabellen • statR + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +
+

+Allgemeine Informationen

+

statR enthält mehrere Funktionen, mit welchen Datensätze aus R als Excel-Dateien exportiert werden können. Die Funktionen bauen auf dem openxlsx-package auf.

+

Per Default wird bei allen Funktionen das Logo des Statistischen Amts eingefügt und es werden die Kontaktangaben des Data Shops angegeben (contactdetails = "statzh", logo = "statzh", source = "statzh"). Mit den Funktionsargumenten können die Dateinamen, Titel, Quellenangaben sowie Metadaten und Namenskürzel spezifiziert werden. Um längere Quellen- und Metadatenangaben über mehrere Zeilen eines Arbeitsblatts zu verteilen, kann man sie in verschiedene Vektorelemente aufteilen (Beispiel: c("Text Zeile 1, "Text Zeile 2", "Text Zeile 3"). Mit dem Argument grouplines werden zudem vertikale Linien zwischen ausgewählten Spalten in der Excel-Tabelle eingefügt und die Spalten optisch voneinander separiert (aktuell nicht möglich bei datasetsXLSX()).

+

Die Spalteninhalte können bei allen Funktionen entsprechend ihrer Einheit formatiert werden, indem pro Variablennamen die class festlegt wird. Mit class(data$variable1) <- "percentage" können die Werte der variable1 (reichen von 0 bis 1) als Prozent mit Prozentzeichen ausgegeben werden. Weblinks können mit class(data$variable2) <- "hyperlink" aufrufbar gemacht werden und mit class(data$variable3) <- "scientific" können Zahlen in der wissenschaftlichen Notation dargestellt werden.

+
+
+

+Funktionen und Beispiele

+
+

+quickXLSX()

+

Mit der Funktion quickXLSX() kann ein Datensatz aus R als vorformatierte XLSX-Datei exportiert werden. Die Funktion eignet sich, um einzelne Datensätze als Exceldatei zu verschicken. Mit dem Argument author kann vermerkt werden, wer die Datei erstellt hat. Per Default werden die Initialen bzw. letzten zwei Ziffern des hinterlegten Benutzernamens eingefügt.

+
+# Beispiel anhand des Datensatzes 'mtcars'
+dat <- mtcars
+
+quickXLSX(data = dat, 
+          title = "Motor trend car road tests", 
+          file = "motor_trend_car_road_tests", # '.xlsx' wird automatisch hinzugefügt
+          source = "Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.",
+          metadata = c("The data was extracted from the 1974 Motor Trend US magazine and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models)."),
+          contactdetails = "statzh",
+          logo = "statzh",
+          grouplines = FALSE,
+          author = "MD")
+
+

Screenshot der Datei motor_trend_car_road_tests.xlsx

+
+
+
+

+splitXLSX()

+

Mit der Funktion splitXLSX() kann ein Datensatz aus R in eine XLSX-Datei exportiert und auf mehreren Arbeitsblättern verteilt werden. Die Funktion ist besonders dann geeignet, wenn man einen Datensatz für verschiedene Ausprägungen einer Gruppierungsvariable (z.B. Altersklassen) separat aufführen möchte. Mit dem Argument author kann vermerkt werden, wer die Datei erstellt hat. Per Default werden die Initialen bzw. letzten zwei Ziffern des hinterlegten Benutzernamens eingefügt.

+

Im Beispiel unten wird ein Arbeitsblatt pro Zylinderanzahl der Autos im mtcars-Datensatz generiert.

+
+# Beispiel anhand des Datensatzes 'mtcars'
+dat <- mtcars
+
+# Beispiel mit Standardlogo (Logo des Statistischen Amts)
+splitXLSX(data = dat,
+          title = "Motor trend car road tests",
+          file = "motor_trend_car_road_tests", # '.xlsx' wird automatisch hinzugefügt
+          sheetvar = cyl, # Variable, nach der die Daten auf die Tabellenblätter aufgeteilt werden sollen
+          source = "Source: Henderson and Velleman (1981), Building multiple regression models interactively. Biometrics, 37, 391–411.",
+          metadata = c("The data was extracted from the 1974 Motor Trend US magazine and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models)."),
+          contactdetails = "statzh",
+          grouplines = FALSE,
+          logo = "statzh",
+          author = "MD")
+
+

Screenshot der Datei motor_trend_car_road_tests.xlsx

+
+
+
+

+datasetsXLSX() (NEU)

+

Die Funktion datasetsXLSX() erlaubt es, mehrere Datensätze und/oder Grafiken aus R in eine XLSX-Datei zu exportieren. Pro Arbeitsblatt wird ein Datensatz oder eine Grafik dargestellt. Es kann auch eine Auftragsnummer hinzugefügt werden. Die Funktion eignet sich besonders für Fälle, wo man mehrere Datensätze an eine/n Empfänger/in verschicken möchte.

+

Die Datensätze, die zusammen in einer Excel-Datei erscheinen sollen, müssen dem Funktionsargument datasets als Liste übergeben werden (datasets = list(dataset1, dataset2, ...).

+
+# Beispiel mit zwei Datensätzen:
+dat1 <- mtcars
+dat2 <- PlantGrowth
+
+datasetsXLSX(file="twoDatasets", # '.xlsx' wird automatisch hinzugefügt
+             maintitle = "Autos und Pflanzen", 
+             datasets = list(dat1, dat2),
+             sheetnames = c("Autos","Blumen"),
+             titles = c("mtcars-Datensatz","PlantGrowth-Datensatz"),
+             sources = c("Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.", 
+                         "Dobson, A. J. (1983) An Introduction to Statistical Modelling. London: Chapman and Hall."),
+             metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", 
+                           "Bemerkungen zum PlantGrowth-Datensatz: x"),
+             auftrag_id="A2021_0000", 
+             logo = "statzh",
+             homepage = "statzh",
+             contact = "statzh",
+             openinghours = "statzh",
+             titlesource = "Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.")
+
+

Screenshot des Titelblatts der Datei twoDatasets.xlsx

+
+
+

Screenshot des ersten Blatts der Datei twoDatasets.xlsx

+
+

Um eine Grafik in die Excel-Datei einzufügen, muss sie der datasets-Liste hinzugefügt werden: datasets = list(dataset1, dataset2, grafik1).

+

Mit den Argumenten startrows und startcols kann bestimmt werden, wo im Arbeitsblatt die Grafik platziert werden soll und mit widths und heights kann man die Höhe und die Breite adjustieren (aktuell in Zoll/inches, 1 Zoll = 2.54 cm). Die Grösse und Position wird mittels eines Vektors bestimmt, wobei es pro Arbeitsblatt ein Vektorelement gibt. Die Vektorelemente müssen überall auf = 0 gesetzt sein ausser bei den Visualisierungen. Bei zwei Datensätzen und einer Grafik sieht der Vektor bspw. folgendermassen aus: c(0,0,4). Hätte man einen Datensatz und zwei Grafiken, sähe der Vektor hingegen so aus: c(0,4,4).

+
+
+dat1 <- mtcars
+dat2 <- PlantGrowth
+fig <- hist(mtcars$disp)
+
+datasetsXLSX(file="twoDatasetsandFigure",
+             maintitle = "Autos und Pflanzen", # '.xlsx' wird automatisch hinzugefügt
+             datasets = list(dat1, dat2, fig),
+             widths = c(0,0,5),
+             heights = c(0,0,5),
+             startrows = c(0,0,3),
+             startcols = c(0,0,3),
+             sheetnames = c("Autos","Blumen", "Histogramm"),
+             logo = "statzh",
+             titles = c("mtcars-Datensatz","PlantGrowth-Datensatz", "Histogramm"),
+             sources = c("Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.", 
+                         "Source: Dobson, A. J. (1983) An Introduction to Statistical Modelling. London: Chapman and Hall."),
+             metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", 
+                           "Bemerkungen zum PlantGrowth-Datensatz: x"),
+             auftrag_id="A2021_0000",
+             contact = "statzh",
+             openinghours = "statzh",
+             titlesource = "Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.")
+
+
+
+ + + +
+ + + +
+ + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + diff --git a/docs/articles/Excel-Tabellen_files/anchor-sections-1.0/anchor-sections.css b/docs/articles/Excel-Tabellen_files/anchor-sections-1.0/anchor-sections.css new file mode 100644 index 0000000..07aee5f --- /dev/null +++ b/docs/articles/Excel-Tabellen_files/anchor-sections-1.0/anchor-sections.css @@ -0,0 +1,4 @@ +/* Styles for section anchors */ +a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} +a.anchor-section::before {content: '#';} +.hasAnchor:hover a.anchor-section {visibility: visible;} diff --git a/docs/articles/Excel-Tabellen_files/anchor-sections-1.0/anchor-sections.js b/docs/articles/Excel-Tabellen_files/anchor-sections-1.0/anchor-sections.js new file mode 100644 index 0000000..570f99a --- /dev/null +++ b/docs/articles/Excel-Tabellen_files/anchor-sections-1.0/anchor-sections.js @@ -0,0 +1,33 @@ +// Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. +document.addEventListener('DOMContentLoaded', function() { + // Do nothing if AnchorJS is used + if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { + return; + } + + const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); + + // Do nothing if sections are already anchored + if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { + return null; + } + + // Use section id when pandoc runs with --section-divs + const section_id = function(x) { + return ((x.classList.contains('section') || (x.tagName === 'SECTION')) + ? x.id : ''); + }; + + // Add anchors + h.forEach(function(x) { + const id = x.id || section_id(x.parentElement); + if (id === '') { + return null; + } + let anchor = document.createElement('a'); + anchor.href = '#' + id; + anchor.classList = ['anchor-section']; + x.classList.add('hasAnchor'); + x.appendChild(anchor); + }); +}); diff --git a/docs/articles/Excel-Tabellen_files/header-attrs-2.5/header-attrs.js b/docs/articles/Excel-Tabellen_files/header-attrs-2.5/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Excel-Tabellen_files/header-attrs-2.5/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/Excel-Tabellen_files/header-attrs-2.6/header-attrs.js b/docs/articles/Excel-Tabellen_files/header-attrs-2.6/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Excel-Tabellen_files/header-attrs-2.6/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/Excel-Tabellen_files/header-attrs-2.7/header-attrs.js b/docs/articles/Excel-Tabellen_files/header-attrs-2.7/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Excel-Tabellen_files/header-attrs-2.7/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/Sonstige_Funktionen.html b/docs/articles/Sonstige_Funktionen.html new file mode 100644 index 0000000..f0412c9 --- /dev/null +++ b/docs/articles/Sonstige_Funktionen.html @@ -0,0 +1,183 @@ + + + + + + + +Sonstige Funktionen • statR + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

Neben Funktionen zur Excel-Dateierzeugung und Visualisierungen beinhaltet statR auch zwei weitere Hilfsfunktionen. quick_sum() erleichtert das Erstellen von deskriptiven Übersichtstabellen. interpolate2() kann zur Generierung von individualisierten Farbpaletten verwendet werden.

+
+

+quick_sum()

+

Mit der Funktion quick_sum() können deskriptive Statistiken berechnet werden. Je nach Spezifikation des stats-Arguments wird eine andere Anzahl Statistiken angezeigt (Durchschnitt, Median, Standardabweichung, Quantile, etc.). Siehe ?quick_sum().

+

Im Beispiel unten wird mittels der Funktion berechnet, wie viele mpg (Miles/(US) gallon) die Autos abhängig von der Zylinderanzahl (cyl) und ihres Motorentyps (vs; ‘V-shaped’ oder ‘straight’) haben. Ausgegeben werden die Ausprägungen der Gruppierungsvariablen, die Anzahl sowie der Durchschnitt und die Quartile.

+
+library(statR)
+quick_sum(df=mtcars, var=mpg, cyl, vs, stats="base", protect=FALSE)
+#> # A tibble: 5 x 7
+#>     cyl    vs Anzahl mean_mpg q25_mpg med_mpg q75_mpg
+#>   <dbl> <dbl>  <int>    <dbl>   <dbl>   <dbl>   <dbl>
+#> 1     4     0      1     26      26      26      26  
+#> 2     4     1     10     26.7    22.8    25.8    30.4
+#> 3     6     0      3     20.6    20.4    21      21  
+#> 4     6     1      4     19.1    18.0    18.6    19.8
+#> 5     8     0     14     15.1    14.4    15.2    16.2
+
+
+

+interpolate2()

+

Mit der Funktion interpolate2() können neue Farbpaletten erstellt werden, indem zhpal-Paletten mit einer oder mehreren Farben interpoliert werden. Die Funktion baut auf grDevices::colorRamp() auf. Mit dem Argument degree kann die Stärke der Interpolation bestimmt werden (von 1 bis 7) und mit dem Argument number die Anzahl der Farben, die die neue Palette enthalten soll.

+

Im Beispiel unten wird die Palette zhpal$zhblue mit schwarz (“#000000”) interpoliert.

+
+new <- interpolate2(palette = zhpal$zhblue, color = c("#000000"), degree = 3, number = 7)
+

+

So sieht die ursprüngliche Palette aus:

+
+display(zhpal$zhblue)
+

+

Zum direkten Vergleich die interpolierte Palette:

+
+display(new)
+

+
+
+ + + +
+ + + +
+ + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + diff --git a/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000..09c6f50 Binary files /dev/null and b/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 0000000..f353962 Binary files /dev/null and b/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..5f5dc72 Binary files /dev/null and b/docs/articles/Sonstige_Funktionen_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/Sonstige_Funktionen_files/header-attrs-2.6/header-attrs.js b/docs/articles/Sonstige_Funktionen_files/header-attrs-2.6/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Sonstige_Funktionen_files/header-attrs-2.6/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/Sonstige_Funktionen_files/header-attrs-2.7/header-attrs.js b/docs/articles/Sonstige_Funktionen_files/header-attrs-2.7/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Sonstige_Funktionen_files/header-attrs-2.7/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/Visualisierungen.html b/docs/articles/Visualisierungen.html new file mode 100644 index 0000000..2f8b748 --- /dev/null +++ b/docs/articles/Visualisierungen.html @@ -0,0 +1,311 @@ + + + + + + + +Visualisierungen • statR + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +
+

+theme_stat() für ggplot2-Grafiken

+ +

Das statR-ggplot2-theme ist darauf ausgelegt, sich gut ins kantonale Corporate Design einzufügen. Es basiert auf dem ggplot2-theme ‘minimal’ und bestimmt diejenigen Grafikeigenschaften, die nichts mit den Daten an sich zu tun haben (z.B. die Schriftart).

+

Innerhalb des themes kann die Schriftgrösse, die Position der Achsenbeschriftungen sowie das Vorhandensein von Achsenlinien, Achsen-Ticks und kleineren Gitterlinien bestimmt werden.

+
+ggplot(mpg, aes(class,fill = drv))+
+  geom_bar()+
+  # Default-Spezifikationen innerhalb theme_stat()
+  theme_stat(base_size = 11,
+             axis.label.pos = "top",
+             axis.lines = "x",
+             ticks = "x",
+             minor.grid.lines = FALSE) +
+  labs(title = "Title", subtitle = "Subtitle", caption = "Caption")
+

+
+
+

+Farbpaletten

+

Das Farbpalettenobjekt zhpal enthält alle im Package vorhandenen Farbpaletten und ist mit dem geladenen statR-Package global verfügbar.

+

Mit der Funktion display() kann man sich die Farben einer Palette anschauen:

+
+display(zhpal$zhdiagonal)
+

+

Mit der Funktion grDevices::colorRampPalette() kann eine beliebige Anzahl Farbtöne basierend auf einer statR-Farbpalette erstellt werden:

+
+#Mische 20 Farbtöne auf Basis der zhdiagonal-Palette
+display(grDevices::colorRampPalette((zhpal$zhdiagonal),space="Lab")(20))
+

+

Anwendungsbeispiel mit kategorialen Daten:

+
+#verwende die Paletten für kategoriale Daten mittels 'scale_fill_manual'
+ggplot(mpg, aes(class,fill = drv))+
+  geom_bar()+
+  theme_stat()+
+  scale_fill_manual(values=zhpal$zhblue)
+

+
+

+Barrierefreie Grafiken

+

Bei der Erstellung von Grafiken ist es besonders wichtig darauf zu achten, dass die Grafiken auch für Personen mit (Farb-)Sehschwächen und Sehbehinderungen interpretierbar sind. Um solche barrierefreie Grafiken zu erstellen, bieten sich im Allgemeinen verschiedene Strategien an:

+
    +
  • Daten, die der Grafik zugrunde liegen, zusätzlich als csv oder -html-Tabelle einbinden

  • +
  • Einen Alternativtext (alt-Text) hinterlegen, der beschreibt, was auf der Grafik abgebildet ist und wo die Daten zu finden sind

  • +
  • Farbpaletten wählen, die für Farbsehschwächen optimiert sind

  • +
  • Die Grafik soll nicht ausschliesslich aufgrund einer Farbpalette interpretierbar sein

  • +
  • Die Komplexität der Grafiken sollte auf ein Minimum beschränkt werden

  • +
+

Einige dieser Punkte können direkt bei der Erstellung der Grafiken in R berücksichtigt werden.

+
+

+1. Farbsehschwächen

+

Damit Grafiken auch für Personen mit Farbsehschwächen möglichst gut interpretierbar sind, sollten Farben in Grafiken sowohl bezüglich der Farbanteile als auch der Farbsättigung variiert werden. Wenn möglich, sollten unterschiedliche Datenkategorien zudem nicht nur über die Farben sondern auch über unterschiedliche Darstellungsformen unterscheidbar sein (z.B. Schraffuren, Punkt- oder Linientypen; siehe 1.3). Auch die direkte Beschriftung von Kategorien bietet sich hier als Mittel an (siehe 1.4).

+
+
+

+1.2 Auswahl Farbpaletten

+

In R können mit dem dichromat-Package diverse Ausprägungen von Farbsehschwäche simuliert werden. Dies erlaubt es Farbpaletten auszuwählen, die möglichst farbsehschwächenfreundlich sind.

+
+library(dichromat)
+# Anzeige der Farbpalette zhdiagonal
+display(zhpal$zhdiagonal)
+

+
+# Simulation Grünsehschwäche (Deuteranomalie)
+display(dichromat(zhpal$zhdiagonal))
+

+
+# Simulation Blaublindheit (Tritanopie)
+display(dichromat(zhpal$zhdiagonal,type="tritan"))
+

+

Die Simulation kann auch anhand von Grafiken vorgenommen werden.

+
+p <- ggplot(diamonds, aes(clarity, fill=cut)) + 
+  geom_bar(position = "stack", width= 0.5)
+
+p + theme_stat() +
+  scale_fill_manual(values=dichromat(zhpal$zhdiagonal, type=c("tritan")))
+

+
+
+

+1.3 Form- oder Linientypen

+

Wenn immer möglich sollten unterschiedliche Kategorien nicht nur mit unterschiedlichen Farben gekennzeichnet werden, sondern auch mit unterschiedlichen Schraffuren, Symbol- oder Linientypen (siehe: https://bbc.github.io/gel/components/infographics/#recommended-layout). Ja nach Grafiktyp eignen sich andere Ansätze:

+ +

Ab einer gewissen Anzahl an Kategorien, wird die Grafik unübersichtlich.

+

Beispiel : Liniengrafik

+
+data <- read.csv("https://www.web.statistik.zh.ch/ogd/data/ojuga/KANTON-ZUERICH_jugendstrafrechtspflege_geschlechter_verurteilungen.csv") %>% 
+  pivot_longer(cols=2:3)
+
+gg_ojuga <- ggplot(data, aes(Jahr, value ,color=name,linetype=name)) + 
+     geom_line()+
+     theme_stat()
+

Beispiel : Säulendiagramm

+
+ggplot(mpg, aes(class,fill = drv,linetype=drv))+
+  geom_bar(col ="black")+
+  theme_stat()+
+  scale_fill_manual(values=zhpal$zhblue)+
+  theme(legend.position="right", axis.text.x = element_text(angle=90,vjust = 0.5, hjust=0),
+        panel.grid.major = element_line(colour = "grey", size = 0.1),
+        panel.grid.minor = element_line(colour = "grey", size = 0.2))
+

+
+
+

+1.4 Direkte Beschriftung

+

Bei gewissen Grafiktypen kann die Unterscheidbarkeit von Kategorien auch durch direkte Beschriftung verbessert werden. Das ´ggrepel´-package verfügt über die notwendigen Funktionen. Beispielsweise sorgt es dafür, dass die Beschriftungen nicht überlappen.

+
+library(ggrepel)
+
+data <- read.csv("https://www.web.statistik.zh.ch/ogd/data/ojuga/KANTON-ZUERICH_jugendstrafrechtspflege_geschlechter_verurteilungen.csv") %>% 
+  pivot_longer(cols=2:3)
+
+ggplot(data, aes(Jahr, value ,color=name)) + 
+    geom_text_repel(data=data %>% filter(Jahr==max(Jahr)), aes(label=name), direction = "y") +
+     geom_line()+
+     theme_stat()+
+     guides(color="none")
+

+
+
+
+
+

+Grafiken fürs ZHWeb

+

Bei Grafiken, welche auf zh.ch Publiziert werden sollen, gilt es folgendes zu berücksichtigen:

+
    +
  • Maximale Bildgrösse 4000x4000
  • +
  • Grafik-Titel, Untertitel, Legende, Quelle und Alt-Text müssen direkt im CMS (Bild-Komponente) hinterlegt und nicht in die Grafik selber integriert werden
  • +
+
+
+ggplot(mpg, aes(class,fill = drv))+
+  geom_bar()+
+  theme_stat()+
+  scale_fill_manual(values=zhpal$zhblue)+
+  theme(legend.position="right", axis.text.x = element_text(angle=90,vjust = 0.5, hjust=0),
+        panel.grid.major = element_line(colour = "grey", size = 0.1),
+        panel.grid.minor = element_line(colour = "grey", size = 0.2))
+

+
+
+
+# ggsave(file = "zhweb_plot.png", width=18, height=8, unit="cm")
+
+
+ + + +
+ + + +
+ + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + diff --git a/docs/articles/Visualisierungen_files/anchor-sections-1.0/anchor-sections.css b/docs/articles/Visualisierungen_files/anchor-sections-1.0/anchor-sections.css new file mode 100644 index 0000000..07aee5f --- /dev/null +++ b/docs/articles/Visualisierungen_files/anchor-sections-1.0/anchor-sections.css @@ -0,0 +1,4 @@ +/* Styles for section anchors */ +a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} +a.anchor-section::before {content: '#';} +.hasAnchor:hover a.anchor-section {visibility: visible;} diff --git a/docs/articles/Visualisierungen_files/anchor-sections-1.0/anchor-sections.js b/docs/articles/Visualisierungen_files/anchor-sections-1.0/anchor-sections.js new file mode 100644 index 0000000..570f99a --- /dev/null +++ b/docs/articles/Visualisierungen_files/anchor-sections-1.0/anchor-sections.js @@ -0,0 +1,33 @@ +// Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. +document.addEventListener('DOMContentLoaded', function() { + // Do nothing if AnchorJS is used + if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { + return; + } + + const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); + + // Do nothing if sections are already anchored + if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { + return null; + } + + // Use section id when pandoc runs with --section-divs + const section_id = function(x) { + return ((x.classList.contains('section') || (x.tagName === 'SECTION')) + ? x.id : ''); + }; + + // Add anchors + h.forEach(function(x) { + const id = x.id || section_id(x.parentElement); + if (id === '') { + return null; + } + let anchor = document.createElement('a'); + anchor.href = '#' + id; + anchor.classList = ['anchor-section']; + x.classList.add('hasAnchor'); + x.appendChild(anchor); + }); +}); diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-10-1.png new file mode 100644 index 0000000..7e106ea Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-11-1.png new file mode 100644 index 0000000..ee401d6 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-11-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-2-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-2-1.png new file mode 100644 index 0000000..b0993d7 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-2-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-1.png new file mode 100644 index 0000000..415f299 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-2.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-2.png new file mode 100644 index 0000000..5f59d29 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-2.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-3.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-3.png new file mode 100644 index 0000000..169a742 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-3.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-4.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-4.png new file mode 100644 index 0000000..4ab6bbd Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-3-4.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 0000000..5f59d29 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-2.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-2.png new file mode 100644 index 0000000..1f95780 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-2.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-3.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-3.png new file mode 100644 index 0000000..595855b Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-4-3.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..4ab6bbd Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-1.png new file mode 100644 index 0000000..415f299 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-2.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-2.png new file mode 100644 index 0000000..1f95780 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-2.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-3.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-3.png new file mode 100644 index 0000000..595855b Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-6-3.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-7-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-7-1.png new file mode 100644 index 0000000..6d6f523 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-7-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-8-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-8-1.png new file mode 100644 index 0000000..f9f07be Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-8-1.png differ diff --git a/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-9-1.png b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-9-1.png new file mode 100644 index 0000000..4ba3172 Binary files /dev/null and b/docs/articles/Visualisierungen_files/figure-html/unnamed-chunk-9-1.png differ diff --git a/docs/articles/Visualisierungen_files/header-attrs-2.5/header-attrs.js b/docs/articles/Visualisierungen_files/header-attrs-2.5/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Visualisierungen_files/header-attrs-2.5/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/Visualisierungen_files/header-attrs-2.6/header-attrs.js b/docs/articles/Visualisierungen_files/header-attrs-2.6/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Visualisierungen_files/header-attrs-2.6/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/Visualisierungen_files/header-attrs-2.7/header-attrs.js b/docs/articles/Visualisierungen_files/header-attrs-2.7/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/Visualisierungen_files/header-attrs-2.7/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/excels_with_statr.html b/docs/articles/excels_with_statr.html new file mode 100644 index 0000000..6d29345 --- /dev/null +++ b/docs/articles/excels_with_statr.html @@ -0,0 +1,142 @@ + + + + + + + +excels_with_statr • statR + + + + + + + + + + + +
+
+ + + + +
+
+ + + + + +
+ + + +
+ + + +
+ + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + diff --git a/docs/articles/excels_with_statr_files/header-attrs-2.6/header-attrs.js b/docs/articles/excels_with_statr_files/header-attrs-2.6/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/excels_with_statr_files/header-attrs-2.6/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/html_report_template.html b/docs/articles/html_report_template.html new file mode 100644 index 0000000..5f15f9b --- /dev/null +++ b/docs/articles/html_report_template.html @@ -0,0 +1,153 @@ + + + + + + + +HTML Dokumente im ZH.CH-Design • statR + + + + + + + + + + + +
+
+ + + + +
+
+ + + + +

Alpha-Version

+

Das statR-Package enthält ein Template für html-Berichte, die dem kantonalen Corporate Design entsprechen.

+

Dieses ist in R Studio im Menü unter ‘File > New File > R Markdown’ verfügbar.

+
+

Auswahl des Templates

+
+

Im Auswahlfenster kann das ZH Report-Template ausgewählt werden.

+
+

zh-Report

+
+
+

sample zh-Report

+
+
+ + + +
+ + + +
+ + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + diff --git a/docs/articles/html_report_template_files/header-attrs-2.6/header-attrs.js b/docs/articles/html_report_template_files/header-attrs-2.6/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/html_report_template_files/header-attrs-2.6/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/html_report_template_files/header-attrs-2.7/header-attrs.js b/docs/articles/html_report_template_files/header-attrs-2.7/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/html_report_template_files/header-attrs-2.7/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/index.html b/docs/articles/index.html new file mode 100644 index 0000000..954227c --- /dev/null +++ b/docs/articles/index.html @@ -0,0 +1,182 @@ + + + + + + + + +Articles • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + + +
+
+ + +
+ + + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + + + diff --git a/docs/articles/output-datasetsXLSX-1.PNG b/docs/articles/output-datasetsXLSX-1.PNG new file mode 100644 index 0000000..cb83542 Binary files /dev/null and b/docs/articles/output-datasetsXLSX-1.PNG differ diff --git a/docs/articles/output-datasetsXLSX-2.PNG b/docs/articles/output-datasetsXLSX-2.PNG new file mode 100644 index 0000000..f678628 Binary files /dev/null and b/docs/articles/output-datasetsXLSX-2.PNG differ diff --git a/docs/articles/output-datasetsXLSX1.PNG b/docs/articles/output-datasetsXLSX1.PNG new file mode 100644 index 0000000..60adc2a Binary files /dev/null and b/docs/articles/output-datasetsXLSX1.PNG differ diff --git a/docs/articles/output-datasetsXLSX2.PNG b/docs/articles/output-datasetsXLSX2.PNG new file mode 100644 index 0000000..0ed33ec Binary files /dev/null and b/docs/articles/output-datasetsXLSX2.PNG differ diff --git a/docs/articles/output-quickXLSX.PNG b/docs/articles/output-quickXLSX.PNG new file mode 100644 index 0000000..7942bed Binary files /dev/null and b/docs/articles/output-quickXLSX.PNG differ diff --git a/docs/articles/output-splitXLSX.PNG b/docs/articles/output-splitXLSX.PNG new file mode 100644 index 0000000..c89f174 Binary files /dev/null and b/docs/articles/output-splitXLSX.PNG differ diff --git a/docs/articles/rmd_template.PNG b/docs/articles/rmd_template.PNG new file mode 100644 index 0000000..1e28ca5 Binary files /dev/null and b/docs/articles/rmd_template.PNG differ diff --git a/docs/articles/sample_report.PNG b/docs/articles/sample_report.PNG new file mode 100644 index 0000000..06c6be5 Binary files /dev/null and b/docs/articles/sample_report.PNG differ diff --git a/docs/articles/statR_intro.html b/docs/articles/statR_intro.html new file mode 100644 index 0000000..5907597 --- /dev/null +++ b/docs/articles/statR_intro.html @@ -0,0 +1,275 @@ + + + + + + + +Intro • statR + + + + + + + + + + + +
+
+ + + + +
+
+
+ + + + +

Das statR-package enthält:

+
    +
  • Das Stat ZH Theme (stat_theme()) für ggplot2 Grafiken
  • +
  • Farbpaletten (zhpal)
  • +
  • Farbpaletten-Funktionen für ggplot2
  • +
  • Funktionen um Datensätze aus R in formattierte und Kantons CD-konforme XLSX-files abzuspeichern.
  • +
+

Zu jeder Funktion ist mittels Hilfe-Befehl (?) eine Beschreibung sowie ein Verwendungsbeispiel aufrufbar (z.B.: ?splitXLSX )

+
+

+Installation

+

Die Development Version des Package liegt auf github und kann wiefolgt installiert werden.

+
+#Variante 1
+library(downloader)
+download("https://github.com/statistikZH/statR/archive/dev.tar.gz", "statR.tar.gz")
+install.packages("statR.tar.gz", repos = NULL, type = "source")
+
+#Variante 2
+library(devtools)
+
+devtools::install_github("statistikZH/statR",ref="dev")
+
+
+

+Theme

+

Das ggplot2-theme ist darauf ausgelegt, sich gut ins kantonalen Corporate Design einzufügen.

+
+#Lade package
+library(statR)
+library(ggplot2)
+
+ggplot(mpg, aes(class,fill = drv))+
+  geom_bar()+
+  theme_stat()
+

+
+
+

+Farben

+

Das Farbpalettenobjekt zhpal, welches alle StatZH-Farbpaletten enthält, ist mit geladenem statR Package global verfügbar.

+
+#Zeige Farben an
+display(zhpal$zhdiagonal)
+

+
+
+#Mische 20 Farbtöne auf Basis der zhdiagonal-Palette
+colorRampPalette((zhpal$zhdiagonal),space="Lab")(20)
+#>  [1] "#3F7A9F" "#418AA1" "#4099A3" "#46A79F" "#5AB08D" "#67B97A" "#8AC473"
+#>  [8] "#BAD076" "#E6DB78" "#EFCF7C" "#F2BF80" "#F4B184" "#F3AC92" "#F3A79F"
+#> [15] "#F1ACB0" "#EBBFC7" "#E2D0DF" "#C7BACE" "#A594AF" "#857091"
+
+#Zeige die 20 Farben an
+display(colorRampPalette((zhpal$zhdiagonal),space="Lab")(20))
+

+
+
+#Alle Paletten auf einen Blick
+display.statcol.all()
+

+
+
+#verwende die Paletten für kategoriale Daten mittels 'scale_fill_manual'
+ggplot(mpg, aes(class,fill = drv))+geom_bar()+theme_stat()+scale_fill_manual(values=zhpal$zhblue)
+

+
+
+

+Formattierte ZH Excel-Tabellen mit R

+

statR enthält zwei Funktionen welche Daten in formatierte Excel-Dateien abfüllen. Die Funktionen bauen auf dem openxlsx-package auf.

+

insert_worksheet

+

Schreibt Daten aus R in eine XLSX-Tabelle mit einem einzelnen Arbeitsblatt.

+
+
+#erstelle ein neues Workbook
+wb <- openxlsx::createWorkbook("hello")
+
+#schreibe daten in ein neues sheet im bestehenden Workbook
+insert_worksheet(mtcars[c(1:25),],wb)
+
+#speichere workbook als xlsx-Datei ab
+openxlsx::saveWorkbook(wb, "file.xlsx", overwrite = TRUE)
+

quickXLSX

+

Schreibt Daten aus R in eine XLSX-Tabelle mit einem einzelnen Arbeitsblatt.

+
+#Beschreibung & Anwendungsbeispiele via '?'
+?quickXLSX
+
+#Speichere die obersten Zeilen des mtcars-Datensatzes als formatiertes XLSX File ab
+quickXLSX(head(mtcars),"title of the spreadsheet")
+

splitXLSX

+

Die Funktion splitXLSX erlaubt es einen Datensatz aus R in einer XLSX-Tabelle mit mehreren Arbeitsblättern abzuspeichern und die Daten über mehrere Tabellenblätter zu verteilen.

+

Beispiel: Speichere die ersten 10 Zeilen des mtcars-Datemsatzes in mehreren Arbeitsblättern ab, ein Blatt pro Kategorie der ‘carb’-Variable. Die Funktion eignet sich für Excel-Files welche pro Jahr oder pro Region etc. jeweils einzelne Arbeitsblätter enthalten sollen.

+
+#Beispiel mit Standardlogo (Logo des Statistischen Amtes ZH)
+splitXLSX(mtcars[c(1:10),],"mtcars",carb,grouplines=c(1,5,6))
+
+#Beispiel mit modifzierten Bemerkungen und eigenem Logo
+splitXLSX(head(mtcars),carb, file="filename",grouplines = c(1,2,3), metadata = "remarks: ....",source="canton of zurich",logo="L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/nacht_map.png")
+

datasetsXLSX (NEU)

+

Die Funktion datasetsXLSX erlaubt es mehrere Datensätze aus R in einer XLSX-Tabelle mit mehreren Arbeitsblättern zu bündeln.

+

Beispiel mit zwei Datensätzen:

+
+
+datasetsXLSX(file="datasetsXLSX2"
+,maintitle = "nice datasets"
+,datasets = list(head(mtcars),tail(mtcars))
+,sheetnames = c("data1","data2")
+,titles = c("Title","Title")
+,sources = c("Quelle: STATENT", "Quelle: Strukturerhebung")
+,metadata1 = c("Bemerkungen: x", "Bemerkungen: x")
+,auftrag_id="AS2020_01"
+)
+

Tabellenblätter können auch Bilder oder Plots enthalten.

+
+
+plot <- plot(mtcars$mpg)
+
+datasetsXLSX(file="datasetsXLSX",
+            maintitle = "nice datasets",
+             datasets = list(head(mtcars),tail(mtcars),plot),
+            sheetnames = c("data1","data2","map"),
+            widths = c(0,0,5),
+             heights = c(0,0,2.5),
+             startrows = c(0,0,10),
+             startcols = c(0,0,8),
+             titles = c("Title","Title", "Plot"),
+             sources = c("Quelle: STATENT", "Quelle: Strukturerhebung", "Quelle: Strukturerhebung"),
+             metadata1 = c("Bemerkungen: bla", "Bemerkungen: x", "Bemerkungen: x"),
+             auftrag_id="A2020_0200"
+)
+
+
+ + + +
+ + + +
+ + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + diff --git a/docs/articles/statR_intro_files/anchor-sections-1.0/anchor-sections.css b/docs/articles/statR_intro_files/anchor-sections-1.0/anchor-sections.css new file mode 100644 index 0000000..07aee5f --- /dev/null +++ b/docs/articles/statR_intro_files/anchor-sections-1.0/anchor-sections.css @@ -0,0 +1,4 @@ +/* Styles for section anchors */ +a.anchor-section {margin-left: 10px; visibility: hidden; color: inherit;} +a.anchor-section::before {content: '#';} +.hasAnchor:hover a.anchor-section {visibility: visible;} diff --git a/docs/articles/statR_intro_files/anchor-sections-1.0/anchor-sections.js b/docs/articles/statR_intro_files/anchor-sections-1.0/anchor-sections.js new file mode 100644 index 0000000..570f99a --- /dev/null +++ b/docs/articles/statR_intro_files/anchor-sections-1.0/anchor-sections.js @@ -0,0 +1,33 @@ +// Anchor sections v1.0 written by Atsushi Yasumoto on Oct 3rd, 2020. +document.addEventListener('DOMContentLoaded', function() { + // Do nothing if AnchorJS is used + if (typeof window.anchors === 'object' && anchors.hasOwnProperty('hasAnchorJSLink')) { + return; + } + + const h = document.querySelectorAll('h1, h2, h3, h4, h5, h6'); + + // Do nothing if sections are already anchored + if (Array.from(h).some(x => x.classList.contains('hasAnchor'))) { + return null; + } + + // Use section id when pandoc runs with --section-divs + const section_id = function(x) { + return ((x.classList.contains('section') || (x.tagName === 'SECTION')) + ? x.id : ''); + }; + + // Add anchors + h.forEach(function(x) { + const id = x.id || section_id(x.parentElement); + if (id === '') { + return null; + } + let anchor = document.createElement('a'); + anchor.href = '#' + id; + anchor.classList = ['anchor-section']; + x.classList.add('hasAnchor'); + x.appendChild(anchor); + }); +}); diff --git a/docs/articles/statR_intro_files/figure-html/unnamed-chunk-4-1.png b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-4-1.png new file mode 100644 index 0000000..c740db7 Binary files /dev/null and b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-4-1.png differ diff --git a/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-1.png b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-1.png new file mode 100644 index 0000000..415f299 Binary files /dev/null and b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-1.png differ diff --git a/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-2.png b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-2.png new file mode 100644 index 0000000..5f59d29 Binary files /dev/null and b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-2.png differ diff --git a/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-3.png b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-3.png new file mode 100644 index 0000000..1b8969d Binary files /dev/null and b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-3.png differ diff --git a/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-4.png b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-4.png new file mode 100644 index 0000000..fd4ced7 Binary files /dev/null and b/docs/articles/statR_intro_files/figure-html/unnamed-chunk-5-4.png differ diff --git a/docs/articles/statR_intro_files/header-attrs-2.5/header-attrs.js b/docs/articles/statR_intro_files/header-attrs-2.5/header-attrs.js new file mode 100644 index 0000000..dd57d92 --- /dev/null +++ b/docs/articles/statR_intro_files/header-attrs-2.5/header-attrs.js @@ -0,0 +1,12 @@ +// Pandoc 2.9 adds attributes on both header and div. We remove the former (to +// be compatible with the behavior of Pandoc < 2.8). +document.addEventListener('DOMContentLoaded', function(e) { + var hs = document.querySelectorAll("div.section[class*='level'] > :first-child"); + var i, h, a; + for (i = 0; i < hs.length; i++) { + h = hs[i]; + if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6 + a = h.attributes; + while (a.length > 0) h.removeAttribute(a[0].name); + } +}); diff --git a/docs/articles/zh_report.PNG b/docs/articles/zh_report.PNG new file mode 100644 index 0000000..c30a3aa Binary files /dev/null and b/docs/articles/zh_report.PNG differ diff --git a/docs/articles/zhweb_plot.png b/docs/articles/zhweb_plot.png new file mode 100644 index 0000000..ec1bcf3 Binary files /dev/null and b/docs/articles/zhweb_plot.png differ diff --git a/docs/authors.html b/docs/authors.html new file mode 100644 index 0000000..7873278 --- /dev/null +++ b/docs/authors.html @@ -0,0 +1,184 @@ + + + + + + + + +Authors • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + + + +
+ +
+
+ + +
    +
  • +

    Andrea Schnell. Author. +

    +
  • +
  • +

    Thomas Lo Russo. Author, maintainer. +

    +
  • +
  • +

    Michelle Donzallaz. Contributor. +

    +
  • +
+ +
+ +
+ + + +
+ + + + +
+

Site built with pkgdown 1.6.1.

+
+ +
+
+ + + + + + + + diff --git a/docs/bootstrap-toc.css b/docs/bootstrap-toc.css new file mode 100644 index 0000000..5a85941 --- /dev/null +++ b/docs/bootstrap-toc.css @@ -0,0 +1,60 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ + +/* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ + +/* All levels of nav */ +nav[data-toggle='toc'] .nav > li > a { + display: block; + padding: 4px 20px; + font-size: 13px; + font-weight: 500; + color: #767676; +} +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 19px; + color: #563d7c; + text-decoration: none; + background-color: transparent; + border-left: 1px solid #563d7c; +} +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 18px; + font-weight: bold; + color: #563d7c; + background-color: transparent; + border-left: 2px solid #563d7c; +} + +/* Nav: second level (shown on .active) */ +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} +nav[data-toggle='toc'] .nav .nav > li > a { + padding-top: 1px; + padding-bottom: 1px; + padding-left: 30px; + font-size: 12px; + font-weight: normal; +} +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 29px; +} +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 28px; + font-weight: 500; +} + +/* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ +nav[data-toggle='toc'] .nav > .active > ul { + display: block; +} diff --git a/docs/bootstrap-toc.js b/docs/bootstrap-toc.js new file mode 100644 index 0000000..1cdd573 --- /dev/null +++ b/docs/bootstrap-toc.js @@ -0,0 +1,159 @@ +/*! + * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) + * Copyright 2015 Aidan Feldman + * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ +(function() { + 'use strict'; + + window.Toc = { + helpers: { + // return all matching elements in the set, or their descendants + findOrFilter: function($el, selector) { + // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ + // http://stackoverflow.com/a/12731439/358804 + var $descendants = $el.find(selector); + return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); + }, + + generateUniqueIdBase: function(el) { + var text = $(el).text(); + var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); + return anchor || el.tagName.toLowerCase(); + }, + + generateUniqueId: function(el) { + var anchorBase = this.generateUniqueIdBase(el); + for (var i = 0; ; i++) { + var anchor = anchorBase; + if (i > 0) { + // add suffix + anchor += '-' + i; + } + // check if ID already exists + if (!document.getElementById(anchor)) { + return anchor; + } + } + }, + + generateAnchor: function(el) { + if (el.id) { + return el.id; + } else { + var anchor = this.generateUniqueId(el); + el.id = anchor; + return anchor; + } + }, + + createNavList: function() { + return $(''); + }, + + createChildNavList: function($parent) { + var $childList = this.createNavList(); + $parent.append($childList); + return $childList; + }, + + generateNavEl: function(anchor, text) { + var $a = $(''); + $a.attr('href', '#' + anchor); + $a.text(text); + var $li = $('
  • '); + $li.append($a); + return $li; + }, + + generateNavItem: function(headingEl) { + var anchor = this.generateAnchor(headingEl); + var $heading = $(headingEl); + var text = $heading.data('toc-text') || $heading.text(); + return this.generateNavEl(anchor, text); + }, + + // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). + getTopLevel: function($scope) { + for (var i = 1; i <= 6; i++) { + var $headings = this.findOrFilter($scope, 'h' + i); + if ($headings.length > 1) { + return i; + } + } + + return 1; + }, + + // returns the elements for the top level, and the next below it + getHeadings: function($scope, topLevel) { + var topSelector = 'h' + topLevel; + + var secondaryLevel = topLevel + 1; + var secondarySelector = 'h' + secondaryLevel; + + return this.findOrFilter($scope, topSelector + ',' + secondarySelector); + }, + + getNavLevel: function(el) { + return parseInt(el.tagName.charAt(1), 10); + }, + + populateNav: function($topContext, topLevel, $headings) { + var $context = $topContext; + var $prevNav; + + var helpers = this; + $headings.each(function(i, el) { + var $newNav = helpers.generateNavItem(el); + var navLevel = helpers.getNavLevel(el); + + // determine the proper $context + if (navLevel === topLevel) { + // use top level + $context = $topContext; + } else if ($prevNav && $context === $topContext) { + // create a new level of the tree and switch to it + $context = helpers.createChildNavList($prevNav); + } // else use the current $context + + $context.append($newNav); + + $prevNav = $newNav; + }); + }, + + parseOps: function(arg) { + var opts; + if (arg.jquery) { + opts = { + $nav: arg + }; + } else { + opts = arg; + } + opts.$scope = opts.$scope || $(document.body); + return opts; + } + }, + + // accepts a jQuery object, or an options object + init: function(opts) { + opts = this.helpers.parseOps(opts); + + // ensure that the data attribute is in place for styling + opts.$nav.attr('data-toggle', 'toc'); + + var $topContext = this.helpers.createChildNavList(opts.$nav); + var topLevel = this.helpers.getTopLevel(opts.$scope); + var $headings = this.helpers.getHeadings(opts.$scope, topLevel); + this.helpers.populateNav($topContext, topLevel, $headings); + } + }; + + $(function() { + $('nav[data-toggle="toc"]').each(function(i, el) { + var $nav = $(el); + Toc.init($nav); + }); + }); +})(); diff --git a/docs/docsearch.css b/docs/docsearch.css new file mode 100644 index 0000000..e5f1fe1 --- /dev/null +++ b/docs/docsearch.css @@ -0,0 +1,148 @@ +/* Docsearch -------------------------------------------------------------- */ +/* + Source: https://github.com/algolia/docsearch/ + License: MIT +*/ + +.algolia-autocomplete { + display: block; + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1 +} + +.algolia-autocomplete .ds-dropdown-menu { + width: 100%; + min-width: none; + max-width: none; + padding: .75rem 0; + background-color: #fff; + background-clip: padding-box; + border: 1px solid rgba(0, 0, 0, .1); + box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .175); +} + +@media (min-width:768px) { + .algolia-autocomplete .ds-dropdown-menu { + width: 175% + } +} + +.algolia-autocomplete .ds-dropdown-menu::before { + display: none +} + +.algolia-autocomplete .ds-dropdown-menu [class^=ds-dataset-] { + padding: 0; + background-color: rgb(255,255,255); + border: 0; + max-height: 80vh; +} + +.algolia-autocomplete .ds-dropdown-menu .ds-suggestions { + margin-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion { + padding: 0; + overflow: visible +} + +.algolia-autocomplete .algolia-docsearch-suggestion--category-header { + padding: .125rem 1rem; + margin-top: 0; + font-size: 1.3em; + font-weight: 500; + color: #00008B; + border-bottom: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--wrapper { + float: none; + padding-top: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--subcategory-column { + float: none; + width: auto; + padding: 0; + text-align: left +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content { + float: none; + width: auto; + padding: 0 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--content::before { + display: none +} + +.algolia-autocomplete .ds-suggestion:not(:first-child) .algolia-docsearch-suggestion--category-header { + padding-top: .75rem; + margin-top: .75rem; + border-top: 1px solid rgba(0, 0, 0, .1) +} + +.algolia-autocomplete .ds-suggestion .algolia-docsearch-suggestion--subcategory-column { + display: block; + padding: .1rem 1rem; + margin-bottom: 0.1; + font-size: 1.0em; + font-weight: 400 + /* display: none */ +} + +.algolia-autocomplete .algolia-docsearch-suggestion--title { + display: block; + padding: .25rem 1rem; + margin-bottom: 0; + font-size: 0.9em; + font-weight: 400 +} + +.algolia-autocomplete .algolia-docsearch-suggestion--text { + padding: 0 1rem .5rem; + margin-top: -.25rem; + font-size: 0.8em; + font-weight: 400; + line-height: 1.25 +} + +.algolia-autocomplete .algolia-docsearch-footer { + width: 110px; + height: 20px; + z-index: 3; + margin-top: 10.66667px; + float: right; + font-size: 0; + line-height: 0; +} + +.algolia-autocomplete .algolia-docsearch-footer--logo { + background-image: url("data:image/svg+xml;utf8,"); + background-repeat: no-repeat; + background-position: 50%; + background-size: 100%; + overflow: hidden; + text-indent: -9000px; + width: 100%; + height: 100%; + display: block; + transform: translate(-8px); +} + +.algolia-autocomplete .algolia-docsearch-suggestion--highlight { + color: #FF8C00; + background: rgba(232, 189, 54, 0.1) +} + + +.algolia-autocomplete .algolia-docsearch-suggestion--text .algolia-docsearch-suggestion--highlight { + box-shadow: inset 0 -2px 0 0 rgba(105, 105, 105, .5) +} + +.algolia-autocomplete .ds-suggestion.ds-cursor .algolia-docsearch-suggestion--content { + background-color: rgba(192, 192, 192, .15) +} diff --git a/docs/docsearch.js b/docs/docsearch.js new file mode 100644 index 0000000..b35504c --- /dev/null +++ b/docs/docsearch.js @@ -0,0 +1,85 @@ +$(function() { + + // register a handler to move the focus to the search bar + // upon pressing shift + "/" (i.e. "?") + $(document).on('keydown', function(e) { + if (e.shiftKey && e.keyCode == 191) { + e.preventDefault(); + $("#search-input").focus(); + } + }); + + $(document).ready(function() { + // do keyword highlighting + /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ + var mark = function() { + + var referrer = document.URL ; + var paramKey = "q" ; + + if (referrer.indexOf("?") !== -1) { + var qs = referrer.substr(referrer.indexOf('?') + 1); + var qs_noanchor = qs.split('#')[0]; + var qsa = qs_noanchor.split('&'); + var keyword = ""; + + for (var i = 0; i < qsa.length; i++) { + var currentParam = qsa[i].split('='); + + if (currentParam.length !== 2) { + continue; + } + + if (currentParam[0] == paramKey) { + keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); + } + } + + if (keyword !== "") { + $(".contents").unmark({ + done: function() { + $(".contents").mark(keyword); + } + }); + } + } + }; + + mark(); + }); +}); + +/* Search term highlighting ------------------------------*/ + +function matchedWords(hit) { + var words = []; + + var hierarchy = hit._highlightResult.hierarchy; + // loop to fetch from lvl0, lvl1, etc. + for (var idx in hierarchy) { + words = words.concat(hierarchy[idx].matchedWords); + } + + var content = hit._highlightResult.content; + if (content) { + words = words.concat(content.matchedWords); + } + + // return unique words + var words_uniq = [...new Set(words)]; + return words_uniq; +} + +function updateHitURL(hit) { + + var words = matchedWords(hit); + var url = ""; + + if (hit.anchor) { + url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; + } else { + url = hit.url + '?q=' + escape(words.join(" ")); + } + + return url; +} diff --git a/docs/extra.css b/docs/extra.css new file mode 100644 index 0000000..db693d2 --- /dev/null +++ b/docs/extra.css @@ -0,0 +1,148 @@ +@import url('https://fonts.googleapis.com/css?family=Raleway|Ubuntu+Mono'); + +h1, h2, h3, h4 { + font-family: HelveticaNowBlack,"Arial Black",Helvetica,sans-serif; + color: #000; + } + + +*{ + font-family: HelveticaNowRegular, Helvetica, sans-serif; +} + +body { + font-size: 16px; + line-height: 1.5; + position: relative; + text-decoration: none; + } + +code{ + font-family: 'Ubuntu Mono', monospace; +} + +p>a { + color: #66c4ff; +} + +li>a { + color: #66c4ff; +} + +.sourceCode>a{ + color: #293c55; +} + +.st{ + color: #B03A5B; +} + +.op{ + color: #666666; +} + +.dv, .dt{ + color: #191919; +} + +.btn-copy-ex{ + background-color: #B03A5B; + border-color: #293c55; +} + +.btn-copy-ex:hover{ + background-color: #293c55; + border-color: #B03A5B; +} + + +pre { + box-shadow: + rgba(0, 0, 0, 0.1) 0 2px 3px 1px, + rgba(0, 0, 0, 0.1) 0 1px 3px 1px, + rgba(0, 0, 0, 0.2) 0 1px 1px -1px; +} + +.navbar-default{ + border-color: #293c55; + background-color: #0076be; +} + +.navbar-default .navbar-nav>li>a { + color:#fff; +} + +.navbar-default .navbar-link { + color:#fff +} + +.label-default { + background-color: #293c55; +} + +.navbar-default .navbar-nav > .active > a, +.navbar-default .navbar-nav > .active > a:hover, +.navbar-default .navbar-nav > .active > a:focus { + color: #66c4ff; + background-color: #293c55; +} + +.navbar-default .navbar-nav > li > a:hover, +.navbar-default .navbar-nav > li > a:focus { + color: #66c4ff; +} + + .navbar-default .navbar-nav .open .dropdown-menu>li>a, .navbar-default .navbar-nav .open .dropdown-menu { + border-color: #FFFFFF; + background-color: #293c55; + color : #66c4ff; +} + + +.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { + color: #293c55; + background-color: #66c4ff; +} + +.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:hover, .navbar-default .navbar-nav > .open > a:focus { + + background-color: #293c55; + color: #ffffff; + +} + +.navbar-default .navbar-nav > .dropdown > a .caret { + color: #999999; +} +.navbar-default .navbar-nav > .dropdown > a:hover .caret, +.navbar-default .navbar-nav > .dropdown > a:focus .caret { + color: #B03A5B; +} + +.navbar-default .navbar-nav>.open>a, +.navbar-default .navbar-nav>.open>a:hover, +.navbar-default .navbar-nav>.open>a:focus{ + color: #d8d8d8; +} + +.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover, +.navbar-default .navbar-nav .open .dropdown-menu{ + color: #dce6f2; +} + +.nav-pills>li.active>a, +.nav-pills>li.active>a:hover, +.nav-pills>li.active>a:focus { + color: #FFFFFF; + background-color: #435b7b; +} + +a:hover, a:focus { + color: #293c55; +} + +/*fix to move article titles below nav bar*/ + +.contents .page-header { + margin-top: calc(60px + 1em); +} diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..31fc4b4 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,183 @@ + + + + + + + +statR • statR + + + + + + + + + + + +
    +
    + + + + +
    +
    + +
    + +

    +

    +

    +

    Mit dem statR-Package können mit dem Corporate Design des Kantons Zürich konforme Visualisierungen, Excel-Tabellen und Html-Berichte in R erstellt werden. Das Package beinhaltet:

    +
      +
    • Funktionen, mit denen Datensätze aus R als XLSX-Datei abgespeichert werden können (inkl. Quellenangaben und weiteren Zusatzinformationen).

    • +
    • generische Farbpaletten für Datenvisualisierungen

    • +
    • ein ggplot2 theme

    • +
    • ein Template für Html-Berichte

    • +
    +
    + + +
    + + +
    + + +
    + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + diff --git a/docs/link.svg b/docs/link.svg new file mode 100644 index 0000000..88ad827 --- /dev/null +++ b/docs/link.svg @@ -0,0 +1,12 @@ + + + + + + diff --git a/docs/news/index.html b/docs/news/index.html new file mode 100644 index 0000000..e635b88 --- /dev/null +++ b/docs/news/index.html @@ -0,0 +1,189 @@ + + + + + + + + +Changelog • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    +statR 2.0.0

    +
      +
    • An R Markdown template ZH report for .html-reports is now available.
      +
    • +
    • New function datasetsXLSX(): several datasets and/or figures can now be exported from R to a single .xlsx-file. The function creates an overview sheet and separate sheets for each dataset/figure.
    • +
    • Additional function arguments for quickXLSX(), splitXLSX(), and datasetsXLSX() have been implemented, for example the author’s initials and individual contact details can be specified and the logo of the canton of Zurich can be added.
    • +
    • The column widths in the output of quickXLSX(), splitXLSX(), and datasetsXLSX() are set automatically and the first row no longer freezes.
    • +
    • The documentation has been extended.
    • +
    • +theme_stat() has been revised and a couple of theme arguments have been added for increased flexibility (e.g., axis ticks, position of axis labels)
    • +
    +
    +
    + + + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/pkgdown.css b/docs/pkgdown.css new file mode 100644 index 0000000..1273238 --- /dev/null +++ b/docs/pkgdown.css @@ -0,0 +1,367 @@ +/* Sticky footer */ + +/** + * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ + * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css + * + * .Site -> body > .container + * .Site-content -> body > .container .row + * .footer -> footer + * + * Key idea seems to be to ensure that .container and __all its parents__ + * have height set to 100% + * + */ + +html, body { + height: 100%; +} + +body { + position: relative; +} + +body > .container { + display: flex; + height: 100%; + flex-direction: column; +} + +body > .container .row { + flex: 1 0 auto; +} + +footer { + margin-top: 45px; + padding: 35px 0 36px; + border-top: 1px solid #e5e5e5; + color: #666; + display: flex; + flex-shrink: 0; +} +footer p { + margin-bottom: 0; +} +footer div { + flex: 1; +} +footer .pkgdown { + text-align: right; +} +footer p { + margin-bottom: 0; +} + +img.icon { + float: right; +} + +img { + max-width: 100%; +} + +/* Fix bug in bootstrap (only seen in firefox) */ +summary { + display: list-item; +} + +/* Typographic tweaking ---------------------------------*/ + +.contents .page-header { + margin-top: calc(-60px + 1em); +} + +dd { + margin-left: 3em; +} + +/* Section anchors ---------------------------------*/ + +a.anchor { + margin-left: -30px; + display:inline-block; + width: 30px; + height: 30px; + visibility: hidden; + + background-image: url(./link.svg); + background-repeat: no-repeat; + background-size: 20px 20px; + background-position: center center; +} + +.hasAnchor:hover a.anchor { + visibility: visible; +} + +@media (max-width: 767px) { + .hasAnchor:hover a.anchor { + visibility: hidden; + } +} + + +/* Fixes for fixed navbar --------------------------*/ + +.contents h1, .contents h2, .contents h3, .contents h4 { + padding-top: 60px; + margin-top: -40px; +} + +/* Navbar submenu --------------------------*/ + +.dropdown-submenu { + position: relative; +} + +.dropdown-submenu>.dropdown-menu { + top: 0; + left: 100%; + margin-top: -6px; + margin-left: -1px; + border-radius: 0 6px 6px 6px; +} + +.dropdown-submenu:hover>.dropdown-menu { + display: block; +} + +.dropdown-submenu>a:after { + display: block; + content: " "; + float: right; + width: 0; + height: 0; + border-color: transparent; + border-style: solid; + border-width: 5px 0 5px 5px; + border-left-color: #cccccc; + margin-top: 5px; + margin-right: -10px; +} + +.dropdown-submenu:hover>a:after { + border-left-color: #ffffff; +} + +.dropdown-submenu.pull-left { + float: none; +} + +.dropdown-submenu.pull-left>.dropdown-menu { + left: -100%; + margin-left: 10px; + border-radius: 6px 0 6px 6px; +} + +/* Sidebar --------------------------*/ + +#pkgdown-sidebar { + margin-top: 30px; + position: -webkit-sticky; + position: sticky; + top: 70px; +} + +#pkgdown-sidebar h2 { + font-size: 1.5em; + margin-top: 1em; +} + +#pkgdown-sidebar h2:first-child { + margin-top: 0; +} + +#pkgdown-sidebar .list-unstyled li { + margin-bottom: 0.5em; +} + +/* bootstrap-toc tweaks ------------------------------------------------------*/ + +/* All levels of nav */ + +nav[data-toggle='toc'] .nav > li > a { + padding: 4px 20px 4px 6px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; +} + +nav[data-toggle='toc'] .nav > li > a:hover, +nav[data-toggle='toc'] .nav > li > a:focus { + padding-left: 5px; + color: inherit; + border-left: 1px solid #878787; +} + +nav[data-toggle='toc'] .nav > .active > a, +nav[data-toggle='toc'] .nav > .active:hover > a, +nav[data-toggle='toc'] .nav > .active:focus > a { + padding-left: 5px; + font-size: 1.5rem; + font-weight: 400; + color: inherit; + border-left: 2px solid #878787; +} + +/* Nav: second level (shown on .active) */ + +nav[data-toggle='toc'] .nav .nav { + display: none; /* Hide by default, but at >768px, show it */ + padding-bottom: 10px; +} + +nav[data-toggle='toc'] .nav .nav > li > a { + padding-left: 16px; + font-size: 1.35rem; +} + +nav[data-toggle='toc'] .nav .nav > li > a:hover, +nav[data-toggle='toc'] .nav .nav > li > a:focus { + padding-left: 15px; +} + +nav[data-toggle='toc'] .nav .nav > .active > a, +nav[data-toggle='toc'] .nav .nav > .active:hover > a, +nav[data-toggle='toc'] .nav .nav > .active:focus > a { + padding-left: 15px; + font-weight: 500; + font-size: 1.35rem; +} + +/* orcid ------------------------------------------------------------------- */ + +.orcid { + font-size: 16px; + color: #A6CE39; + /* margins are required by official ORCID trademark and display guidelines */ + margin-left:4px; + margin-right:4px; + vertical-align: middle; +} + +/* Reference index & topics ----------------------------------------------- */ + +.ref-index th {font-weight: normal;} + +.ref-index td {vertical-align: top; min-width: 100px} +.ref-index .icon {width: 40px;} +.ref-index .alias {width: 40%;} +.ref-index-icons .alias {width: calc(40% - 40px);} +.ref-index .title {width: 60%;} + +.ref-arguments th {text-align: right; padding-right: 10px;} +.ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} +.ref-arguments .name {width: 20%;} +.ref-arguments .desc {width: 80%;} + +/* Nice scrolling for wide elements --------------------------------------- */ + +table { + display: block; + overflow: auto; +} + +/* Syntax highlighting ---------------------------------------------------- */ + +pre { + word-wrap: normal; + word-break: normal; + border: 1px solid #eee; +} + +pre, code { + background-color: #f8f8f8; + color: #333; +} + +pre code { + overflow: auto; + word-wrap: normal; + white-space: pre; +} + +pre .img { + margin: 5px 0; +} + +pre .img img { + background-color: #fff; + display: block; + height: auto; +} + +code a, pre a { + color: #375f84; +} + +a.sourceLine:hover { + text-decoration: none; +} + +.fl {color: #1514b5;} +.fu {color: #000000;} /* function */ +.ch,.st {color: #036a07;} /* string */ +.kw {color: #264D66;} /* keyword */ +.co {color: #888888;} /* comment */ + +.message { color: black; font-weight: bolder;} +.error { color: orange; font-weight: bolder;} +.warning { color: #6A0366; font-weight: bolder;} + +/* Clipboard --------------------------*/ + +.hasCopyButton { + position: relative; +} + +.btn-copy-ex { + position: absolute; + right: 0; + top: 0; + visibility: hidden; +} + +.hasCopyButton:hover button.btn-copy-ex { + visibility: visible; +} + +/* headroom.js ------------------------ */ + +.headroom { + will-change: transform; + transition: transform 200ms linear; +} +.headroom--pinned { + transform: translateY(0%); +} +.headroom--unpinned { + transform: translateY(-100%); +} + +/* mark.js ----------------------------*/ + +mark { + background-color: rgba(255, 255, 51, 0.5); + border-bottom: 2px solid rgba(255, 153, 51, 0.3); + padding: 1px; +} + +/* vertical spacing after htmlwidgets */ +.html-widget { + margin-bottom: 10px; +} + +/* fontawesome ------------------------ */ + +.fab { + font-family: "Font Awesome 5 Brands" !important; +} + +/* don't display links in code chunks when printing */ +/* source: https://stackoverflow.com/a/10781533 */ +@media print { + code a:link:after, code a:visited:after { + content: ""; + } +} diff --git a/docs/pkgdown.js b/docs/pkgdown.js new file mode 100644 index 0000000..7e7048f --- /dev/null +++ b/docs/pkgdown.js @@ -0,0 +1,108 @@ +/* http://gregfranko.com/blog/jquery-best-practices/ */ +(function($) { + $(function() { + + $('.navbar-fixed-top').headroom(); + + $('body').css('padding-top', $('.navbar').height() + 10); + $(window).resize(function(){ + $('body').css('padding-top', $('.navbar').height() + 10); + }); + + $('[data-toggle="tooltip"]').tooltip(); + + var cur_path = paths(location.pathname); + var links = $("#navbar ul li a"); + var max_length = -1; + var pos = -1; + for (var i = 0; i < links.length; i++) { + if (links[i].getAttribute("href") === "#") + continue; + // Ignore external links + if (links[i].host !== location.host) + continue; + + var nav_path = paths(links[i].pathname); + + var length = prefix_length(nav_path, cur_path); + if (length > max_length) { + max_length = length; + pos = i; + } + } + + // Add class to parent
  • , and enclosing
  • if in dropdown + if (pos >= 0) { + var menu_anchor = $(links[pos]); + menu_anchor.parent().addClass("active"); + menu_anchor.closest("li.dropdown").addClass("active"); + } + }); + + function paths(pathname) { + var pieces = pathname.split("/"); + pieces.shift(); // always starts with / + + var end = pieces[pieces.length - 1]; + if (end === "index.html" || end === "") + pieces.pop(); + return(pieces); + } + + // Returns -1 if not found + function prefix_length(needle, haystack) { + if (needle.length > haystack.length) + return(-1); + + // Special case for length-0 haystack, since for loop won't run + if (haystack.length === 0) { + return(needle.length === 0 ? 0 : -1); + } + + for (var i = 0; i < haystack.length; i++) { + if (needle[i] != haystack[i]) + return(i); + } + + return(haystack.length); + } + + /* Clipboard --------------------------*/ + + function changeTooltipMessage(element, msg) { + var tooltipOriginalTitle=element.getAttribute('data-original-title'); + element.setAttribute('data-original-title', msg); + $(element).tooltip('show'); + element.setAttribute('data-original-title', tooltipOriginalTitle); + } + + if(ClipboardJS.isSupported()) { + $(document).ready(function() { + var copyButton = ""; + + $(".examples, div.sourceCode").addClass("hasCopyButton"); + + // Insert copy buttons: + $(copyButton).prependTo(".hasCopyButton"); + + // Initialize tooltips: + $('.btn-copy-ex').tooltip({container: 'body'}); + + // Initialize clipboard: + var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { + text: function(trigger) { + return trigger.parentNode.textContent; + } + }); + + clipboardBtnCopies.on('success', function(e) { + changeTooltipMessage(e.trigger, 'Copied!'); + e.clearSelection(); + }); + + clipboardBtnCopies.on('error', function() { + changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); + }); + }); + } +})(window.jQuery || window.$) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml new file mode 100644 index 0000000..2f82bff --- /dev/null +++ b/docs/pkgdown.yml @@ -0,0 +1,10 @@ +pandoc: 2.11.4 +pkgdown: 1.6.1 +pkgdown_sha: ~ +articles: + Excel-Tabellen: Excel-Tabellen.html + Sonstige_Funktionen: Sonstige_Funktionen.html + Visualisierungen: Visualisierungen.html + html_report_template: html_report_template.html +last_built: 2021-06-04T12:35Z + diff --git a/docs/reference/Rplot001.png b/docs/reference/Rplot001.png new file mode 100644 index 0000000..17a3580 Binary files /dev/null and b/docs/reference/Rplot001.png differ diff --git a/docs/reference/Rplot002.png b/docs/reference/Rplot002.png new file mode 100644 index 0000000..09549b1 Binary files /dev/null and b/docs/reference/Rplot002.png differ diff --git a/docs/reference/datasetsXLSX-1.png b/docs/reference/datasetsXLSX-1.png new file mode 100644 index 0000000..d4e6ae2 Binary files /dev/null and b/docs/reference/datasetsXLSX-1.png differ diff --git a/docs/reference/datasetsXLSX.html b/docs/reference/datasetsXLSX.html new file mode 100644 index 0000000..3f14300 --- /dev/null +++ b/docs/reference/datasetsXLSX.html @@ -0,0 +1,330 @@ + + + + + + + + +datasetsXLSX() — datasetsXLSX • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to export several datasets and/or figures from R to an .xlsx-file. The function creates an overview sheet and separate sheets +for each dataset/figure.

    +
    + +
    datasetsXLSX(
    +  file,
    +  maintitle,
    +  datasets,
    +  widths = NULL,
    +  heights = NULL,
    +  startrows = NULL,
    +  startcols = NULL,
    +  sheetnames,
    +  titles,
    +  logo = "statzh",
    +  titlesource = "statzh",
    +  sources = "statzh",
    +  metadata1 = NA,
    +  auftrag_id = NULL,
    +  contact = "statzh",
    +  homepage = "statzh",
    +  openinghours = "statzh"
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    file

    file name of the spreadsheet. The extension ".xlsx" is added automatically.

    maintitle

    Title to be put on the first (overview) sheet.

    datasets

    datasets or plots to be included.

    widths

    width of figure in inch (1 inch = 2.54 cm). See details.

    heights

    height of figure in inch (1 inch = 2.54 cm). See details.

    startrows

    row where upper left corner of figure should be placed. See details.

    startcols

    column where upper left corner of figure should be placed. See details.

    sheetnames

    names of the sheet tabs.

    titles

    titles of the different sheets.

    logo

    file path to the logo to be included in the index-sheet. Can be "statzh" or "zh". Defaults to "statzh".

    titlesource

    source to be mentioned on the title sheet beneath the title

    sources

    source of the data. Defaults to "statzh".

    metadata1

    metadata information to be included. Defaults to NA.

    auftrag_id

    order number.

    contact

    contact information on the title sheet. Defaults to "statzh"

    homepage

    web address to be put on the title sheet. Default to "statzh"

    openinghours

    openinghours written on the title sheet. Defaults to Data Shop

    + +

    Details

    + +

    When including figures, the heights and widths need to be specified as a vector. For example, say you have two datasets and one figure +that you would like to export. widths = c(0,0,5) then suggests that the figure will be 5 inches wide and placed in the third (and last) sheet of the file. +The same logic applies to the specification of `startrows` and `startcols`. +To include a ggplot2-plot, put a print statement around the ggplot2-object: list(..., ..., print(plot)).

    + +

    Examples

    +
    # \donttest{ +if (FALSE) { + + +# Example with two datasets and no figure +dat1 <- mtcars +dat2 <- PlantGrowth + +datasetsXLSX(file="twoDatasets", # '.xlsx' wird automatisch hinzugefügt + maintitle = "Autos und Pflanzen", + datasets = list(dat1, dat2), + logo = "statzh", + sheetnames = c("Autos","Blumen"), + titles = c("mtcars-Datensatz","PlantGrowth-Datensatz"), + sources = c("Source: Henderson and Velleman (1981). + Building multiple regression models interactively. Biometrics, 37, 391–411.", + "Dobson, A. J. (1983) An Introduction to Statistical + Modelling. London: Chapman and Hall."), + metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", + "Bemerkungen zum PlantGrowth-Datensatz: x"), + auftrag_id="A2021_0000") + +# Example with two datasets and one figure + +dat1 <- mtcars +dat2 <- PlantGrowth +fig <- hist(mtcars$disp) + +datasetsXLSX(file="twoDatasetsandFigure", + maintitle = "Autos und Pflanzen", # '.xlsx' wird automatisch hinzugefügt + datasets = list(dat1, dat2, fig), + widths = c(0,0,5), + heights = c(0,0,5), + startrows = c(0,0,3), + startcols = c(0,0,3), + sheetnames = c("Autos","Blumen", "Histogramm"), + titles = c("mtcars-Datensatz","PlantGrowth-Datensatz", "Histogramm"), + sources = c("Source: Henderson and Velleman (1981). + Building multiple regression models interactively. Biometrics, 37, 391–411.", + "Source: Dobson, A. J. (1983) An Introduction to + Statistical Modelling. London: Chapman and Hall."), + metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", + "Bemerkungen zum PlantGrowth-Datensatz: x"), + auftrag_id="A2021_0000") +} +# } +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/display-1.png b/docs/reference/display-1.png new file mode 100644 index 0000000..a183a70 Binary files /dev/null and b/docs/reference/display-1.png differ diff --git a/docs/reference/display-2.png b/docs/reference/display-2.png new file mode 100644 index 0000000..c4d0882 Binary files /dev/null and b/docs/reference/display-2.png differ diff --git a/docs/reference/display.html b/docs/reference/display.html new file mode 100644 index 0000000..e44e161 --- /dev/null +++ b/docs/reference/display.html @@ -0,0 +1,206 @@ + + + + + + + + +display() — display • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    preview colors in console

    +
    + +
    display(col, border = "light gray", ...)
    + +

    Arguments

    + + + + + + + + + + + + + + +
    col

    a vector of hex-code colors to be displayed

    border

    border color

    ...

    further arguments that can be passed to the plot()-function

    + + +

    Examples

    +
    #display can be used to preview all the palettes included in the 'zhpal'-list: +display(zhpal$zhdiagonal) +
    #example with a single hex-code +display("#000000") +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/display.statcol.all-1.png b/docs/reference/display.statcol.all-1.png new file mode 100644 index 0000000..69251e1 Binary files /dev/null and b/docs/reference/display.statcol.all-1.png differ diff --git a/docs/reference/display.statcol.all.html b/docs/reference/display.statcol.all.html new file mode 100644 index 0000000..d5f4066 --- /dev/null +++ b/docs/reference/display.statcol.all.html @@ -0,0 +1,188 @@ + + + + + + + + +display.statcol.all() — display.statcol.all • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Preview all Stat ZH palettes stored in the 'zhpal'-object

    +
    + +
    display.statcol.all()
    + + + +

    Examples

    +
    display.statcol.all() +
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/data/Stempel_STAT-01.png b/docs/reference/figures/Stempel_STAT-01.png similarity index 100% rename from data/Stempel_STAT-01.png rename to docs/reference/figures/Stempel_STAT-01.png diff --git a/docs/reference/flush_left.html b/docs/reference/flush_left.html new file mode 100644 index 0000000..f51171f --- /dev/null +++ b/docs/reference/flush_left.html @@ -0,0 +1,199 @@ + + + + + + + + +flush_left — flush_left • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to flush title, subtitle and caption to the lefthand side of the graphics device

    +
    + +
    flush_left(g)
    + +

    Arguments

    + + + + + + +
    g

    ggplot object

    + + +

    Examples

    +
    if (FALSE) { +flush_left(ggplot(mtcars, aes( x = cyl))+ +geom_bar()+ +labs(title = "Titel", subtitle = "Untertitel", caption = "Datenquelle")) +} +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/index.html b/docs/reference/index.html new file mode 100644 index 0000000..3ca9abe --- /dev/null +++ b/docs/reference/index.html @@ -0,0 +1,262 @@ + + + + + + + + +Function reference • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +

    All functions

    +

    +
    +

    datasetsXLSX()

    +

    datasetsXLSX()

    +

    display()

    +

    display()

    +

    display.statcol.all()

    +

    display.statcol.all()

    +

    flush_left()

    +

    flush_left

    +

    insert_worksheet()

    +

    insert_worksheet()

    +

    interpolate2()

    +

    interpolate2()

    +

    quickXLSX()

    +

    quickXLSX()

    +

    quick_sum()

    +

    quick_sum()

    +

    splitXLSX()

    +

    splitXLSX()

    +

    theme_stat()

    +

    theme_stat()

    +

    zhpal

    +

    Data used by the stat zh palettes

    +
    + + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/insert_worksheet.html b/docs/reference/insert_worksheet.html new file mode 100644 index 0000000..3e7b82f --- /dev/null +++ b/docs/reference/insert_worksheet.html @@ -0,0 +1,246 @@ + + + + + + + + +insert_worksheet() — insert_worksheet • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to add formatted worksheets to an existing .xlsx-workbook.

    +
    + +
    insert_worksheet(
    +  data,
    +  workbook,
    +  sheetname = "data",
    +  title = "Title",
    +  source = "statzh",
    +  metadata = NA,
    +  logo = "statzh",
    +  grouplines = FALSE,
    +  contactdetails = "statzh",
    +  author = "user"
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    data to be included.

    workbook

    workbook object to add new worksheet to.

    sheetname

    name of the sheet tab.

    title

    title to be put above the data.

    source

    source of the data. Defaults to "statzh".

    metadata

    metadata information to be included. Defaults to NA.

    logo

    path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh"

    grouplines

    defaults to FALSE. Can be used to separate grouped variables visually.

    contactdetails

    contact details of the data publisher. Defaults to "statzh".

    author

    defaults to the last two letters (initials) or numbers of the internal user name.

    + + +

    Examples

    +
    +# Generation of a spreadsheet +wb <- openxlsx::createWorkbook("hello") + +insert_worksheet(data = mtcars[c(1:10),], workbook = wb, title = "mtcars", sheetname = "carb") +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/insert_worksheet_image-1.png b/docs/reference/insert_worksheet_image-1.png new file mode 100644 index 0000000..610722f Binary files /dev/null and b/docs/reference/insert_worksheet_image-1.png differ diff --git a/docs/reference/insert_worksheet_image.html b/docs/reference/insert_worksheet_image.html new file mode 100644 index 0000000..f4cf923 --- /dev/null +++ b/docs/reference/insert_worksheet_image.html @@ -0,0 +1,235 @@ + + + + + + + + +insert_image — insert_worksheet_image • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    insert_image

    +
    + +
    insert_worksheet_image(
    +  image,
    +  workbook,
    +  sheetname,
    +  startrow,
    +  startcol,
    +  width,
    +  height
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    image

    image or plot

    workbook

    workbook object to write new worksheet in

    sheetname

    name of the sheet tab

    startrow

    row coordinate of upper left corner of figure

    startcol

    column coordinate of upper left corner of figure

    width

    width of figure

    height

    height of figure

    + + +

    Examples

    +
    # example +if (FALSE) { +export <- openxlsx::createWorkbook("export") + +insert_worksheet_image(image=plot(x = mtcars$wt, y = mtcars$mpg), + export, + "image", + startrow=2, + startcol=2, + width=3.5, + height=5.5 +) +openxlsx::saveWorkbook(export,"insert_worksheet_image.xlsx") + +} +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/insert_worksheet_nh.html b/docs/reference/insert_worksheet_nh.html new file mode 100644 index 0000000..aa11e7b --- /dev/null +++ b/docs/reference/insert_worksheet_nh.html @@ -0,0 +1,249 @@ + + + + + + + + +insert_worksheet_nh — insert_worksheet_nh • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to create formatted spreadsheets automatically

    +
    + +
    insert_worksheet_nh(
    +  data,
    +  workbook,
    +  sheetname = "data",
    +  title = "Title",
    +  source = "Quelle: Statistisches Amt Kanton Zürich",
    +  metadata = NA,
    +  grouplines = FALSE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    data to be included in the XLSX-table.

    workbook

    workbook object to write new worksheet in.

    sheetname

    name of the sheet-tab.

    title

    title of the table and the sheet

    source

    source of the data. Defaults to "statzh".

    metadata

    metadata-information to be included. Defaults to NA.

    grouplines

    defaults to FALSE. Can be used to separate grouped variables visually.

    + + +

    Examples

    +
    # insertion of two worksheets in a existing workbook + + # create workbook +wb <- openxlsx::createWorkbook("hello") + +insert_worksheet_nh(mtcars[c(1:10),],wb,"mtcars",c(1:4),"carb",grouplines=c(1,5,6)) + + # create workbook +export <- openxlsx::createWorkbook("export") + +# insert a new worksheet +insert_worksheet_nh(head(mtcars) + ,export + ,"data1" + ,title = "Title" + ,source = "Quelle: Statistisches Amt Kanton Zürich" + ,metadata = "Bemerkung: ...") + + # insert a further worksheet +insert_worksheet_nh(tail(mtcars) + ,export + ,"data2" + ,title = "Title" + ,source = "Quelle: Statistisches Amt Kanton Zürich" + ,metadata = "Bemerkung: ...") +if (FALSE) { + # save workbook + openxlsx::saveWorkbook(export,"example.xlsx") +} +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/interpolate2-1.png b/docs/reference/interpolate2-1.png new file mode 100644 index 0000000..764acf0 Binary files /dev/null and b/docs/reference/interpolate2-1.png differ diff --git a/docs/reference/interpolate2.html b/docs/reference/interpolate2.html new file mode 100644 index 0000000..479b7a6 --- /dev/null +++ b/docs/reference/interpolate2.html @@ -0,0 +1,209 @@ + + + + + + + + +interpolate2() — interpolate2 • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to generate new color palettes by interpolation.

    +
    + +
    interpolate2(palette, color = color, degree = degree, number = number)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + +
    palette

    a vector of colors to be interpolated

    color

    color (hex-code) to be mixed with the colors in the 'palette'.

    degree

    degree of interpolation, range: 1 (slight interpolation) - 7 (strong interpolation).

    number

    number of colors to be generated.

    + + +

    Examples

    +
    #interpolate the 'zhblue'-palette with black and generate 7 new ones +interpolate2(palette = zhpal$zhblue, color = c("#000000"), degree = 3, number = 7) +
    #> [1] "#2A526A" "#2A5B78" "#2A6587" "#3F708C" "#537A92" "#6A8698" "#7F929E"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/mid_rescaler.html b/docs/reference/mid_rescaler.html new file mode 100644 index 0000000..b57a47a --- /dev/null +++ b/docs/reference/mid_rescaler.html @@ -0,0 +1,179 @@ + + + + + + + + +mid_rescaler() — mid_rescaler • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    mid_rescaler(mid)
    + + + +

    Examples

    +
    mid_rescaler() +
    #> Error in mid_rescaler(): could not find function "mid_rescaler"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/motor_trend_car_road_tests.xlsx b/docs/reference/motor_trend_car_road_tests.xlsx new file mode 100644 index 0000000..a0baa5a Binary files /dev/null and b/docs/reference/motor_trend_car_road_tests.xlsx differ diff --git a/docs/reference/quickXLSX.html b/docs/reference/quickXLSX.html new file mode 100644 index 0000000..0a98389 --- /dev/null +++ b/docs/reference/quickXLSX.html @@ -0,0 +1,254 @@ + + + + + + + + +quickXLSX() — quickXLSX • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to export data from R to a formatted .xlsx-spreadsheet.

    +
    + +
    quickXLSX(
    +  data,
    +  file,
    +  title = "Title",
    +  source = "statzh",
    +  metadata = NA,
    +  logo = "statzh",
    +  grouplines = FALSE,
    +  contactdetails = "statzh",
    +  author = "user"
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    data to be exported.

    file

    file name of the xlsx-file. The extension ".xlsx" is added automatically.

    title

    title to be put above the data in the worksheet.

    source

    source of the data. Defaults to "statzh".

    metadata

    metadata-information to be included. Defaults to NA.

    logo

    path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh"

    grouplines

    columns to be separated visually by vertical lines.

    contactdetails

    contactdetails of the data publisher. Defaults to "statzh".

    author

    defaults to last two letters (initials) or numbers of the user name.

    + + +

    Examples

    +
    # Beispiel anhand des Datensatzes 'mtcars' +dat <- mtcars + +quickXLSX(data = dat, + title = "Motor trend car road tests", + file = "motor_trend_car_road_tests", # '.xlsx' is automatically added + source = "Source: Henderson and Velleman (1981). Building multiple + regression models interactively. + Biometrics, 37, 391–411.", + metadata = c("The data was extracted from the 1974 Motor Trend US + magazine and comprises fuel + consumption and 10 aspects of automobile design and performance + for 32 automobiles (1973–74 models)."), + contactdetails = "statzh", + grouplines = FALSE, + logo = "statzh", + author = "user") + +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/quick_sum.html b/docs/reference/quick_sum.html new file mode 100644 index 0000000..1356a47 --- /dev/null +++ b/docs/reference/quick_sum.html @@ -0,0 +1,232 @@ + + + + + + + + +quick_sum() — quick_sum • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function for simple (grouped) descriptive analyses.

    +
    + +
    quick_sum(df, var, ..., stats = "all", protect = FALSE)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + +
    df

    dataframe

    var

    variables to be aggregated

    ...

    grouping variables

    stats

    Which descriptive statistics should be computed? Can be "all", "base", or "mean". See details.

    protect

    Apply data protection, can be TRUE or FALSE. See details.

    + +

    Details

    + +

    If stats is set to "all" (the default), the following descriptive statistics are computed per category of the grouping variable(s): mean, standard deviation, +10%-quantile, 25%-quantile, median, 75%-quantile, 90%-quantile. +If stats is set to "base", the mean, 25%-quantile, median, and 75%-quantile are returned. +stats = "mean" computes the mean and the standard deviation.

    +

    If protect is set to TRUE, the mean and the median is only computed for variables/variable categories with four or more observations. For <4 observations, the function returns NA for the respective variable/category. The other descriptives are only computed if there are at least 6 observations per variable (category).

    + +

    Examples

    +
    +quick_sum(df=mtcars, var=cyl, mpg, vs, stats="all", protect=FALSE) +
    #> # A tibble: 26 x 10 +#> mpg vs Anzahl mean_cyl sd_cyl q10_cyl q25_cyl med_cyl q75_cyl q90_cyl +#> <dbl> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> +#> 1 10.4 0 2 8 0 8 8 8 8 8 +#> 2 13.3 0 1 8 NA 8 8 8 8 8 +#> 3 14.3 0 1 8 NA 8 8 8 8 8 +#> 4 14.7 0 1 8 NA 8 8 8 8 8 +#> 5 15 0 1 8 NA 8 8 8 8 8 +#> 6 15.2 0 2 8 0 8 8 8 8 8 +#> 7 15.5 0 1 8 NA 8 8 8 8 8 +#> 8 15.8 0 1 8 NA 8 8 8 8 8 +#> 9 16.4 0 1 8 NA 8 8 8 8 8 +#> 10 17.3 0 1 8 NA 8 8 8 8 8 +#> # … with 16 more rows
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/scale_color_gradient2_stat.html b/docs/reference/scale_color_gradient2_stat.html new file mode 100644 index 0000000..7a65409 --- /dev/null +++ b/docs/reference/scale_color_gradient2_stat.html @@ -0,0 +1,186 @@ + + + + + + + + +scale_color_gradient2_stat() — scale_color_gradient2_stat • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    scale_color_gradient2_stat(
    +  palette = "zhbluered",
    +  ...,
    +  space = "Lab",
    +  na.value = "grey50",
    +  guide = "colourbar",
    +  midpoint = 0
    +)
    + + + +

    Examples

    +
    scale_color_gradient2_stat() +
    #> Error in scale_color_gradient2_stat(): could not find function "scale_color_gradient2_stat"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/scale_color_gradient_stat.html b/docs/reference/scale_color_gradient_stat.html new file mode 100644 index 0000000..559c92a --- /dev/null +++ b/docs/reference/scale_color_gradient_stat.html @@ -0,0 +1,185 @@ + + + + + + + + +scale_color_gradient_stat() — scale_color_gradient_stat • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    scale_color_gradient_stat(
    +  palette = "zhblueseq",
    +  ...,
    +  space = "Lab",
    +  na.value = "grey50",
    +  guide = "colourbar"
    +)
    + + + +

    Examples

    +
    scale_color_gradient_stat() +
    #> Error in scale_color_gradient_stat(): could not find function "scale_color_gradient_stat"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/scale_color_gradientn_stat.html b/docs/reference/scale_color_gradientn_stat.html new file mode 100644 index 0000000..ba231ce --- /dev/null +++ b/docs/reference/scale_color_gradientn_stat.html @@ -0,0 +1,187 @@ + + + + + + + + +scale_color_gradientn_stat() — scale_color_gradientn_stat • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    scale_color_gradientn_stat(
    +  ...,
    +  colours,
    +  values = NULL,
    +  space = "Lab",
    +  na.value = "grey50",
    +  guide = "colourbar",
    +  colors
    +)
    + + + +

    Examples

    +
    scale_color_gradientn_stat() +
    #> Error in scale_color_gradientn_stat(): could not find function "scale_color_gradientn_stat"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/scale_color_stat.html b/docs/reference/scale_color_stat.html new file mode 100644 index 0000000..036c280 --- /dev/null +++ b/docs/reference/scale_color_stat.html @@ -0,0 +1,179 @@ + + + + + + + + +scale_colour_stat() — scale_color_stat • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    scale_color_stat(palette = "zh", ...)
    + + + +

    Examples

    +
    scale_colour_stat() +
    #> Error in scale_colour_stat(): could not find function "scale_colour_stat"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/scale_fill_gradient_stat.html b/docs/reference/scale_fill_gradient_stat.html new file mode 100644 index 0000000..437d279 --- /dev/null +++ b/docs/reference/scale_fill_gradient_stat.html @@ -0,0 +1,185 @@ + + + + + + + + +scale_fill_gradient_stat() — scale_fill_gradient_stat • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    scale_fill_gradient_stat(
    +  palette = "zhblueseq",
    +  ...,
    +  space = "Lab",
    +  na.value = "grey50",
    +  guide = "colourbar"
    +)
    + + + +

    Examples

    +
    scale_fill_gradient_stat() +
    #> Error in scale_fill_gradient_stat(): could not find function "scale_fill_gradient_stat"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/scale_fill_stat.html b/docs/reference/scale_fill_stat.html new file mode 100644 index 0000000..14702b6 --- /dev/null +++ b/docs/reference/scale_fill_stat.html @@ -0,0 +1,179 @@ + + + + + + + + +scale_fill_stat() — scale_fill_stat • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    scale_fill_stat(palette = "zh", ...)
    + + + +

    Examples

    +
    scale_fill_stat() +
    #> Error in scale_fill_stat(): could not find function "scale_fill_stat"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/splitXLSX.html b/docs/reference/splitXLSX.html new file mode 100644 index 0000000..0f43609 --- /dev/null +++ b/docs/reference/splitXLSX.html @@ -0,0 +1,259 @@ + + + + + + + + +splitXLSX() — splitXLSX • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Function to export data from R as formatted .xlsx-file and spread them over several worksheets based on a grouping variable (e.g., year).

    +
    + +
    splitXLSX(
    +  data,
    +  file,
    +  sheetvar,
    +  title = "Titel",
    +  source = "statzh",
    +  metadata = NA,
    +  logo = "statzh",
    +  grouplines = FALSE,
    +  contactdetails = "statzh",
    +  author = "user"
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    data

    data to be exported.

    file

    file name of the xlsx-file. The extension ".xlsx" is added automatically.

    sheetvar

    name of the variable used to split the data and spread them over several sheets.

    title

    title to be put above the data in the worksheet. the sheetvar subcategory is added in brackets.

    source

    source of the data. Defaults to "statzh".

    metadata

    metadata-information to be included. Defaults to NA.

    logo

    path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh"

    grouplines

    columns to be separated visually by vertical lines.

    contactdetails

    contactdetails of the data publisher. Defaults to "statzh".

    author

    defaults to last two letters (initials) or numbers of the user name.

    + + +

    Examples

    +
    +dat <- mtcars + +splitXLSX(data = dat, + title = "Motor trend car road tests", + file = "motor_trend_car_road_tests", # '.xlsx' automatically added + sheetvar = cyl, + source = "Source: Henderson and Velleman (1981), + Building multiple regression models interactively. + Biometrics, 37, 391–411.", + metadata = c("The data was extracted from the 1974 + Motor Trend US magazine and comprises fuel consumption and + 10 aspects of automobile design and performance for + 32 automobiles (1973–74 models)."), + contactdetails = "statzh", + grouplines = FALSE, + logo = "statzh", + author = "user") +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/stat_div_gradient_pal.html b/docs/reference/stat_div_gradient_pal.html new file mode 100644 index 0000000..b5f3e4b --- /dev/null +++ b/docs/reference/stat_div_gradient_pal.html @@ -0,0 +1,179 @@ + + + + + + + + +stat_div_gradient_pal() — stat_div_gradient_pal • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    stat_div_gradient_pal(palette = "zhbluered", space = "Lab")
    + + + +

    Examples

    +
    stat_div_gradient_pal() +
    #> Error in stat_div_gradient_pal(): could not find function "stat_div_gradient_pal"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/stat_seq_gradient_pal.html b/docs/reference/stat_seq_gradient_pal.html new file mode 100644 index 0000000..20ca97e --- /dev/null +++ b/docs/reference/stat_seq_gradient_pal.html @@ -0,0 +1,179 @@ + + + + + + + + +scale_seq_gradient() — stat_seq_gradient_pal • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    stat_seq_gradient_pal(palette = "zhblue", space = "Lab")
    + + + +

    Examples

    +
    scale_seq_gradient() +
    #> Error in scale_seq_gradient(): could not find function "scale_seq_gradient"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/stattheme_data.html b/docs/reference/stattheme_data.html new file mode 100644 index 0000000..dca3941 --- /dev/null +++ b/docs/reference/stattheme_data.html @@ -0,0 +1,181 @@ + + + + + + + + +Data used by the stat zh palettes — stattheme_data • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Data used by the stat zh palettes

    +
    + +
    stattheme_data
    + + +

    Format

    + +

    A list.

    + +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/stattheme_pal.html b/docs/reference/stattheme_pal.html new file mode 100644 index 0000000..97a1a04 --- /dev/null +++ b/docs/reference/stattheme_pal.html @@ -0,0 +1,179 @@ + + + + + + + + +stattheme_pal() — stattheme_pal • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Stat ZH scales

    +
    + +
    stattheme_pal(palette = "default")
    + + + +

    Examples

    +
    stattheme_pal() +
    #> Error in stattheme_pal(): could not find function "stattheme_pal"
    +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/theme_stat.html b/docs/reference/theme_stat.html new file mode 100644 index 0000000..a4b78e2 --- /dev/null +++ b/docs/reference/theme_stat.html @@ -0,0 +1,231 @@ + + + + + + + + +theme_stat() — theme_stat • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    This ggplot2 theme is based on ggplot2::theme_minimal(). It controls the non-data related characteristics of a plot (e.g., the font type). +On top of that, the font size, the presence (or absence) of minor grid lines, axis lines, axis ticks and the axis label positions can be specified.

    +
    + +
    theme_stat(
    +  base_size = 11,
    +  axis.label.pos = "top",
    +  axis.lines = "x",
    +  ticks = "x",
    +  minor.grid.lines = FALSE
    +)
    + +

    Arguments

    + + + + + + + + + + + + + + + + + + + + + + +
    base_size

    base font size, given in pts.

    axis.label.pos

    position of x and y-axis labels, can be set to "top", "center", or "bottom".

    axis.lines

    presence of axis lines, can be set to "x", "y", or "both".

    ticks

    presence of axis ticks, can be set to "x", "y", or "both".

    minor.grid.lines

    presence of minor grid lines on the y-axis, can be set to TRUE or FALSE.

    + +

    Details

    + +

    To use this theme in a R Markdown generated PDF document, insert `dev="cairo_pdf"` into `knitr::opts_chunk$set()`.

    + +

    Examples

    +
    # \donttest{ +if (FALSE) { +library(ggplot2) +library(statR) + +ggplot(mpg, aes(class)) + +geom_bar() + +theme_stat() + +labs(title = "Title") +}# } +
    +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/docs/reference/zhpal.html b/docs/reference/zhpal.html new file mode 100644 index 0000000..7e5af5d --- /dev/null +++ b/docs/reference/zhpal.html @@ -0,0 +1,187 @@ + + + + + + + + +Data used by the stat zh palettes — zhpal • statR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    + + + + +
    + +
    +
    + + +
    +

    Data used by the stat zh palettes

    +
    + +
    zhpal
    + + +

    Format

    + +

    A list.

    + +
    + +
    + + +
    + + + + +
    +

    Site built with pkgdown 1.6.1.

    +
    + +
    +
    + + + + + + + + diff --git a/inst/extdata/Stempel_Kanton_ZH.png b/inst/extdata/Stempel_Kanton_ZH.png new file mode 100644 index 0000000..aacea8c Binary files /dev/null and b/inst/extdata/Stempel_Kanton_ZH.png differ diff --git a/inst/extdata/Stempel_STAT-01.png b/inst/extdata/Stempel_STAT-01.png new file mode 100644 index 0000000..de585d8 Binary files /dev/null and b/inst/extdata/Stempel_STAT-01.png differ diff --git a/inst/rmarkdown/templates/zh_report/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/zh_report/skeleton/skeleton.Rmd new file mode 100644 index 0000000..5048161 --- /dev/null +++ b/inst/rmarkdown/templates/zh_report/skeleton/skeleton.Rmd @@ -0,0 +1,33 @@ +--- +title: "Titel" +author: "Petra Muster" +date: "01.01.2020" +output: + html_document: + css: style.css + template: zhtemplate.html +--- + +```{r setup, include=FALSE} +knitr::opts_chunk$set(echo = TRUE) +``` + +## R Markdown + +This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see . + +When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: + +```{r cars} +summary(cars) +``` + +## Including Plots + +You can also embed plots, for example: + +```{r pressure, echo=FALSE} +plot(pressure) +``` + +Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. diff --git a/inst/rmarkdown/templates/zh_report/skeleton/skeleton.html b/inst/rmarkdown/templates/zh_report/skeleton/skeleton.html new file mode 100644 index 0000000..c4e02ee --- /dev/null +++ b/inst/rmarkdown/templates/zh_report/skeleton/skeleton.html @@ -0,0 +1,202 @@ + + + + + + + + + + + + + +Titel + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + + + +
    +

    zh.ch style Rmarkdown

    +

    This file is what a user will see when they select your template. Make sure that you update the fields in the yaml header. In particular you will want to update the output field to whatever format your template requires.

    +

    This is a good place to demonstrate special features that your template provides. Ideally it should knit out-of-the-box, or at least contain clear instructions as to what needs changing.

    +

    Finally, be sure to remove this message!

    +
    +
    +

    zh.ch style Rmarkdown

    +

    This file is what a user will see when they select your template. Make sure that you update the fields in the yaml header. In particular you will want to update the output field to whatever format your template requires.

    +

    This is a good place to demonstrate special features that your template provides. Ideally it should knit out-of-the-box, or at least contain clear instructions as to what needs changing.

    +

    Finally, be sure to remove this message!

    +
    + + + + +
    + + + + + + + + + + + + + \ No newline at end of file diff --git a/inst/rmarkdown/templates/zh_report/skeleton/style.css b/inst/rmarkdown/templates/zh_report/skeleton/style.css new file mode 100644 index 0000000..28cf31b --- /dev/null +++ b/inst/rmarkdown/templates/zh_report/skeleton/style.css @@ -0,0 +1,135 @@ +*{ + font-family: HelveticaNowRegular, Helvetica, sans-serif; +} + +.col-leftmid{ + float: left; + width: 30%; + text-align: left; +} + +.col-rightmid{ + float: right; + width: 70%; + text-align: left; +} + + + /* Whole document: */ + html { + font-size: 16px; + color: #fff; + line-height: 1.5; + position: relative; + text-decoration: none; + } + + body { + font-size: 16px; + line-height: 1.5; + position: relative; + text-decoration: none; + } + + h1, h2, h3, h4 { + font-family: HelveticaNowBlack,"Arial Black",Helvetica,sans-serif; + color: #000; + } + +h2 { + font-family: HelveticaNowBlack,"Arial Black",Helvetica,sans-serif; + color: #0076BD; + } + + +p { + margin-left: 5px; + color: rgba(0, 0, 0, 0.6); + font-size: 20px; + } + +th { + font-family: HelveticaNowBlack,"Arial Black",Helvetica,sans-serif; +} + + .container-fluid { + padding-left: 20px; + padding-right: 20px; + position: relative; + margin-left: 0; + } + + +.nav-tabs > li > a { + margin-right: 2px; + line-height: 1.42857143; + border: none; + border-radius: 4px 4px 4px 4px; + font-family: "Arial Black"; +} + +.nav-tabs { + border-bottom: none; +} + + +.nav-tabs > li.active > a, .nav-tabs > li.active > a:focus, .nav-tabs > li.active > a:hover { + color: #ffffff; + cursor: default; + background-color: #0076BD; + border: 1px solid #ddd; + border-bottom-color: transparent; +} + +.js-plotly-plot .plotly, .js-plotly-plot .plotly div { + direction: ltr; + margin-left: 25px; + padding: 0px; +} + + +.col-rightmid { + float: right; + width: 69.5%; + text-align: left; +} + +#header { + overflow: hidden; + background-color: #0076BD; + padding: 20px 10px; + text-align: center; + color: white; +} + + +h1.title { + font-size: 38px; + color: white; +} + +h4.author, h4.date { + color: white; + font-family: HelveticaNowRegular,Helvetica,sans-serif; +} + +.logo { + width: 5%; + height: auto; + min-width: 10px; + position:absolute; + left:2%; +} + +.main-container { + max-width: 1800px !important; + margin-left: auto; + margin-right: auto; +} + +#header ~ * { + max-width: 1042px; + margin-left: 15%; + margin-right: 15%; + display: inline-block; +} diff --git a/inst/rmarkdown/templates/zh_report/skeleton/zhtemplate.html b/inst/rmarkdown/templates/zh_report/skeleton/zhtemplate.html new file mode 100644 index 0000000..2ae0587 --- /dev/null +++ b/inst/rmarkdown/templates/zh_report/skeleton/zhtemplate.html @@ -0,0 +1,665 @@ + + + + + + + + + + +$if(theme)$ +$else$ + +$endif$ + +$for(author-meta)$ + +$endfor$ + +$if(date-meta)$ + +$endif$ + +$if(title-prefix)$$title-prefix$ - $endif$$pagetitle$ + +$for(header-includes)$ +$header-includes$ +$endfor$ +$if(shiny-prerendered)$ + +$endif$ + + + +$if(highlightjs)$ + + +$endif$ + +$if(highlighting-css)$ + + + +$endif$ + +$if(abstract)$ + +$endif$ + +$if(source_embed)$ + +$endif$ + +$if(csl-css)$ + +$endif$ + +$for(css)$ + +$endfor$ + + + +$if(theme)$ + + +$if(kable-scroll)$ + +$endif$ + +$if(navbar)$ + + + +$endif$ + + + + + + +$if(code_menu)$ + +$endif$ + + +$if(toc_float)$ + + + +$endif$ + +$endif$ + + + + + +$if(theme)$ + +
    + +$if(toc_float)$ + + +
    +$if(bs3)$ +
    +$else$ +
    +$endif$ +$if(toc-title)$ +

    $toc-title$

    +$endif$ +
    +
    +
    + +$if(bs3)$ +
    +$else$ +
    +$endif$ + +$endif$ + +$endif$ + +$for(include-before)$ +$include-before$ +$endfor$ + +$if(theme)$ +
    + +$if(code_menu)$ +
    + + +
    + +$endif$ + +$endif$ + +$if(title)$ +

    $title$

    +$if(subtitle)$ +

    $subtitle$

    +$endif$ +$for(author)$ +$if(author.name)$ +

    $author.name$

    +$if(author.affiliation)$ +
    +$author.affiliation$
    $endif$ +$if(author.email)$ +$author.email$ +
    +$endif$ +$else$ +

    $author$

    +$endif$ +$endfor$ +$if(date)$ +

    $date$

    +$endif$ +$if(abstract)$ +
    +

    Abstract

    +$abstract$ +
    +$endif$ +$endif$ + +$if(theme)$ +
    +$endif$ + +$if(toc_float)$ +$else$ +$if(toc)$ +
    +$if(toc-title)$ +

    $toc-title$

    +$endif$ +$toc$ +
    +$endif$ +$endif$ + +$body$ + +$for(include-after)$ +$include-after$ +$endfor$ + +$if(theme)$ + +$if(toc_float)$ +
    +
    +$endif$ + +
    + + + + + + +$endif$ + + +$if(code_menu)$ + +$endif$ + +$if(toc_float)$ + +$endif$ + +$if(mathjax-url)$ + + +$endif$ + + + \ No newline at end of file diff --git a/inst/rmarkdown/templates/zh_report/skeleton/zhweb.png b/inst/rmarkdown/templates/zh_report/skeleton/zhweb.png new file mode 100644 index 0000000..3c21f30 Binary files /dev/null and b/inst/rmarkdown/templates/zh_report/skeleton/zhweb.png differ diff --git a/inst/rmarkdown/templates/zh_report/template.yaml b/inst/rmarkdown/templates/zh_report/template.yaml new file mode 100644 index 0000000..84c01b4 --- /dev/null +++ b/inst/rmarkdown/templates/zh_report/template.yaml @@ -0,0 +1,3 @@ +name: "ZH Report" +description: A template with customized pandoc output format +create_dir: true diff --git a/man-roxygen/shared_parameters.R b/man-roxygen/shared_parameters.R new file mode 100644 index 0000000..7003ee1 --- /dev/null +++ b/man-roxygen/shared_parameters.R @@ -0,0 +1,8 @@ +# Parameters that are used in several functions + +#' @param source source of the data. Defaults to "statzh". +#' @param metadata metadata-information to be included. Defaults to NA. +#' @param logo path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh" +#' @param contactdetails contactdetails of the data publisher. Defaults to "statzh". +#' @param grouplines columns to be separated visually by vertical lines. +#' @param author defaults to last two letters (initials) or numbers of the user name. diff --git a/man/datasetsXLSX.Rd b/man/datasetsXLSX.Rd new file mode 100644 index 0000000..766e53e --- /dev/null +++ b/man/datasetsXLSX.Rd @@ -0,0 +1,120 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/datasetsXLSX.R +\name{datasetsXLSX} +\alias{datasetsXLSX} +\title{datasetsXLSX()} +\usage{ +datasetsXLSX( + file, + maintitle, + datasets, + widths = NULL, + heights = NULL, + startrows = NULL, + startcols = NULL, + sheetnames, + titles, + logo = "statzh", + titlesource = "statzh", + sources = "statzh", + metadata1 = NA, + auftrag_id = NULL, + contact = "statzh", + homepage = "statzh", + openinghours = "statzh" +) +} +\arguments{ +\item{file}{file name of the spreadsheet. The extension ".xlsx" is added automatically.} + +\item{maintitle}{Title to be put on the first (overview) sheet.} + +\item{datasets}{datasets or plots to be included.} + +\item{widths}{width of figure in inch (1 inch = 2.54 cm). See details.} + +\item{heights}{height of figure in inch (1 inch = 2.54 cm). See details.} + +\item{startrows}{row where upper left corner of figure should be placed. See details.} + +\item{startcols}{column where upper left corner of figure should be placed. See details.} + +\item{sheetnames}{names of the sheet tabs.} + +\item{titles}{titles of the different sheets.} + +\item{logo}{file path to the logo to be included in the index-sheet. Can be "statzh" or "zh". Defaults to "statzh".} + +\item{titlesource}{source to be mentioned on the title sheet beneath the title} + +\item{sources}{source of the data. Defaults to "statzh".} + +\item{metadata1}{metadata information to be included. Defaults to NA.} + +\item{auftrag_id}{order number.} + +\item{contact}{contact information on the title sheet. Defaults to "statzh"} + +\item{homepage}{web address to be put on the title sheet. Default to "statzh"} + +\item{openinghours}{openinghours written on the title sheet. Defaults to Data Shop} +} +\description{ +Function to export several datasets and/or figures from R to an .xlsx-file. The function creates an overview sheet and separate sheets +for each dataset/figure. +} +\details{ +When including figures, the heights and widths need to be specified as a vector. For example, say you have two datasets and one figure +that you would like to export. widths = c(0,0,5) then suggests that the figure will be 5 inches wide and placed in the third (and last) sheet of the file. +The same logic applies to the specification of `startrows` and `startcols`. +To include a ggplot2-plot, put a print statement around the ggplot2-object: list(..., ..., print(plot)). +} +\examples{ +\donttest{ +\dontrun{ + + +# Example with two datasets and no figure +dat1 <- mtcars +dat2 <- PlantGrowth + +datasetsXLSX(file="twoDatasets", # '.xlsx' wird automatisch hinzugefügt + maintitle = "Autos und Pflanzen", + datasets = list(dat1, dat2), + logo = "statzh", + sheetnames = c("Autos","Blumen"), + titles = c("mtcars-Datensatz","PlantGrowth-Datensatz"), + sources = c("Source: Henderson and Velleman (1981). + Building multiple regression models interactively. Biometrics, 37, 391–411.", + "Dobson, A. J. (1983) An Introduction to Statistical + Modelling. London: Chapman and Hall."), + metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", + "Bemerkungen zum PlantGrowth-Datensatz: x"), + auftrag_id="A2021_0000") + +# Example with two datasets and one figure + +dat1 <- mtcars +dat2 <- PlantGrowth +fig <- hist(mtcars$disp) + +datasetsXLSX(file="twoDatasetsandFigure", + maintitle = "Autos und Pflanzen", # '.xlsx' wird automatisch hinzugefügt + datasets = list(dat1, dat2, fig), + widths = c(0,0,5), + heights = c(0,0,5), + startrows = c(0,0,3), + startcols = c(0,0,3), + sheetnames = c("Autos","Blumen", "Histogramm"), + titles = c("mtcars-Datensatz","PlantGrowth-Datensatz", "Histogramm"), + sources = c("Source: Henderson and Velleman (1981). + Building multiple regression models interactively. Biometrics, 37, 391–411.", + "Source: Dobson, A. J. (1983) An Introduction to + Statistical Modelling. London: Chapman and Hall."), + metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", + "Bemerkungen zum PlantGrowth-Datensatz: x"), + auftrag_id="A2021_0000") +} +} +} +\keyword{datasetsXLSX} diff --git a/man/display.Rd b/man/display.Rd index 91169fa..794f016 100644 --- a/man/display.Rd +++ b/man/display.Rd @@ -8,6 +8,10 @@ display(col, border = "light gray", ...) } \arguments{ \item{col}{a vector of hex-code colors to be displayed} + +\item{border}{border color} + +\item{...}{further arguments that can be passed to the plot()-function} } \description{ preview colors in console diff --git a/man/figures/Stempel_STAT-01.png b/man/figures/Stempel_STAT-01.png new file mode 100644 index 0000000..de585d8 Binary files /dev/null and b/man/figures/Stempel_STAT-01.png differ diff --git a/man/flush_left.Rd b/man/flush_left.Rd new file mode 100644 index 0000000..8c7a23d --- /dev/null +++ b/man/flush_left.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/flush_left.r +\name{flush_left} +\alias{flush_left} +\title{flush_left} +\usage{ +flush_left(g) +} +\arguments{ +\item{g}{ggplot object} +} +\description{ +Function to flush title, subtitle and caption to the lefthand side of the graphics device +} +\examples{ +\dontrun{ +flush_left(ggplot(mtcars, aes( x = cyl))+ +geom_bar()+ +labs(title = "Titel", subtitle = "Untertitel", caption = "Datenquelle")) +} +} +\keyword{flush} +\keyword{left} diff --git a/man/insert_worksheet.Rd b/man/insert_worksheet.Rd index a554b3a..fea078e 100644 --- a/man/insert_worksheet.Rd +++ b/man/insert_worksheet.Rd @@ -2,41 +2,50 @@ % Please edit documentation in R/insert_worksheet.R \name{insert_worksheet} \alias{insert_worksheet} -\title{insert_worksheet} +\title{insert_worksheet()} \usage{ -insert_worksheet(data, workbook, sheetname = "data", title = "Title", - source = "statzh", metadata = NA, logo = NULL, grouplines = FALSE, - contactdetails = "statzh") +insert_worksheet( + data, + workbook, + sheetname = "data", + title = "Title", + source = "statzh", + metadata = NA, + logo = "statzh", + grouplines = FALSE, + contactdetails = "statzh", + author = "user" +) } \arguments{ -\item{data}{data to be included in the XLSX-table.} +\item{data}{data to be included.} -\item{workbook}{workbook object to write new worksheet in.} +\item{workbook}{workbook object to add new worksheet to.} -\item{sheetname}{name of the sheet-tab.} +\item{sheetname}{name of the sheet tab.} -\item{title}{title of the table and the sheet} +\item{title}{title to be put above the data.} \item{source}{source of the data. Defaults to "statzh".} -\item{metadata}{metadata-information to be included. Defaults to NA.} +\item{metadata}{metadata information to be included. Defaults to NA.} \item{logo}{path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh"} \item{grouplines}{defaults to FALSE. Can be used to separate grouped variables visually.} -\item{contactdetails}{contactdetails of the data publisher. Defaults to "statzh".} +\item{contactdetails}{contact details of the data publisher. Defaults to "statzh".} + +\item{author}{defaults to the last two letters (initials) or numbers of the internal user name.} } \description{ -Function to create formatted spreadsheets automatically +Function to add formatted worksheets to an existing .xlsx-workbook. } \examples{ -# Generation of a spreadsheet with four worksheets (one per 'carb'-category). -# Can be used to generate worksheets for multiple years. - # create workbook +# Generation of a spreadsheet wb <- openxlsx::createWorkbook("hello") -insert_worksheet(mtcars[c(1:10),],wb,"mtcars",c(1:4),carb,grouplines=c(1,5,6)) +insert_worksheet(data = mtcars[c(1:10),], workbook = wb, title = "mtcars", sheetname = "carb") } \keyword{insert_worksheet} diff --git a/man/interpolate2.Rd b/man/interpolate2.Rd index 98c8a6d..d80f9ac 100644 --- a/man/interpolate2.Rd +++ b/man/interpolate2.Rd @@ -7,20 +7,20 @@ interpolate2(palette, color = color, degree = degree, number = number) } \arguments{ -\item{palette}{a vector of colors to be interpolated to the same degree with the same color to generate uniform color palettes} +\item{palette}{a vector of colors to be interpolated} -\item{color}{a single color (hex-code) to be mixed with the colors in the 'palette'.} +\item{color}{color (hex-code) to be mixed with the colors in the 'palette'.} \item{degree}{degree of interpolation, range: 1 (slight interpolation) - 7 (strong interpolation).} -\item{number}{number of colours to be generated.} +\item{number}{number of colors to be generated.} } \description{ -generate new palettes by interpolation +Function to generate new color palettes by interpolation. } \examples{ -#interpolate the 'zhblue'-palette with black and generate 11 new hues. -interpolate2(zhpal$zhblue,"#000000",3,11) +#interpolate the 'zhblue'-palette with black and generate 7 new ones +interpolate2(palette = zhpal$zhblue, color = c("#000000"), degree = 3, number = 7) } \keyword{interpolate2} diff --git a/man/mid_rescaler.Rd b/man/mid_rescaler.Rd deleted file mode 100644 index f53962c..0000000 --- a/man/mid_rescaler.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{mid_rescaler} -\alias{mid_rescaler} -\title{mid_rescaler()} -\usage{ -mid_rescaler(mid) -} -\description{ -Stat ZH scales -} -\examples{ -mid_rescaler() - -} -\keyword{mid_rescaler} diff --git a/man/quickXLSX.Rd b/man/quickXLSX.Rd index 49df067..01735b4 100644 --- a/man/quickXLSX.Rd +++ b/man/quickXLSX.Rd @@ -2,16 +2,26 @@ % Please edit documentation in R/quickXLSX.R \name{quickXLSX} \alias{quickXLSX} -\title{quickXLSX} +\title{quickXLSX()} \usage{ -quickXLSX(data, file, ...) +quickXLSX( + data, + file, + title = "Title", + source = "statzh", + metadata = NA, + logo = "statzh", + grouplines = FALSE, + contactdetails = "statzh", + author = "user" +) } \arguments{ -\item{data}{data to be included in the XLSX-table.} +\item{data}{data to be exported.} -\item{file}{filename of the xlsx-file. No Default.} +\item{file}{file name of the xlsx-file. The extension ".xlsx" is added automatically.} -\item{name}{title of the table in the worksheet, defaults to "Titel".} +\item{title}{title to be put above the data in the worksheet.} \item{source}{source of the data. Defaults to "statzh".} @@ -19,18 +29,33 @@ quickXLSX(data, file, ...) \item{logo}{path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh"} +\item{grouplines}{columns to be separated visually by vertical lines.} + \item{contactdetails}{contactdetails of the data publisher. Defaults to "statzh".} -\item{grouplines}{columns to be separated visually by vertical lines.} +\item{author}{defaults to last two letters (initials) or numbers of the user name.} } \description{ -Function to create a formated single-worksheet XLSX automatically +Function to export data from R to a formatted .xlsx-spreadsheet. } \examples{ -quickXLSX(head(mtcars), "mtcars") - -#example with own logo, a custom filename, lines separating selected columns and some remarks +# Beispiel anhand des Datensatzes 'mtcars' +dat <- mtcars + +quickXLSX(data = dat, + title = "Motor trend car road tests", + file = "motor_trend_car_road_tests", # '.xlsx' is automatically added + source = "Source: Henderson and Velleman (1981). Building multiple + regression models interactively. + Biometrics, 37, 391–411.", + metadata = c("The data was extracted from the 1974 Motor Trend US + magazine and comprises fuel + consumption and 10 aspects of automobile design and performance + for 32 automobiles (1973–74 models)."), + contactdetails = "statzh", + grouplines = FALSE, + logo = "statzh", + author = "user") -quickXLSX(head(mtcars), file="filename", title="alternative title", source="alternative source",contactdetails="blavla", grouplines = c(1,2,3), metadata = "remarks:",logo="L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/nacht_map.png") } \keyword{quickXLSX} diff --git a/man/quick_sum.Rd b/man/quick_sum.Rd new file mode 100644 index 0000000..6206b15 --- /dev/null +++ b/man/quick_sum.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/quick_sum.r +\name{quick_sum} +\alias{quick_sum} +\title{quick_sum()} +\usage{ +quick_sum(df, var, ..., stats = "all", protect = FALSE) +} +\arguments{ +\item{df}{dataframe} + +\item{var}{variables to be aggregated} + +\item{...}{grouping variables} + +\item{stats}{Which descriptive statistics should be computed? Can be "all", "base", or "mean". See details.} + +\item{protect}{Apply data protection, can be TRUE or FALSE. See details.} +} +\description{ +Function for simple (grouped) descriptive analyses. +} +\details{ +If stats is set to "all" (the default), the following descriptive statistics are computed per category of the grouping variable(s): mean, standard deviation, +10\%-quantile, 25\%-quantile, median, 75\%-quantile, 90\%-quantile. +If stats is set to "base", the mean, 25\%-quantile, median, and 75\%-quantile are returned. +stats = "mean" computes the mean and the standard deviation. + +If protect is set to TRUE, the mean and the median is only computed for variables/variable categories with four or more observations. For <4 observations, the function returns NA for the respective variable/category. The other descriptives are only computed if there are at least 6 observations per variable (category). +} +\examples{ + +quick_sum(df=mtcars, var=cyl, mpg, vs, stats="all", protect=FALSE) +} +\keyword{quick_sum} diff --git a/man/scale_color_gradient2_stat.Rd b/man/scale_color_gradient2_stat.Rd deleted file mode 100644 index 55037e1..0000000 --- a/man/scale_color_gradient2_stat.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{scale_color_gradient2_stat} -\alias{scale_color_gradient2_stat} -\title{scale_color_gradient2_stat()} -\usage{ -scale_color_gradient2_stat(palette = "zhbluered", ..., space = "Lab", - na.value = "grey50", guide = "colourbar", midpoint = 0) -} -\description{ -Stat ZH scales -} -\examples{ -scale_color_gradient2_stat() - -} -\keyword{scale_color_gradient2_stat} diff --git a/man/scale_color_gradient_stat.Rd b/man/scale_color_gradient_stat.Rd deleted file mode 100644 index 4a548c0..0000000 --- a/man/scale_color_gradient_stat.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{scale_color_gradient_stat} -\alias{scale_color_gradient_stat} -\title{scale_color_gradient_stat()} -\usage{ -scale_color_gradient_stat(palette = "zhblueseq", ..., space = "Lab", - na.value = "grey50", guide = "colourbar") -} -\description{ -Stat ZH scales -} -\examples{ -scale_color_gradient_stat() - -} -\keyword{scale_color_gradient_stat} diff --git a/man/scale_color_gradientn_stat.Rd b/man/scale_color_gradientn_stat.Rd deleted file mode 100644 index abf52eb..0000000 --- a/man/scale_color_gradientn_stat.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{scale_color_gradientn_stat} -\alias{scale_color_gradientn_stat} -\title{scale_color_gradientn_stat()} -\usage{ -scale_color_gradientn_stat(..., colours, values = NULL, space = "Lab", - na.value = "grey50", guide = "colourbar", colors) -} -\description{ -Stat ZH scales -} -\examples{ -scale_color_gradientn_stat() - -} -\keyword{scale_color_gradientn_stat} diff --git a/man/scale_color_stat.Rd b/man/scale_color_stat.Rd deleted file mode 100644 index f88531e..0000000 --- a/man/scale_color_stat.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{scale_color_stat} -\alias{scale_color_stat} -\title{scale_colour_stat()} -\usage{ -scale_color_stat(palette = "zh", ...) -} -\description{ -Stat ZH scales -} -\examples{ -scale_colour_stat() - -} -\keyword{scale_colour_stat} diff --git a/man/scale_fill_gradient_stat.Rd b/man/scale_fill_gradient_stat.Rd deleted file mode 100644 index c58e4e8..0000000 --- a/man/scale_fill_gradient_stat.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{scale_fill_gradient_stat} -\alias{scale_fill_gradient_stat} -\title{scale_fill_gradient_stat()} -\usage{ -scale_fill_gradient_stat(palette = "zhblueseq", ..., space = "Lab", - na.value = "grey50", guide = "colourbar") -} -\description{ -Stat ZH scales -} -\examples{ -scale_fill_gradient_stat() - -} -\keyword{scale_fill_gradient_stat} diff --git a/man/scale_fill_stat.Rd b/man/scale_fill_stat.Rd deleted file mode 100644 index b993a2c..0000000 --- a/man/scale_fill_stat.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{scale_fill_stat} -\alias{scale_fill_stat} -\title{scale_fill_stat()} -\usage{ -scale_fill_stat(palette = "zh", ...) -} -\description{ -Stat ZH scales -} -\examples{ -scale_fill_stat() - -} -\keyword{scale_fill_stat} diff --git a/man/splitXLSX.Rd b/man/splitXLSX.Rd index df7a255..3080c37 100644 --- a/man/splitXLSX.Rd +++ b/man/splitXLSX.Rd @@ -2,18 +2,29 @@ % Please edit documentation in R/splitXLSX.R \name{splitXLSX} \alias{splitXLSX} -\title{splitXLSX} +\title{splitXLSX()} \usage{ -splitXLSX(data, file, sheetvar, ...) +splitXLSX( + data, + file, + sheetvar, + title = "Titel", + source = "statzh", + metadata = NA, + logo = "statzh", + grouplines = FALSE, + contactdetails = "statzh", + author = "user" +) } \arguments{ -\item{data}{data to be included in the XLSX-table.} +\item{data}{data to be exported.} -\item{file}{filename of the xlsx-file. No Default.} +\item{file}{file name of the xlsx-file. The extension ".xlsx" is added automatically.} -\item{sheetvar}{variable which contains the variable to be used to split the data across several sheets.} +\item{sheetvar}{name of the variable used to split the data and spread them over several sheets.} -\item{name}{title of the table in the worksheet, defaults to "Titel" + the value of the variable used to split the dataset across sheets.} +\item{title}{title to be put above the data in the worksheet. the sheetvar subcategory is added in brackets.} \item{source}{source of the data. Defaults to "statzh".} @@ -21,19 +32,33 @@ splitXLSX(data, file, sheetvar, ...) \item{logo}{path of the file to be included as logo (png / jpeg / svg). Defaults to "statzh"} +\item{grouplines}{columns to be separated visually by vertical lines.} + \item{contactdetails}{contactdetails of the data publisher. Defaults to "statzh".} -\item{grouplines}{columns to be separated visually by vertical lines.} +\item{author}{defaults to last two letters (initials) or numbers of the user name.} } \description{ -Function to create formatted spreadsheets automatically +Function to export data from R as formatted .xlsx-file and spread them over several worksheets based on a grouping variable (e.g., year). } \examples{ -# Generation of a spreadsheet with four worksheets (one per 'carb'-category). -# Can be used to generate worksheets for multiple years. -splitXLSX(mtcars[c(1:10),],"mtcars",carb,grouplines=c(1,5,6)) +dat <- mtcars -splitXLSX(head(mtcars),carb, file="filename",grouplines = c(1,2,3), metadata = "remarks: ....",source="canton of zurich",logo="L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/nacht_map.png") +splitXLSX(data = dat, + title = "Motor trend car road tests", + file = "motor_trend_car_road_tests", # '.xlsx' automatically added + sheetvar = cyl, + source = "Source: Henderson and Velleman (1981), + Building multiple regression models interactively. + Biometrics, 37, 391–411.", + metadata = c("The data was extracted from the 1974 + Motor Trend US magazine and comprises fuel consumption and + 10 aspects of automobile design and performance for + 32 automobiles (1973–74 models)."), + contactdetails = "statzh", + grouplines = FALSE, + logo = "statzh", + author = "user") } \keyword{splitXLSX} diff --git a/man/stat_div_gradient_pal.Rd b/man/stat_div_gradient_pal.Rd deleted file mode 100644 index ac6b9c5..0000000 --- a/man/stat_div_gradient_pal.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{stat_div_gradient_pal} -\alias{stat_div_gradient_pal} -\title{stat_div_gradient_pal()} -\usage{ -stat_div_gradient_pal(palette = "zhbluered", space = "Lab") -} -\description{ -Stat ZH scales -} -\examples{ -stat_div_gradient_pal() - -} -\keyword{stat_div_gradient_pal} diff --git a/man/stat_seq_gradient_pal.Rd b/man/stat_seq_gradient_pal.Rd deleted file mode 100644 index c15f850..0000000 --- a/man/stat_seq_gradient_pal.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{stat_seq_gradient_pal} -\alias{stat_seq_gradient_pal} -\title{scale_seq_gradient()} -\usage{ -stat_seq_gradient_pal(palette = "zhblue", space = "Lab") -} -\description{ -Stat ZH scales -} -\examples{ -scale_seq_gradient() - -} -\keyword{scale_seq_gradient} diff --git a/man/stattheme_data.Rd b/man/stattheme_data.Rd deleted file mode 100644 index a853324..0000000 --- a/man/stattheme_data.Rd +++ /dev/null @@ -1,14 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\docType{data} -\name{stattheme_data} -\alias{stattheme_data} -\title{Data used by the stat zh palettes} -\format{A \code{list}.} -\usage{ -stattheme_data -} -\description{ -Data used by the stat zh palettes -} -\keyword{datasets} diff --git a/man/stattheme_pal.Rd b/man/stattheme_pal.Rd deleted file mode 100644 index 33821d4..0000000 --- a/man/stattheme_pal.Rd +++ /dev/null @@ -1,16 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/col_stat.R -\name{stattheme_pal} -\alias{stattheme_pal} -\title{stattheme_pal()} -\usage{ -stattheme_pal(palette = "default") -} -\description{ -Stat ZH scales -} -\examples{ -stattheme_pal() - -} -\keyword{stattheme_pal} diff --git a/man/theme_stat.Rd b/man/theme_stat.Rd index 462dd14..b1e5098 100644 --- a/man/theme_stat.Rd +++ b/man/theme_stat.Rd @@ -4,16 +4,42 @@ \alias{theme_stat} \title{theme_stat()} \usage{ -theme_stat(base_size = 11) +theme_stat( + base_size = 11, + axis.label.pos = "top", + axis.lines = "x", + ticks = "x", + minor.grid.lines = FALSE +) } \arguments{ -\item{base_size}{base font size} +\item{base_size}{base font size, given in pts.} + +\item{axis.label.pos}{position of x and y-axis labels, can be set to "top", "center", or "bottom".} + +\item{axis.lines}{presence of axis lines, can be set to "x", "y", or "both".} + +\item{ticks}{presence of axis ticks, can be set to "x", "y", or "both".} + +\item{minor.grid.lines}{presence of minor grid lines on the y-axis, can be set to TRUE or FALSE.} } \description{ -Stat ZH Theme for ggplot2 +This ggplot2 theme is based on ggplot2::theme_minimal(). It controls the non-data related characteristics of a plot (e.g., the font type). +On top of that, the font size, the presence (or absence) of minor grid lines, axis lines, axis ticks and the axis label positions can be specified. +} +\details{ +To use this theme in a R Markdown generated PDF document, insert `dev="cairo_pdf"` into `knitr::opts_chunk$set()`. } \examples{ -theme_stat() +\donttest{ +\dontrun{ +library(ggplot2) +library(statR) +ggplot(mpg, aes(class)) + +geom_bar() + +theme_stat() + +labs(title = "Title") +}} } \keyword{theme_stat} diff --git a/man/zhpal.Rd b/man/zhpal.Rd index 04a46b4..ca81c10 100644 --- a/man/zhpal.Rd +++ b/man/zhpal.Rd @@ -4,7 +4,9 @@ \name{zhpal} \alias{zhpal} \title{Data used by the stat zh palettes} -\format{A \code{list}.} +\format{ +A \code{list}. +} \usage{ zhpal } diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml new file mode 100644 index 0000000..e2d9de6 --- /dev/null +++ b/pkgdown/_pkgdown.yml @@ -0,0 +1,4 @@ +template: + path: pkgdown/templates + params: + bootswatch: lumen diff --git a/pkgdown/extra.css b/pkgdown/extra.css new file mode 100644 index 0000000..db693d2 --- /dev/null +++ b/pkgdown/extra.css @@ -0,0 +1,148 @@ +@import url('https://fonts.googleapis.com/css?family=Raleway|Ubuntu+Mono'); + +h1, h2, h3, h4 { + font-family: HelveticaNowBlack,"Arial Black",Helvetica,sans-serif; + color: #000; + } + + +*{ + font-family: HelveticaNowRegular, Helvetica, sans-serif; +} + +body { + font-size: 16px; + line-height: 1.5; + position: relative; + text-decoration: none; + } + +code{ + font-family: 'Ubuntu Mono', monospace; +} + +p>a { + color: #66c4ff; +} + +li>a { + color: #66c4ff; +} + +.sourceCode>a{ + color: #293c55; +} + +.st{ + color: #B03A5B; +} + +.op{ + color: #666666; +} + +.dv, .dt{ + color: #191919; +} + +.btn-copy-ex{ + background-color: #B03A5B; + border-color: #293c55; +} + +.btn-copy-ex:hover{ + background-color: #293c55; + border-color: #B03A5B; +} + + +pre { + box-shadow: + rgba(0, 0, 0, 0.1) 0 2px 3px 1px, + rgba(0, 0, 0, 0.1) 0 1px 3px 1px, + rgba(0, 0, 0, 0.2) 0 1px 1px -1px; +} + +.navbar-default{ + border-color: #293c55; + background-color: #0076be; +} + +.navbar-default .navbar-nav>li>a { + color:#fff; +} + +.navbar-default .navbar-link { + color:#fff +} + +.label-default { + background-color: #293c55; +} + +.navbar-default .navbar-nav > .active > a, +.navbar-default .navbar-nav > .active > a:hover, +.navbar-default .navbar-nav > .active > a:focus { + color: #66c4ff; + background-color: #293c55; +} + +.navbar-default .navbar-nav > li > a:hover, +.navbar-default .navbar-nav > li > a:focus { + color: #66c4ff; +} + + .navbar-default .navbar-nav .open .dropdown-menu>li>a, .navbar-default .navbar-nav .open .dropdown-menu { + border-color: #FFFFFF; + background-color: #293c55; + color : #66c4ff; +} + + +.navbar-default .navbar-nav > li > a:hover, .navbar-default .navbar-nav > li > a:focus { + color: #293c55; + background-color: #66c4ff; +} + +.navbar-default .navbar-nav > .open > a, .navbar-default .navbar-nav > .open > a:hover, .navbar-default .navbar-nav > .open > a:focus { + + background-color: #293c55; + color: #ffffff; + +} + +.navbar-default .navbar-nav > .dropdown > a .caret { + color: #999999; +} +.navbar-default .navbar-nav > .dropdown > a:hover .caret, +.navbar-default .navbar-nav > .dropdown > a:focus .caret { + color: #B03A5B; +} + +.navbar-default .navbar-nav>.open>a, +.navbar-default .navbar-nav>.open>a:hover, +.navbar-default .navbar-nav>.open>a:focus{ + color: #d8d8d8; +} + +.navbar-default .navbar-nav .open .dropdown-menu>li>a:hover, +.navbar-default .navbar-nav .open .dropdown-menu{ + color: #dce6f2; +} + +.nav-pills>li.active>a, +.nav-pills>li.active>a:hover, +.nav-pills>li.active>a:focus { + color: #FFFFFF; + background-color: #435b7b; +} + +a:hover, a:focus { + color: #293c55; +} + +/*fix to move article titles below nav bar*/ + +.contents .page-header { + margin-top: calc(60px + 1em); +} diff --git a/pkgdown/templates/content-article.html b/pkgdown/templates/content-article.html new file mode 100644 index 0000000..5ad6b22 --- /dev/null +++ b/pkgdown/templates/content-article.html @@ -0,0 +1,70 @@ +$for(header-includes)$ +$header-includes$ +$endfor$ + +
    +
    + + + $for(include-before)$ + $include-before$ + $endfor$ + + $if(abstract)$ +
    +

    Abstract

    + $abstract$ +
    + $endif$ + +$body$ +
    + + + +
    + +$for(include-after)$ +$include-after$ +$endfor$ \ No newline at end of file diff --git a/pkgdown/templates/content-home.html b/pkgdown/templates/content-home.html new file mode 100644 index 0000000..ebfa121 --- /dev/null +++ b/pkgdown/templates/content-home.html @@ -0,0 +1,14 @@ +
    +
    +{{{index}}} +
    + + +
    \ No newline at end of file diff --git a/pkgdown/templates/footer.html b/pkgdown/templates/footer.html new file mode 100644 index 0000000..f072cbe --- /dev/null +++ b/pkgdown/templates/footer.html @@ -0,0 +1,9 @@ + + + + +
    +

    Site built with pkgdown {{#pkgdown}}{{version}}{{/pkgdown}}.

    +
    diff --git a/pkgdown/templates/head.html b/pkgdown/templates/head.html new file mode 100644 index 0000000..48e80a1 --- /dev/null +++ b/pkgdown/templates/head.html @@ -0,0 +1,95 @@ + + + + +{{{pagetitle}}} • {{#site}}{{title}}{{/site}} + +{{#has_favicons}} + + + + + + + +{{/has_favicons}} + + + + +{{#yaml}} +{{#bootswatch}}{{/bootswatch}} +{{^bootswatch}}{{/bootswatch}} +{{/yaml}} + + + + + + + + + + + + + + + + +{{#yaml}}{{#docsearch}} + + + + + +{{/docsearch}}{{/yaml}} + +{{#extra}} + {{#css}}{{/css}} + {{#js}}{{/js}} +{{/extra}} + + +{{#opengraph}} +{{#description}} + +{{/description}} +{{#image}} + +{{/image}} + +{{/opengraph}} + + + +{{#yaml}}{{#noindex}}{{/noindex}}{{/yaml}} +{{#development}}{{#in_dev}}{{/in_dev}}{{/development}} + + + + + + + +{{#yaml}}{{#ganalytics}} + + + +{{/ganalytics}}{{/yaml}} + + + \ No newline at end of file diff --git a/vignettes/Excel-Tabellen.Rmd b/vignettes/Excel-Tabellen.Rmd new file mode 100644 index 0000000..212c166 --- /dev/null +++ b/vignettes/Excel-Tabellen.Rmd @@ -0,0 +1,140 @@ +--- +title: "Excel-Tabellen" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Excel-Tabellen} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +## Allgemeine Informationen + +`statR` enthält mehrere Funktionen, mit welchen Datensätze aus `R` als Excel-Dateien exportiert werden können. Die Funktionen bauen auf dem [openxlsx-package](https://github.com/awalker89/openxlsx) auf. + +Per Default wird bei allen Funktionen das Logo des Statistischen Amts eingefügt und es werden die Kontaktangaben des Data Shops angegeben (`contactdetails = "statzh", logo = "statzh", source = "statzh"`). Mit den Funktionsargumenten können die Dateinamen, Titel, Quellenangaben sowie Metadaten und Namenskürzel spezifiziert werden. Um längere Quellen- und Metadatenangaben über mehrere Zeilen eines Arbeitsblatts zu verteilen, kann man sie in verschiedene Vektorelemente aufteilen (Beispiel: `c("Text Zeile 1, "Text Zeile 2", "Text Zeile 3")`. Mit dem Argument `grouplines` werden zudem vertikale Linien zwischen ausgewählten Spalten in der Excel-Tabelle eingefügt und die Spalten optisch voneinander separiert (aktuell nicht möglich bei `datasetsXLSX()`). + +Die Spalteninhalte können bei allen Funktionen entsprechend ihrer Einheit formatiert werden, indem pro Variablennamen die `class` festlegt wird. Mit `class(data$variable1) <- "percentage"` können die Werte der `variable1` (reichen von 0 bis 1) als Prozent mit Prozentzeichen ausgegeben werden. Weblinks können mit `class(data$variable2) <- "hyperlink"` aufrufbar gemacht werden und mit `class(data$variable3) <- "scientific"` können Zahlen in der wissenschaftlichen Notation dargestellt werden. + +## Funktionen und Beispiele + +### quickXLSX() + +Mit der Funktion `quickXLSX()` kann ein Datensatz aus `R` als vorformatierte XLSX-Datei exportiert werden. Die Funktion eignet sich, um einzelne Datensätze als Exceldatei zu verschicken. Mit dem Argument `author` kann vermerkt werden, wer die Datei erstellt hat. Per Default werden die Initialen bzw. letzten zwei Ziffern des hinterlegten Benutzernamens eingefügt. + +```{r,echo=T,eval=F,error=F} +# Beispiel anhand des Datensatzes 'mtcars' +dat <- mtcars + +quickXLSX(data = dat, + title = "Motor trend car road tests", + file = "motor_trend_car_road_tests", # '.xlsx' wird automatisch hinzugefügt + source = "Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.", + metadata = c("The data was extracted from the 1974 Motor Trend US magazine and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models)."), + contactdetails = "statzh", + logo = "statzh", + grouplines = FALSE, + author = "MD") + +``` + +![Screenshot der Datei motor_trend_car_road_tests.xlsx](./output-quickXLSX.PNG){width=95%} + +### splitXLSX() + +Mit der Funktion `splitXLSX()` kann ein Datensatz aus R in eine XLSX-Datei exportiert und auf mehreren Arbeitsblättern verteilt werden. Die Funktion ist besonders dann geeignet, wenn man einen Datensatz für verschiedene Ausprägungen einer Gruppierungsvariable (z.B. Altersklassen) separat aufführen möchte. Mit dem Argument `author` kann vermerkt werden, wer die Datei erstellt hat. Per Default werden die Initialen bzw. letzten zwei Ziffern des hinterlegten Benutzernamens eingefügt. + +Im Beispiel unten wird ein Arbeitsblatt pro Zylinderanzahl der Autos im `mtcars`-Datensatz generiert. + + +```{r,echo=T,eval=F} +# Beispiel anhand des Datensatzes 'mtcars' +dat <- mtcars + +# Beispiel mit Standardlogo (Logo des Statistischen Amts) +splitXLSX(data = dat, + title = "Motor trend car road tests", + file = "motor_trend_car_road_tests", # '.xlsx' wird automatisch hinzugefügt + sheetvar = cyl, # Variable, nach der die Daten auf die Tabellenblätter aufgeteilt werden sollen + source = "Source: Henderson and Velleman (1981), Building multiple regression models interactively. Biometrics, 37, 391–411.", + metadata = c("The data was extracted from the 1974 Motor Trend US magazine and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models)."), + contactdetails = "statzh", + grouplines = FALSE, + logo = "statzh", + author = "MD") +``` + +![Screenshot der Datei motor_trend_car_road_tests.xlsx](./output-splitXLSX.PNG){width=95%} + + +### datasetsXLSX() (*NEU*) + +Die Funktion datasetsXLSX() erlaubt es, mehrere Datensätze und/oder Grafiken aus R in eine XLSX-Datei zu exportieren. Pro Arbeitsblatt wird ein Datensatz oder eine Grafik dargestellt. Es kann auch eine Auftragsnummer hinzugefügt werden. Die Funktion eignet sich besonders für Fälle, wo man mehrere Datensätze an eine/n Empfänger/in verschicken möchte. + +Die Datensätze, die zusammen in einer Excel-Datei erscheinen sollen, müssen dem Funktionsargument `datasets` als Liste übergeben werden (`datasets = list(dataset1, dataset2, ...)`. + + +```{r,echo=T,eval=F} +# Beispiel mit zwei Datensätzen: +dat1 <- mtcars +dat2 <- PlantGrowth + +datasetsXLSX(file="twoDatasets", # '.xlsx' wird automatisch hinzugefügt + maintitle = "Autos und Pflanzen", + datasets = list(dat1, dat2), + sheetnames = c("Autos","Blumen"), + titles = c("mtcars-Datensatz","PlantGrowth-Datensatz"), + sources = c("Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.", + "Dobson, A. J. (1983) An Introduction to Statistical Modelling. London: Chapman and Hall."), + metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", + "Bemerkungen zum PlantGrowth-Datensatz: x"), + auftrag_id="A2021_0000", + logo = "statzh", + homepage = "statzh", + contact = "statzh", + openinghours = "statzh", + titlesource = "Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.") +``` + +![Screenshot des Titelblatts der Datei twoDatasets.xlsx](./output-datasetsXLSX-1.PNG){width=95%} + +![Screenshot des ersten Blatts der Datei twoDatasets.xlsx](./output-datasetsXLSX-2.PNG){width=95%} + + +Um eine Grafik in die Excel-Datei einzufügen, muss sie der `datasets`-Liste hinzugefügt werden: `datasets = list(dataset1, dataset2, grafik1)`. + +Mit den Argumenten `startrows` und `startcols` kann bestimmt werden, wo im Arbeitsblatt die Grafik platziert werden soll und mit `widths` und `heights` kann man die Höhe und die Breite adjustieren (aktuell in Zoll/*inches*, 1 Zoll = 2.54 cm). Die Grösse und Position wird mittels eines Vektors bestimmt, wobei es pro Arbeitsblatt ein Vektorelement gibt. Die Vektorelemente müssen überall auf `= 0` gesetzt sein ausser bei den Visualisierungen. Bei zwei Datensätzen und einer Grafik sieht der Vektor bspw. folgendermassen aus: `c(0,0,4)`. Hätte man einen Datensatz und zwei Grafiken, sähe der Vektor hingegen so aus: `c(0,4,4)`. + + +```{r,echo=T,eval=F} + +dat1 <- mtcars +dat2 <- PlantGrowth +fig <- hist(mtcars$disp) + +datasetsXLSX(file="twoDatasetsandFigure", + maintitle = "Autos und Pflanzen", # '.xlsx' wird automatisch hinzugefügt + datasets = list(dat1, dat2, fig), + widths = c(0,0,5), + heights = c(0,0,5), + startrows = c(0,0,3), + startcols = c(0,0,3), + sheetnames = c("Autos","Blumen", "Histogramm"), + logo = "statzh", + titles = c("mtcars-Datensatz","PlantGrowth-Datensatz", "Histogramm"), + sources = c("Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.", + "Source: Dobson, A. J. (1983) An Introduction to Statistical Modelling. London: Chapman and Hall."), + metadata1 = c("Bemerkungen zum mtcars-Datensatz: x", + "Bemerkungen zum PlantGrowth-Datensatz: x"), + auftrag_id="A2021_0000", + contact = "statzh", + openinghours = "statzh", + titlesource = "Source: Henderson and Velleman (1981). Building multiple regression models interactively. Biometrics, 37, 391–411.") +``` + diff --git a/vignettes/Sonstige_Funktionen.Rmd b/vignettes/Sonstige_Funktionen.Rmd new file mode 100644 index 0000000..008bbcf --- /dev/null +++ b/vignettes/Sonstige_Funktionen.Rmd @@ -0,0 +1,51 @@ +--- +title: "Sonstige Funktionen" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Sonstige_Funktionen} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +Neben Funktionen zur Excel-Dateierzeugung und Visualisierungen beinhaltet `statR` auch zwei weitere Hilfsfunktionen. `quick_sum()` erleichtert das Erstellen von deskriptiven Übersichtstabellen. `interpolate2()` kann zur Generierung von individualisierten Farbpaletten verwendet werden. + +# quick_sum() + +Mit der Funktion `quick_sum()` können deskriptive Statistiken berechnet werden. Je nach Spezifikation des `stats`-Arguments wird eine andere Anzahl Statistiken angezeigt (Durchschnitt, Median, Standardabweichung, Quantile, etc.). Siehe `?quick_sum()`. + +Im Beispiel unten wird mittels der Funktion berechnet, wie viele `mpg` (Miles/(US) gallon) die Autos abhängig von der Zylinderanzahl (`cyl`) und ihres Motorentyps (`vs`; 'V-shaped' oder 'straight') haben. Ausgegeben werden die Ausprägungen der Gruppierungsvariablen, die Anzahl sowie der Durchschnitt und die Quartile. + +```{r, eval = T, warning = F, message = F} +library(statR) +quick_sum(df=mtcars, var=mpg, cyl, vs, stats="base", protect=FALSE) +``` + +# interpolate2() + +Mit der Funktion `interpolate2()` können neue Farbpaletten erstellt werden, indem `zhpal`-Paletten mit einer oder mehreren Farben interpoliert werden. Die Funktion baut auf `grDevices::colorRamp()` auf. Mit dem Argument `degree` kann die Stärke der Interpolation bestimmt werden (von 1 bis 7) und mit dem Argument `number` die Anzahl der Farben, die die neue Palette enthalten soll. + +Im Beispiel unten wird die Palette `zhpal$zhblue` mit schwarz ("#000000") interpoliert. + +```{r, results = 'hide', message = F, warning = F} +new <- interpolate2(palette = zhpal$zhblue, color = c("#000000"), degree = 3, number = 7) +``` + +So sieht die ursprüngliche Palette aus: + +```{r} +display(zhpal$zhblue) +``` + +Zum direkten Vergleich die interpolierte Palette: + +```{r} +display(new) +``` + diff --git a/vignettes/Visualisierungen.Rmd b/vignettes/Visualisierungen.Rmd new file mode 100644 index 0000000..c12573a --- /dev/null +++ b/vignettes/Visualisierungen.Rmd @@ -0,0 +1,187 @@ +--- +title: "Visualisierungen" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Visualisierungen} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +# theme_stat() für ggplot2-Grafiken + +```{r setup, warning = F, message = F} +library(statR) +library(dplyr) +library(ggplot2) +library(tidyr) +``` + +Das **statR**-ggplot2-theme ist darauf ausgelegt, sich gut ins kantonale Corporate Design einzufügen. Es basiert auf dem ggplot2-theme 'minimal' und bestimmt diejenigen Grafikeigenschaften, die nichts mit den Daten an sich zu tun haben (z.B. die Schriftart). + +Innerhalb des themes kann die Schriftgrösse, die Position der Achsenbeschriftungen sowie das Vorhandensein von Achsenlinien, Achsen-Ticks und kleineren Gitterlinien bestimmt werden. + +```{r} +ggplot(mpg, aes(class,fill = drv))+ + geom_bar()+ + # Default-Spezifikationen innerhalb theme_stat() + theme_stat(base_size = 11, + axis.label.pos = "top", + axis.lines = "x", + ticks = "x", + minor.grid.lines = FALSE) + + labs(title = "Title", subtitle = "Subtitle", caption = "Caption") +``` + +# Farbpaletten + +Das Farbpalettenobjekt `zhpal` enthält alle im Package vorhandenen Farbpaletten und ist mit dem geladenen `statR`-Package global verfügbar. + +Mit der Funktion `display()` kann man sich die Farben einer Palette anschauen: + +```{r} +display(zhpal$zhdiagonal) +``` + +Mit der Funktion `grDevices::colorRampPalette()` kann eine beliebige Anzahl Farbtöne basierend auf einer statR-Farbpalette erstellt werden: + +```{r} +#Mische 20 Farbtöne auf Basis der zhdiagonal-Palette +display(grDevices::colorRampPalette((zhpal$zhdiagonal),space="Lab")(20)) +``` + +Anwendungsbeispiel mit kategorialen Daten: + +```{r} +#verwende die Paletten für kategoriale Daten mittels 'scale_fill_manual' +ggplot(mpg, aes(class,fill = drv))+ + geom_bar()+ + theme_stat()+ + scale_fill_manual(values=zhpal$zhblue) +``` + +## Barrierefreie Grafiken + +Bei der Erstellung von Grafiken ist es besonders wichtig darauf zu achten, dass die Grafiken auch für Personen mit (Farb-)Sehschwächen und Sehbehinderungen interpretierbar sind. Um solche barrierefreie Grafiken zu erstellen, bieten sich im Allgemeinen verschiedene Strategien an: + +- Daten, die der Grafik zugrunde liegen, zusätzlich als csv oder -html-Tabelle einbinden + +- Einen Alternativtext (alt-Text) hinterlegen, der beschreibt, was auf der Grafik abgebildet ist und wo die Daten zu finden sind + +- Farbpaletten wählen, die für Farbsehschwächen optimiert sind + +- Die Grafik soll nicht ausschliesslich aufgrund einer Farbpalette interpretierbar sein + +- Die Komplexität der Grafiken sollte auf ein Minimum beschränkt werden + +Einige dieser Punkte können direkt bei der Erstellung der Grafiken in R berücksichtigt werden. + +### 1. Farbsehschwächen + +Damit Grafiken auch für Personen mit Farbsehschwächen möglichst gut interpretierbar sind, sollten Farben in Grafiken sowohl bezüglich der *Farbanteile* als auch der *Farbsättigung* variiert werden. Wenn möglich, sollten unterschiedliche Datenkategorien zudem nicht nur über die Farben sondern auch über unterschiedliche Darstellungsformen unterscheidbar sein (z.B. Schraffuren, Punkt- oder Linientypen; siehe 1.3). Auch die direkte Beschriftung von Kategorien bietet sich hier als Mittel an (siehe 1.4). + +### 1.2 Auswahl Farbpaletten + +In R können mit dem [dichromat-Package](https://cran.r-project.org/web/packages/dichromat/index.html) diverse Ausprägungen von Farbsehschwäche simuliert werden. Dies erlaubt es Farbpaletten auszuwählen, die möglichst farbsehschwächenfreundlich sind. + +```{r out.width="20%", out.height="20%"} +library(dichromat) +# Anzeige der Farbpalette zhdiagonal +display(zhpal$zhdiagonal) +# Simulation Grünsehschwäche (Deuteranomalie) +display(dichromat(zhpal$zhdiagonal)) +# Simulation Blaublindheit (Tritanopie) +display(dichromat(zhpal$zhdiagonal,type="tritan")) +``` + +Die Simulation kann auch anhand von Grafiken vorgenommen werden. + +```{r} +p <- ggplot(diamonds, aes(clarity, fill=cut)) + + geom_bar(position = "stack", width= 0.5) + +p + theme_stat() + + scale_fill_manual(values=dichromat(zhpal$zhdiagonal, type=c("tritan"))) +``` + +### 1.3 Form- oder Linientypen + +Wenn immer möglich sollten unterschiedliche Kategorien nicht nur mit unterschiedlichen Farben gekennzeichnet werden, sondern auch mit unterschiedlichen Schraffuren, Symbol- oder Linientypen (siehe: https://bbc.github.io/gel/components/infographics/#recommended-layout). Ja nach Grafiktyp eignen sich andere Ansätze: + +- __Liniendiagramme__: [Linientyp](https://ggplot2.tidyverse.org/reference/aes_linetype_size_shape.html) + +- __Säulen / Flächendiagramme__: [Linientyp](https://ggplot2.tidyverse.org/reference/aes_linetype_size_shape.html) oder [Flächenstruktur](Flächen schraffieren : https://coolbutuseless.github.io/package/ggpattern/articles/pattern-circle.html#the-density-aesthetic-as-a-mapped-aesthetic-1) + +- __Scatter / Punkte-Diagramm__: [Symbole](https://ggplot2.tidyverse.org/reference/aes_linetype_size_shape.html) + + Ab einer gewissen Anzahl an Kategorien, wird die Grafik unübersichtlich. + +__Beispiel : Liniengrafik__ + +```{r} +data <- read.csv("https://www.web.statistik.zh.ch/ogd/data/ojuga/KANTON-ZUERICH_jugendstrafrechtspflege_geschlechter_verurteilungen.csv") %>% + pivot_longer(cols=2:3) + +gg_ojuga <- ggplot(data, aes(Jahr, value ,color=name,linetype=name)) + + geom_line()+ + theme_stat() +``` + +__Beispiel : Säulendiagramm__ + +```{r} +ggplot(mpg, aes(class,fill = drv,linetype=drv))+ + geom_bar(col ="black")+ + theme_stat()+ + scale_fill_manual(values=zhpal$zhblue)+ + theme(legend.position="right", axis.text.x = element_text(angle=90,vjust = 0.5, hjust=0), + panel.grid.major = element_line(colour = "grey", size = 0.1), + panel.grid.minor = element_line(colour = "grey", size = 0.2)) + +``` + +### 1.4 Direkte Beschriftung + +Bei gewissen Grafiktypen kann die Unterscheidbarkeit von Kategorien auch durch direkte Beschriftung verbessert werden. Das ´ggrepel´-package verfügt über die notwendigen Funktionen. Beispielsweise sorgt es dafür, dass die Beschriftungen nicht überlappen. + +```{r} +library(ggrepel) + +data <- read.csv("https://www.web.statistik.zh.ch/ogd/data/ojuga/KANTON-ZUERICH_jugendstrafrechtspflege_geschlechter_verurteilungen.csv") %>% + pivot_longer(cols=2:3) + +ggplot(data, aes(Jahr, value ,color=name)) + + geom_text_repel(data=data %>% filter(Jahr==max(Jahr)), aes(label=name), direction = "y") + + geom_line()+ + theme_stat()+ + guides(color="none") +``` + + +# Grafiken fürs ZHWeb + +Bei Grafiken, welche auf [zh.ch](zh.ch) Publiziert werden sollen, gilt es folgendes zu berücksichtigen: + +- Maximale Bildgrösse 4000x4000 +- Grafik-Titel, Untertitel, Legende, Quelle und Alt-Text müssen direkt im CMS (Bild-Komponente) hinterlegt und nicht in die Grafik selber integriert werden + +```{r} + +ggplot(mpg, aes(class,fill = drv))+ + geom_bar()+ + theme_stat()+ + scale_fill_manual(values=zhpal$zhblue)+ + theme(legend.position="right", axis.text.x = element_text(angle=90,vjust = 0.5, hjust=0), + panel.grid.major = element_line(colour = "grey", size = 0.1), + panel.grid.minor = element_line(colour = "grey", size = 0.2)) + + +# ggsave(file = "zhweb_plot.png", width=18, height=8, unit="cm") + +``` diff --git a/vignettes/html_report_template.Rmd b/vignettes/html_report_template.Rmd new file mode 100644 index 0000000..ee536db --- /dev/null +++ b/vignettes/html_report_template.Rmd @@ -0,0 +1,31 @@ +--- +title: "HTML Dokumente im ZH.CH-Design" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{html_report_template} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + + + __Alpha-Version__ + + +Das statR-Package enthält ein Template für html-Berichte, die dem kantonalen Corporate Design entsprechen. + +Dieses ist in R Studio im Menü unter __'File > New File > R Markdown'__ verfügbar. + +![Auswahl des Templates](./rmd_template.PNG) + +Im Auswahlfenster kann das __ZH Report__-Template ausgewählt werden. + +![zh-Report](./zh_report.PNG) + +![sample zh-Report](./sample_report.PNG) diff --git a/vignettes/output-datasetsXLSX-1.PNG b/vignettes/output-datasetsXLSX-1.PNG new file mode 100644 index 0000000..cb83542 Binary files /dev/null and b/vignettes/output-datasetsXLSX-1.PNG differ diff --git a/vignettes/output-datasetsXLSX-2.PNG b/vignettes/output-datasetsXLSX-2.PNG new file mode 100644 index 0000000..f678628 Binary files /dev/null and b/vignettes/output-datasetsXLSX-2.PNG differ diff --git a/vignettes/output-quickXLSX.PNG b/vignettes/output-quickXLSX.PNG new file mode 100644 index 0000000..7942bed Binary files /dev/null and b/vignettes/output-quickXLSX.PNG differ diff --git a/vignettes/output-splitXLSX.PNG b/vignettes/output-splitXLSX.PNG new file mode 100644 index 0000000..c89f174 Binary files /dev/null and b/vignettes/output-splitXLSX.PNG differ diff --git a/vignettes/rmd_template.PNG b/vignettes/rmd_template.PNG new file mode 100644 index 0000000..1e28ca5 Binary files /dev/null and b/vignettes/rmd_template.PNG differ diff --git a/vignettes/sample_report.PNG b/vignettes/sample_report.PNG new file mode 100644 index 0000000..06c6be5 Binary files /dev/null and b/vignettes/sample_report.PNG differ diff --git a/vignettes/statR_intro.Rmd b/vignettes/statR_intro.Rmd deleted file mode 100644 index a57e956..0000000 --- a/vignettes/statR_intro.Rmd +++ /dev/null @@ -1,123 +0,0 @@ ---- -title: "statR_intro" -output: rmarkdown::html_vignette -vignette: > - %\VignetteIndexEntry{statR_intro} - %\VignetteEngine{knitr::rmarkdown} - %\VignetteEncoding{UTF-8} ---- - -```{r, include = FALSE} -knitr::opts_chunk$set( - collapse = TRUE, - comment = "#>" -) -``` - - -statR-package enthält: - -- Das Stat ZH Theme (stat_theme()) für ggplot2 Grafiken -- Farbpaletten (zhpal) -- Farbpaletten-Funktionen für ggplot2 -- Funktionen um Datensätze aus R in formattierte und Kantons CD-konforme XLSX-files abzuspeichern. - -Zu jeder Funktion ist mittels Hilfe-Befehl (?) eine Beschreibung sowie ein Verwendungsbeispiel aufrufbar (z.B.: ?splitXLSX ) - -# Installation -Das Package liegt auf github und kann wiefolgt installiert werden. -```{r,echo=T,eval=T,message=F,warning=F} -library(pacman) - -#Variante 1 -library(downloader) -download("https://github.com/statistikZH/statR/archive/master.tar.gz", "statR.tar.gz") -install.packages("statR.tar.gz", repos = NULL, type = "source") - -#Lade package -library(statR) -``` - -```{r,echo=T,eval=F,message=F,warning=F} -#Variante 2 - -library(devtools) - -install_github("statistikZH/statR") - -``` - -# Theme - -Das ggplot2-theme ist darauf ausgelegt, sich gut ins kantonalen Corporate Design einzufügen. -```{r} -library(ggplot2) - -ggplot(mpg, aes(class,fill = drv))+geom_bar()+theme_stat() -``` - -# Farben -Das Farbpalettenobjekt zhpal, welches alle StatZH-Farbpaletten enthält, ist mit geladenem statR Package global verfügbar. - -```{r,echo=TRUE} -#Zeige Farben an -display(zhpal$zhdiagonal) - -#Mische 20 Farbtöne auf Basis der zhdiagonal-Palette -colorRampPalette((zhpal$zhdiagonal),space="Lab")(20) - -#Zeige die 20 Farben an -display(colorRampPalette((zhpal$zhdiagonal),space="Lab")(20)) - -#Alle Paletten auf einen Blick -display.statcol.all() - -#verwende die Paletten für kategoriale Daten mittels 'scale_fill_manual' -ggplot(mpg, aes(class,fill = drv))+geom_bar()+theme_stat()+scale_fill_manual(values=zhpal$zhblue) - -``` - -# Formattierte ZH Excel-Tabellen mit R - -statR enthält zwei Funktionen welche Daten in formatierte Excel-Dateien abfüllen. Die Funktionen bauen auf dem [openxlsx-package](https://github.com/awalker89/openxlsx) auf. - -##insert_worksheet - -Schreibt Daten aus R in eine XLSX-Tabelle mit einem einzelnen Arbeitsblatt. -```{r,echo=T,eval=F,error=F} - -#erstelle ein neues Workbook -wb <- openxlsx::createWorkbook("hello") - -#schreibe daten in ein neues sheet im bestehenden Workbook -insert_worksheet(mtcars[c(1:25),],wb) - -#speichere workbook als xlsx-Datei ab -openxlsx::saveWorkbook(wb, "file.xlsx", overwrite = TRUE) - -``` - -##quickXLSX - -Schreibt Daten aus R in eine XLSX-Tabelle mit einem einzelnen Arbeitsblatt. -```{r,echo=T,eval=F,error=F} -#Beschreibung & Anwendungsbeispiele via '?' -?quickXLSX - -#Speichere die obersten Zeilen des mtcars-Datensatzes als formatiertes XLSX File ab -quickXLSX(head(mtcars),"title of the spreadsheet") -``` - -##splitXLSX - -Die Funktion splitXLSX erlaubt es Daten aus R in einer XLSX-Tabelle mit mehreren Arbeitsblättern abspeichern. -Beispiel: Speichere die ersten 10 Zeilen des mtcars-Datemsatzes in mehreren Arbeitsblättern ab, ein Blatt pro Kategorie der 'carb'-Variable. Die Funktion eignet sich für Excel-Files welche pro Jahr oder pro Region etc. jeweils einzelne Arbeitsblätter enthalten sollen. -```{r,echo=T,eval=F} -#Beispiel mit Standardlogo (Logo des Statistischen Amtes ZH) -splitXLSX(mtcars[c(1:10),],"mtcars",carb,grouplines=c(1,5,6)) - -#Beispiel mit modifzierten Bemerkungen und eigenem Logo -splitXLSX(head(mtcars),carb, file="filename",grouplines = c(1,2,3), metadata = "remarks: ....",source="canton of zurich",logo="L:/STAT/08_DS/06_Diffusion/Logos_Bilder/LOGOS/STAT_LOGOS/nacht_map.png") - -``` - diff --git a/vignettes/zh_report.PNG b/vignettes/zh_report.PNG new file mode 100644 index 0000000..c30a3aa Binary files /dev/null and b/vignettes/zh_report.PNG differ