├── .gitattributes ├── .gitignore ├── LICENSE.md ├── README.md ├── data ├── plotdata.csv ├── simulating_data.R └── trees.csv ├── ggplot-intro.Rproj ├── ggplot_intro_paperplanes.Rmd ├── ggplot_intro_paperplanes.pdf ├── ggplot_intro_trees.Rmd ├── ggplot_intro_trees.pdf ├── ggplot_xaringan.Rmd ├── ggplot_xaringan.pdf ├── header.tex ├── images ├── CC-BY-NC-SA_logo.png ├── Statistical plots decision chart.jpg ├── aesthetics_Wilke.png ├── bike_pollution_web.png ├── cheatsheet.png ├── christmas_tree.png ├── cloropleth_rudis.png ├── egg.png ├── esquisse_code.png ├── gganimate.png ├── ggexts.PNG ├── ggplot2-tutorial-slides.045.png ├── ggraph1.png ├── ggrepel.png ├── ggtree.png ├── heatmap_rudis.png ├── learningcurve1.png ├── learningcurve2.png ├── network_plot_final.png ├── patchwork.PNG ├── plants.png ├── plants.png.REMOVED.git-id ├── so.png ├── so2.png ├── tidy-1.png ├── tidy-9.png ├── tidy-9b.png └── trevor_tweet.png └── plotly.Rmd /.gitattributes: -------------------------------------------------------------------------------- 1 | *.tex linguist-detectable=false 2 | *.Rmd linguist-language=R 3 | 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | knitr_output 6 | ggplot_intro.log 7 | ggplot_intro.tex 8 | ggplot_xaringan_cache 9 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## creative commons 2 | 3 | # Attribution-NonCommercial-ShareAlike 4.0 International 4 | 5 | Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. 6 | 7 | ### Using Creative Commons Public Licenses 8 | 9 | Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. 10 | 11 | * __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). 12 | 13 | * __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). 14 | 15 | ## Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License 16 | 17 | By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. 18 | 19 | ### Section 1 – Definitions. 20 | 21 | a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. 22 | 23 | b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. 24 | 25 | c. __BY-NC-SA Compatible License__ means a license listed at [creativecommons.org/compatiblelicenses](http://creativecommons.org/compatiblelicenses), approved by Creative Commons as essentially the equivalent of this Public License. 26 | 27 | d. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. 28 | 29 | e. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. 30 | 31 | f. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. 32 | 33 | g. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. 34 | 35 | h. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. 36 | 37 | i. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. 38 | 39 | h. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. 40 | 41 | i. __NonCommercial__ means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. 42 | 43 | j. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. 44 | 45 | k. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. 46 | 47 | l. __You__ means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. 48 | 49 | ### Section 2 – Scope. 50 | 51 | a. ___License grant.___ 52 | 53 | 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: 54 | 55 | A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and 56 | 57 | B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only. 58 | 59 | 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. 60 | 61 | 3. __Term.__ The term of this Public License is specified in Section 6(a). 62 | 63 | 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. 64 | 65 | 5. __Downstream recipients.__ 66 | 67 | A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. 68 | 69 | B. __Additional offer from the Licensor – Adapted Material.__ Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. 70 | 71 | C. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. 72 | 73 | 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). 74 | 75 | b. ___Other rights.___ 76 | 77 | 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. 78 | 79 | 2. Patent and trademark rights are not licensed under this Public License. 80 | 81 | 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. 82 | 83 | ### Section 3 – License Conditions. 84 | 85 | Your exercise of the Licensed Rights is expressly made subject to the following conditions. 86 | 87 | a. ___Attribution.___ 88 | 89 | 1. If You Share the Licensed Material (including in modified form), You must: 90 | 91 | A. retain the following if it is supplied by the Licensor with the Licensed Material: 92 | 93 | i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); 94 | 95 | ii. a copyright notice; 96 | 97 | iii. a notice that refers to this Public License; 98 | 99 | iv. a notice that refers to the disclaimer of warranties; 100 | 101 | v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; 102 | 103 | B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and 104 | 105 | C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. 106 | 107 | 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. 108 | 109 | 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. 110 | 111 | b. ___ShareAlike.___ 112 | 113 | In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. 114 | 115 | 1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. 116 | 117 | 2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. 118 | 119 | 3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. 120 | 121 | ### Section 4 – Sui Generis Database Rights. 122 | 123 | Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: 124 | 125 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; 126 | 127 | b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and 128 | 129 | c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. 130 | 131 | For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. 132 | 133 | ### Section 5 – Disclaimer of Warranties and Limitation of Liability. 134 | 135 | a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__ 136 | 137 | b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__ 138 | 139 | c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. 140 | 141 | ### Section 6 – Term and Termination. 142 | 143 | a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. 144 | 145 | b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: 146 | 147 | 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or 148 | 149 | 2. upon express reinstatement by the Licensor. 150 | 151 | For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. 152 | 153 | c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. 154 | 155 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. 156 | 157 | ### Section 7 – Other Terms and Conditions. 158 | 159 | a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. 160 | 161 | b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. 162 | 163 | ### Section 8 – Interpretation. 164 | 165 | a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. 166 | 167 | b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. 168 | 169 | c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. 170 | 171 | d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. 172 | 173 | ``` 174 | Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. 175 | 176 | Creative Commons may be contacted at creativecommons.org 177 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Workshop on data visualisation with ggplot2 2 | 3 | [Francisco Rodríguez-Sánchez](https://frodriguezsanchez.net) 4 | 5 | Download slides (PDF) [here](https://github.com/Pakillo/ggplot-intro/raw/master/ggplot_xaringan.pdf). See slides [here](https://github.com/Pakillo/ggplot-intro/blob/master/ggplot_xaringan.pdf) 6 | 7 | See slides source code (Rmarkdown) [here](https://github.com/Pakillo/ggplot-intro/blob/master/ggplot_xaringan.Rmd) 8 | 9 | 10 | ![](images/CC-BY-NC-SA_logo.png) 11 | -------------------------------------------------------------------------------- /data/plotdata.csv: -------------------------------------------------------------------------------- 1 | "plot","temp" 2 | 1,15.1 3 | 2,18 4 | 3,18.2 5 | 4,20.4 6 | 5,20 7 | 6,20.1 8 | 7,17.5 9 | 8,11.6 10 | 9,18.2 11 | 10,19 12 | -------------------------------------------------------------------------------- /data/simulating_data.R: -------------------------------------------------------------------------------- 1 | 2 | ## Generate fake dataset 3 | dbh <- runif(1000, 5, 50) 4 | hist(dbh) 5 | #temp <- runif(10, 5, 20) 6 | temp <- c(15.1, 18.0, 18.2, 20.4, 20.0, 20.1, 17.5, 11.6, 18.2, 19) 7 | #temp.c <- temp - mean(temp) 8 | plot.id <- seq(1:10) 9 | plot <- sample(plot.id, 1000, replace=T, 10 | prob=c(0.4, 0.2, 0.11, 0.1, 0.1, 0.05, 0.02, 0.01, 0.005, 0.005)) # proportion of total trees in each plot 11 | #intercs <- runif(10, 5, 20) # varying intercepts: height when dbh = 0 12 | intercs <- rnorm(10, 5 + 0.8*temp, 2) # varying intercepts: height when dbh = 0 13 | plot(temp, intercs) 14 | height <- rnorm(1000, intercs[plot] + 0.6*dbh, 3) 15 | plot(dbh, height) 16 | sex <- sample(c("male", "female"), size=1000, replace=T) 17 | dead <- rbinom(1000, 1, plogis(-4.5 + 0.04*dbh)) 18 | curve(plogis(-4.5 + 0.04*x), from=5, to=50) 19 | trees <- data.frame(plot=plot, dbh=round(dbh, digits=2), height=round(height, digits=1), sex=sex, dead=dead) 20 | write.csv(trees, file="trees.csv", row.names=F) 21 | plotdata <- data.frame(plot=plot.id, temp=round(temp, digits=2)) 22 | write.csv(plotdata, file="plotdata.csv", row.names=F) 23 | 24 | -------------------------------------------------------------------------------- /data/trees.csv: -------------------------------------------------------------------------------- 1 | "plot","dbh","height","sex","dead" 2 | 4,29.68,36.1,"male",0 3 | 5,33.29,42.3,"male",0 4 | 2,28.03,41.9,"female",0 5 | 5,39.86,46.5,"female",0 6 | 1,47.94,43.9,"female",0 7 | 1,10.82,26.2,"male",0 8 | 2,10.6,29.8,"male",0 9 | 2,20.12,35.6,"male",0 10 | 2,29.14,42.1,"male",0 11 | 1,29.55,36.5,"male",0 12 | 1,36.44,40.7,"male",0 13 | 1,15.64,34.4,"female",0 14 | 4,39.23,44.1,"male",0 15 | 1,20.05,30.8,"female",0 16 | 1,11.58,24.8,"female",0 17 | 1,21.05,32.2,"male",0 18 | 4,15.7,34.3,"female",0 19 | 5,24.57,39.3,"female",0 20 | 1,18.21,26.3,"female",0 21 | 1,34.69,39.4,"female",0 22 | 1,43.49,40.2,"male",0 23 | 5,18.43,33.7,"male",0 24 | 4,30.83,39.6,"male",0 25 | 10,29.15,37.5,"male",0 26 | 7,8.57,24.3,"male",0 27 | 2,34.88,46.9,"male",0 28 | 1,30.59,33.5,"female",0 29 | 1,36.93,36.9,"female",0 30 | 1,29.03,35.5,"male",0 31 | 2,12.83,30.6,"male",0 32 | 5,41.89,45.3,"female",0 33 | 2,32.04,44.1,"female",0 34 | 1,21.76,32,"female",0 35 | 1,46.84,41.9,"female",1 36 | 1,32.62,36.5,"female",0 37 | 1,18.69,32,"male",0 38 | 1,43.53,46.2,"male",0 39 | 3,5.14,20.2,"female",0 40 | 7,26.4,33.3,"male",0 41 | 1,48.04,46.8,"male",0 42 | 2,16.26,37.6,"female",0 43 | 4,31.84,35.9,"male",0 44 | 1,42.57,41.2,"male",0 45 | 6,15.37,30.1,"male",0 46 | 1,16.38,21.4,"female",0 47 | 1,28.89,36.8,"male",1 48 | 1,12.78,26.6,"female",0 49 | 2,15.66,34.4,"female",0 50 | 5,31.76,39.3,"male",0 51 | 3,43.51,51.9,"male",0 52 | 2,31.04,45.8,"female",0 53 | 1,9.9,15.9,"male",0 54 | 3,49.92,53.9,"female",0 55 | 1,34.56,34.1,"male",0 56 | 1,6.02,21.1,"male",0 57 | 2,38.75,42.9,"female",0 58 | 4,12.56,29,"female",0 59 | 1,16.98,32,"female",0 60 | 5,18.51,32.8,"female",0 61 | 1,25.17,33.9,"female",0 62 | 8,17.89,25.3,"male",0 63 | 6,43.32,50,"female",1 64 | 3,30.15,36.2,"female",0 65 | 1,47.08,46.8,"male",0 66 | 2,17.5,34.9,"female",0 67 | 3,23.02,34.5,"male",0 68 | 1,14.38,25.6,"female",0 69 | 3,40.28,43.6,"female",1 70 | 6,30.64,40.6,"male",0 71 | 9,18.05,35.1,"male",0 72 | 1,31.02,34.9,"male",1 73 | 2,23.9,46.4,"male",0 74 | 3,25.99,35.5,"female",0 75 | 4,44.64,44,"male",1 76 | 4,39.25,47.1,"male",0 77 | 2,45.85,49.3,"male",1 78 | 6,9.61,26.2,"male",0 79 | 5,20.68,28.5,"male",0 80 | 1,22.03,30.8,"male",0 81 | 1,31.83,36.7,"male",0 82 | 6,21.69,38.6,"male",0 83 | 1,39.84,37.8,"male",0 84 | 1,29.58,27.3,"male",0 85 | 1,21.5,29.4,"male",0 86 | 2,6.93,26.8,"male",0 87 | 1,29.91,37.6,"male",0 88 | 6,38.75,44.3,"male",0 89 | 4,9.25,21.9,"male",0 90 | 1,28.63,33,"male",0 91 | 2,24.62,36.6,"male",0 92 | 2,48.61,55,"female",0 93 | 3,33.17,39.9,"female",0 94 | 2,47.94,56.8,"male",0 95 | 2,10.74,27.8,"female",0 96 | 1,47.28,42.2,"female",0 97 | 1,7.55,21.9,"male",0 98 | 2,15.01,31.8,"female",0 99 | 8,29.31,34.6,"female",0 100 | 3,19.01,32.4,"male",0 101 | 1,37.4,36.6,"female",0 102 | 6,33.32,42.5,"male",0 103 | 1,13.85,22.8,"male",0 104 | 5,28.83,35.4,"female",0 105 | 2,9.9,23.1,"male",0 106 | 2,47.41,51.1,"male",0 107 | 1,15.81,29.9,"male",0 108 | 1,23.6,29.9,"female",0 109 | 4,13.01,27.1,"female",0 110 | 5,10.44,29.4,"male",0 111 | 2,29,38.4,"female",0 112 | 9,29.23,34.1,"female",0 113 | 3,7.06,27.5,"female",0 114 | 5,36.91,45.8,"male",0 115 | 1,29.78,34.5,"female",0 116 | 5,14.2,28.9,"female",0 117 | 2,46.16,51.5,"male",0 118 | 2,29.48,41.4,"female",0 119 | 4,34.57,37.4,"female",0 120 | 2,35.22,43.5,"female",0 121 | 10,20.78,32.2,"male",0 122 | 6,42.99,50.8,"male",1 123 | 1,14.09,22.3,"female",0 124 | 1,34.26,42.6,"male",0 125 | 3,21.32,34,"female",0 126 | 2,42.41,49.7,"female",0 127 | 2,21.71,36.9,"male",0 128 | 1,32.8,34.1,"male",0 129 | 3,27.11,36.2,"female",0 130 | 1,43.8,44.3,"female",1 131 | 4,12.51,27.8,"female",0 132 | 6,25.61,37.6,"male",0 133 | 1,30.81,36.7,"male",0 134 | 2,20.93,31.2,"male",0 135 | 1,26.55,30.9,"male",0 136 | 3,45.43,49.4,"female",0 137 | 4,28.63,37.8,"male",0 138 | 1,46.26,47.8,"male",1 139 | 1,10.92,23.2,"female",0 140 | 2,35.93,45.5,"female",1 141 | 5,16.25,34.3,"female",0 142 | 2,5.66,33.4,"male",0 143 | 6,34.19,43.5,"female",0 144 | 1,7.88,13.4,"male",0 145 | 3,27.31,42.9,"female",0 146 | 5,10.73,29.2,"male",0 147 | 1,23.5,29.4,"female",0 148 | 3,20.73,38.8,"male",0 149 | 5,36.94,42.9,"female",0 150 | 1,33.62,41.7,"female",0 151 | 1,13.12,23.4,"female",0 152 | 2,22.41,39.6,"male",0 153 | 3,35.69,43.1,"female",0 154 | 2,20.6,36.9,"female",0 155 | 1,12.28,22.2,"male",0 156 | 3,39.77,42.6,"female",0 157 | 1,5.92,22.9,"male",0 158 | 4,5.06,22.4,"female",0 159 | 2,9.23,35.1,"female",0 160 | 1,22.25,31.2,"female",0 161 | 2,34.24,42.9,"female",0 162 | 1,19.06,29.2,"male",0 163 | 1,11.54,17.7,"male",0 164 | 2,8.75,27.5,"female",0 165 | 1,18.41,29.6,"male",0 166 | 1,46.63,45.9,"female",0 167 | 1,11.99,24.6,"female",0 168 | 6,46.32,52.3,"female",0 169 | 5,32.63,40.8,"female",0 170 | 5,46.55,50.5,"male",0 171 | 3,42.15,44.4,"male",0 172 | 6,22.08,35.7,"female",0 173 | 2,14.4,34.5,"female",0 174 | 1,11.93,25,"male",0 175 | 1,17.75,26.1,"male",0 176 | 6,31.64,42,"male",0 177 | 1,13.02,28.4,"female",0 178 | 1,33.84,37.7,"male",0 179 | 2,24.66,36.5,"female",0 180 | 7,35.7,40.7,"male",0 181 | 1,23.83,33.1,"male",0 182 | 1,34.61,39.5,"male",0 183 | 2,16.92,33.1,"female",0 184 | 1,44.52,42.8,"male",0 185 | 1,14.01,26.3,"male",0 186 | 2,42.01,45.7,"female",0 187 | 1,43.35,42,"female",0 188 | 7,41.21,41,"male",0 189 | 2,12.76,31.9,"female",0 190 | 1,17.26,26.1,"female",0 191 | 1,39.49,42.2,"female",0 192 | 4,42.5,50.4,"male",0 193 | 1,42.37,39.9,"female",0 194 | 1,44.23,48.8,"male",0 195 | 1,28.32,29.7,"female",0 196 | 1,49.48,46.4,"female",0 197 | 4,49.81,45.8,"female",0 198 | 1,9.42,21.3,"male",0 199 | 5,9.56,28,"male",0 200 | 6,38.22,39.8,"male",0 201 | 3,43.24,44.9,"male",0 202 | 1,28.65,33.8,"female",0 203 | 4,20.74,31,"female",0 204 | 1,38.11,41.7,"female",0 205 | 1,8.63,24.9,"female",0 206 | 1,26.21,32.6,"male",0 207 | 3,37.59,41.3,"female",0 208 | 3,36.03,44,"female",0 209 | 2,31.97,43.1,"male",0 210 | 1,44.07,46.3,"male",0 211 | 5,46.24,48,"male",1 212 | 1,48.62,46.1,"female",0 213 | 4,48.78,43.4,"female",0 214 | 5,7.43,28,"male",0 215 | 5,31.9,42.1,"male",0 216 | 1,48.71,50.2,"male",0 217 | 4,22.31,25.5,"male",0 218 | 2,34.75,46.8,"female",0 219 | 1,19.95,28.3,"male",0 220 | 2,37.98,46.8,"male",0 221 | 2,23.59,40.3,"female",0 222 | 1,45.6,48.1,"male",0 223 | 2,24.64,37,"female",0 224 | 5,49.69,49.5,"male",0 225 | 1,14.92,28,"female",0 226 | 1,49.09,49.4,"male",0 227 | 1,31.24,38.6,"female",0 228 | 4,16.53,27,"female",0 229 | 2,30.83,39.7,"male",0 230 | 3,31.29,38.7,"male",0 231 | 1,24.21,28.3,"male",0 232 | 1,20.49,27.1,"male",0 233 | 1,39.69,41.4,"male",0 234 | 2,16.98,34.2,"female",0 235 | 1,6.8,21.9,"female",0 236 | 6,40.64,47.5,"female",0 237 | 4,15.02,28,"male",0 238 | 4,11.29,24.7,"male",0 239 | 4,25.25,34.2,"male",0 240 | 2,36.43,48.2,"female",0 241 | 5,18.11,33.8,"male",0 242 | 1,41.37,43,"female",0 243 | 1,22.3,29.7,"female",0 244 | 1,34.43,37.5,"male",0 245 | 1,48.74,53.5,"female",0 246 | 1,48.55,48.7,"male",0 247 | 1,28.06,28.3,"male",0 248 | 5,33.34,40,"female",0 249 | 1,45.66,41.6,"male",0 250 | 5,28.35,42.5,"male",0 251 | 5,41.54,48,"female",0 252 | 1,20.39,24.8,"male",0 253 | 5,25.08,29.3,"female",0 254 | 1,26.13,28.3,"female",0 255 | 6,35.75,43.3,"male",0 256 | 2,42.57,41.7,"male",0 257 | 1,47.39,46.9,"male",0 258 | 1,40.44,45.4,"female",0 259 | 1,9.59,19.7,"female",0 260 | 2,40.66,42.8,"male",0 261 | 2,7.98,30.5,"female",0 262 | 2,8.16,33.3,"male",0 263 | 3,8.5,28.6,"male",0 264 | 2,9.19,30.2,"female",0 265 | 2,47.59,55.2,"female",0 266 | 1,34.49,33.5,"female",0 267 | 3,40.43,40.8,"male",0 268 | 2,24.77,37.4,"female",0 269 | 1,18.6,29.6,"female",0 270 | 3,42.48,44.9,"female",0 271 | 8,28.79,27.6,"female",0 272 | 1,45.29,42.2,"female",0 273 | 2,46.82,50.2,"male",0 274 | 1,27.37,31.6,"female",0 275 | 1,8.89,19.2,"female",0 276 | 1,41.49,45.6,"female",0 277 | 2,16.72,29.4,"female",0 278 | 1,34.99,37.3,"female",0 279 | 1,34.42,37.4,"male",0 280 | 3,20.69,31.5,"female",0 281 | 1,11.62,23.2,"male",0 282 | 2,20.4,36,"female",0 283 | 2,13.11,30.6,"female",0 284 | 5,29.28,39.3,"female",1 285 | 5,41.99,48.2,"female",0 286 | 4,42.52,43.6,"male",0 287 | 1,43.86,45.5,"male",0 288 | 1,39.63,38.5,"female",0 289 | 5,34.83,38.4,"female",0 290 | 4,11.54,25.2,"female",0 291 | 4,45.17,44.8,"female",0 292 | 1,46.1,44.2,"female",0 293 | 1,31.74,41.3,"female",0 294 | 5,48.62,50.3,"female",0 295 | 4,10.66,22.8,"male",0 296 | 1,41.62,40.4,"female",0 297 | 1,34.52,39.1,"male",0 298 | 1,18.45,26.7,"male",0 299 | 4,18.81,31,"female",0 300 | 1,34.99,37.7,"female",0 301 | 7,30.92,36.4,"male",0 302 | 3,30.61,37.7,"female",0 303 | 1,5.84,16.3,"female",0 304 | 2,5.21,33.3,"male",0 305 | 4,34.72,42.7,"female",1 306 | 6,14.18,29.3,"male",0 307 | 2,21.49,36.4,"female",0 308 | 2,37.79,48.5,"male",0 309 | 1,20.94,28.2,"female",0 310 | 5,34.32,37.2,"male",0 311 | 2,6.38,27,"female",0 312 | 2,30.89,44.4,"male",0 313 | 3,34.51,44.6,"male",0 314 | 1,42.78,41.2,"male",0 315 | 2,25.81,44.2,"female",0 316 | 6,35.55,43.8,"male",0 317 | 1,16.67,31.5,"female",0 318 | 1,36.74,40.7,"female",0 319 | 1,14,26.6,"male",0 320 | 4,40.5,39.6,"female",0 321 | 2,44.6,49.7,"female",0 322 | 1,33.64,37.2,"female",0 323 | 1,42.17,41.2,"female",0 324 | 3,7.88,27.3,"female",0 325 | 3,41.16,46.5,"male",0 326 | 5,44.61,50.1,"female",0 327 | 1,32.44,43.1,"male",0 328 | 1,34.52,37,"female",0 329 | 2,21.51,33.1,"female",0 330 | 4,33.24,44.4,"male",0 331 | 3,26.77,37.9,"female",0 332 | 1,46.25,47.7,"female",0 333 | 1,18.22,24.5,"male",0 334 | 4,43.78,45.3,"male",0 335 | 1,31.32,39.4,"male",0 336 | 2,40.99,48.9,"male",0 337 | 2,29.09,44.9,"female",0 338 | 1,30.49,39.6,"male",0 339 | 1,22.03,33.5,"male",0 340 | 5,41.55,47.5,"female",0 341 | 1,19.93,30.6,"male",0 342 | 5,36.91,46.8,"female",0 343 | 3,10.21,24.4,"female",0 344 | 5,16.42,30.2,"male",0 345 | 1,36.88,38.8,"female",0 346 | 4,14.24,27.9,"male",0 347 | 2,20,32.9,"male",0 348 | 1,23.86,30.6,"male",0 349 | 5,41.66,44.2,"male",0 350 | 2,30.08,43.8,"female",0 351 | 5,28.95,42.3,"male",0 352 | 1,32.4,38.4,"female",0 353 | 1,6.13,19.6,"male",0 354 | 6,10.68,26.4,"male",0 355 | 5,21.06,33.9,"male",0 356 | 2,31.62,39.9,"female",0 357 | 2,40.81,49.8,"female",0 358 | 1,7.15,20.9,"male",1 359 | 2,47.03,54,"male",0 360 | 1,33.98,35.4,"female",0 361 | 1,39.53,34.3,"female",0 362 | 2,26.46,38.8,"male",0 363 | 1,40.15,39.9,"female",0 364 | 2,39.38,54.6,"female",0 365 | 2,24.91,37.1,"male",0 366 | 1,10.26,23.4,"female",1 367 | 3,32.39,38.1,"male",0 368 | 1,40.95,45.1,"female",0 369 | 1,36.98,38,"male",0 370 | 5,23.46,24.7,"female",0 371 | 3,28.14,41.5,"female",0 372 | 1,27.63,33.7,"male",0 373 | 2,39.33,50.7,"male",0 374 | 4,18.85,23.1,"female",0 375 | 1,44.97,44.1,"female",0 376 | 1,33.64,39.8,"male",0 377 | 1,12.35,26.4,"male",0 378 | 2,18.56,35,"female",0 379 | 3,27.31,39.4,"male",0 380 | 4,6.34,24,"male",0 381 | 2,27.83,44.6,"female",0 382 | 1,21.42,33.2,"male",0 383 | 3,25.06,30.3,"male",0 384 | 1,20.49,32.5,"female",0 385 | 9,41.42,51.5,"female",0 386 | 4,20.75,33.6,"male",0 387 | 6,45.73,52.3,"male",0 388 | 1,11.31,25.8,"male",0 389 | 3,12.73,32.2,"female",0 390 | 7,42.52,45.8,"female",0 391 | 3,48.89,53.7,"female",0 392 | 5,8.95,25.4,"male",0 393 | 1,19.82,29.3,"male",1 394 | 1,15.51,21.6,"male",0 395 | 1,16.57,26.9,"male",0 396 | 1,46.26,46.3,"female",0 397 | 5,18.86,32.9,"female",0 398 | 2,41.82,48.8,"female",0 399 | 2,32.78,44.8,"male",0 400 | 3,25.12,35.7,"female",0 401 | 1,8.37,17.2,"male",0 402 | 7,25.59,36.6,"female",0 403 | 2,37.44,45.3,"female",0 404 | 2,36.59,50.4,"male",0 405 | 1,37.58,37.4,"male",0 406 | 1,23.14,31.8,"male",0 407 | 9,42.84,48.6,"female",0 408 | 8,43.4,40.8,"female",0 409 | 2,8.39,29.2,"female",0 410 | 2,27.02,34.9,"male",0 411 | 6,5.7,28.2,"female",0 412 | 1,20.87,25.9,"male",0 413 | 4,44.99,46.9,"male",0 414 | 3,33.33,40.3,"male",0 415 | 1,35,37.5,"male",0 416 | 1,28.61,32.5,"male",0 417 | 1,27.64,36.9,"male",0 418 | 3,35.84,40.8,"female",1 419 | 3,20.86,35.9,"female",0 420 | 3,48.57,52.4,"male",1 421 | 1,41.66,43.2,"male",0 422 | 2,37.62,40.8,"male",0 423 | 5,41.24,43.7,"female",0 424 | 1,9.55,22.8,"female",0 425 | 1,13.84,25.3,"male",0 426 | 1,44.82,45.9,"female",0 427 | 5,13.42,26.5,"female",0 428 | 7,7.62,19.2,"male",0 429 | 6,5.71,21.5,"female",0 430 | 1,23.03,33.5,"female",0 431 | 5,13.98,32,"female",0 432 | 4,12.22,25.3,"female",0 433 | 1,40.82,38.7,"male",0 434 | 2,21.55,38.4,"female",0 435 | 2,31.29,43.5,"female",0 436 | 5,43.69,42.7,"male",0 437 | 4,22.7,33.8,"female",0 438 | 1,23.34,30.2,"female",0 439 | 1,7.43,23.6,"female",0 440 | 1,37.41,36.2,"male",0 441 | 2,21.9,35.4,"female",0 442 | 3,40.79,49.7,"female",0 443 | 2,45.24,51.9,"male",0 444 | 5,36.44,44,"female",0 445 | 1,25.97,31.5,"female",0 446 | 1,47.48,49.4,"female",0 447 | 1,23.6,25.4,"male",0 448 | 3,8.23,27.6,"male",0 449 | 1,19.09,28.4,"female",0 450 | 2,16.31,32.2,"male",0 451 | 6,48.84,52,"female",0 452 | 2,7.68,30.4,"male",0 453 | 5,42.32,47.2,"male",0 454 | 1,45.9,46.2,"female",0 455 | 1,15.32,27.6,"female",0 456 | 1,5.96,18.4,"male",0 457 | 4,48.21,49.2,"male",0 458 | 1,6.72,19.6,"female",0 459 | 2,18.7,32.3,"male",0 460 | 5,45.69,51,"female",0 461 | 1,34.12,35.7,"male",0 462 | 5,34.19,41,"female",0 463 | 3,29.01,46.3,"male",0 464 | 1,31.23,36.7,"male",0 465 | 3,41.53,47.5,"male",0 466 | 3,45.05,51.5,"female",0 467 | 4,49.92,47.4,"female",0 468 | 1,10.39,26,"female",0 469 | 6,10.84,26.4,"female",0 470 | 1,34.34,35.3,"male",1 471 | 1,38.21,40,"male",0 472 | 4,26.51,37.8,"female",0 473 | 4,28.34,31.5,"female",0 474 | 5,19.73,34.2,"female",0 475 | 1,13.05,20.8,"female",0 476 | 1,6.19,19.1,"male",0 477 | 2,25.18,35.5,"male",0 478 | 1,22.92,31.6,"female",0 479 | 6,42.06,46.5,"female",0 480 | 2,22.11,41.3,"male",0 481 | 9,33.52,43.5,"female",0 482 | 1,19.92,30,"male",0 483 | 3,32.6,38.1,"male",0 484 | 1,44.02,41.7,"male",0 485 | 1,14.85,33.3,"male",0 486 | 2,31.1,41.8,"female",0 487 | 2,33.91,44.9,"female",0 488 | 1,21.6,30.2,"female",0 489 | 1,26.69,32.8,"male",0 490 | 5,47.88,51.6,"female",0 491 | 1,44.54,46.9,"male",0 492 | 6,23.58,31.6,"male",0 493 | 2,29.59,35.2,"female",0 494 | 1,28.46,29.2,"female",0 495 | 5,44.35,48,"male",0 496 | 1,14.5,24.1,"female",0 497 | 4,19.63,27.5,"female",0 498 | 2,38.03,43.8,"female",0 499 | 1,21.1,34.1,"male",0 500 | 1,42.05,45.6,"male",0 501 | 6,7.52,28.4,"male",0 502 | 5,27.82,38.7,"female",0 503 | 1,47.41,44.2,"male",0 504 | 7,42.2,46.4,"female",0 505 | 1,13.45,31.1,"female",0 506 | 1,30.35,35.9,"female",0 507 | 1,37.22,30.3,"female",0 508 | 1,6.49,20,"female",0 509 | 1,17.19,22.6,"male",0 510 | 2,24.67,36.8,"male",0 511 | 4,48.97,46.3,"male",0 512 | 1,14.31,26.6,"male",0 513 | 6,29.68,34.1,"male",0 514 | 2,49.42,57.2,"male",0 515 | 2,21.23,32.9,"female",0 516 | 2,40.84,50.7,"female",0 517 | 2,36.91,40.2,"female",0 518 | 4,32.33,37.1,"male",0 519 | 3,21.89,35.3,"male",0 520 | 2,48.68,59.3,"female",0 521 | 1,49.88,50.2,"male",0 522 | 4,26.37,26.8,"male",0 523 | 2,14.12,36.9,"male",0 524 | 1,40.06,39.4,"female",0 525 | 4,21.16,35.2,"male",0 526 | 2,39.96,45,"male",0 527 | 3,9.52,25.8,"female",0 528 | 1,41.53,46.5,"male",0 529 | 2,36.2,41.7,"male",0 530 | 5,19.73,35.4,"male",0 531 | 3,22.31,42.2,"male",0 532 | 2,29.25,41.7,"male",0 533 | 6,28.19,33.9,"female",0 534 | 2,48.41,55.7,"male",0 535 | 1,42.51,45.7,"male",0 536 | 2,33.92,39.8,"female",0 537 | 1,30.73,35.2,"male",0 538 | 1,41.78,40.5,"male",1 539 | 5,11.12,29.1,"male",0 540 | 4,25.63,43.8,"female",0 541 | 1,11.25,17.5,"female",0 542 | 6,11.39,29.1,"male",0 543 | 7,28.75,33.3,"male",1 544 | 2,11.53,35.7,"male",0 545 | 6,40.47,46.5,"female",0 546 | 1,32.52,39.9,"female",0 547 | 5,28.87,35.1,"female",0 548 | 1,36.01,35.5,"female",0 549 | 1,42.32,43.4,"female",1 550 | 2,13.82,30.6,"female",0 551 | 1,31.43,42.9,"male",0 552 | 4,23.06,36.9,"female",0 553 | 1,7.24,20.9,"male",0 554 | 1,29.03,37.7,"male",0 555 | 2,38.05,49.5,"female",0 556 | 1,9.06,29.3,"male",0 557 | 2,20.55,33.2,"female",0 558 | 2,19.99,34.1,"male",0 559 | 4,11.17,22.5,"male",0 560 | 2,8.64,27.4,"female",0 561 | 6,22.77,27.8,"female",0 562 | 1,38.98,35.9,"female",0 563 | 1,49.55,49.6,"female",0 564 | 6,18.33,33,"female",0 565 | 1,12.88,27.2,"male",0 566 | 1,11.6,17.2,"male",0 567 | 7,26.95,30.6,"male",0 568 | 2,25.87,35,"female",1 569 | 1,40.45,39.4,"female",0 570 | 2,40.7,47.6,"female",0 571 | 4,29.6,37.7,"female",0 572 | 2,26.25,38.9,"male",0 573 | 1,34.3,32,"female",0 574 | 1,41.86,41.2,"female",0 575 | 5,25.82,37.1,"female",0 576 | 4,30.9,39.6,"female",0 577 | 1,28.79,35,"male",0 578 | 1,36.62,42.4,"male",0 579 | 5,41.06,46.5,"female",0 580 | 1,27.04,34,"female",0 581 | 2,7.32,27.3,"female",0 582 | 6,26.13,41,"male",1 583 | 1,45.12,49.1,"male",0 584 | 1,21.23,30.3,"male",0 585 | 2,27.98,42.6,"male",0 586 | 1,38.59,43.3,"female",0 587 | 1,14.43,20.9,"male",0 588 | 1,20.33,27.9,"male",1 589 | 1,44.32,50,"female",0 590 | 1,26.1,35.8,"male",0 591 | 2,19.59,39.5,"male",0 592 | 1,37.48,43.7,"female",0 593 | 6,36.05,42,"male",0 594 | 2,40.44,55,"female",0 595 | 3,21.09,30.9,"male",0 596 | 2,19.53,35,"male",0 597 | 2,18.91,37.5,"female",0 598 | 5,46.84,45.1,"female",0 599 | 7,48.27,46.9,"female",0 600 | 1,47.1,53.6,"female",0 601 | 3,12.43,27.4,"male",0 602 | 1,12.31,23.2,"female",0 603 | 1,49.24,48.5,"female",0 604 | 1,27.73,32.5,"male",0 605 | 1,29.58,33,"female",0 606 | 5,34.26,42.2,"female",0 607 | 2,44.93,48.9,"male",0 608 | 6,26.97,33,"male",0 609 | 5,37.88,48.7,"female",0 610 | 1,46.82,47.3,"male",0 611 | 1,16.08,25.5,"male",0 612 | 3,10.15,25.1,"female",0 613 | 5,19.03,36.6,"female",0 614 | 1,34.9,42.3,"male",0 615 | 3,5.24,19.1,"female",0 616 | 5,24.36,42.3,"male",0 617 | 2,41.59,48.8,"female",0 618 | 2,18.07,34.2,"male",0 619 | 1,26.92,31.2,"female",0 620 | 1,5.28,24,"female",0 621 | 2,46.91,51.2,"female",0 622 | 1,19.05,26.3,"female",0 623 | 1,20.82,27.5,"female",0 624 | 5,32.53,41,"male",0 625 | 3,45.27,52.4,"male",0 626 | 2,24.87,38.6,"male",0 627 | 1,13.87,27.2,"male",0 628 | 1,18.32,26.6,"female",0 629 | 2,46.18,50.7,"female",0 630 | 2,30.39,42.8,"male",0 631 | 4,27.87,32.7,"male",0 632 | 1,20.98,33.6,"male",0 633 | 2,7.11,28.2,"male",0 634 | 5,36.97,42.4,"male",0 635 | 6,33.5,40.1,"male",0 636 | 5,14.37,28.7,"female",0 637 | 1,45.99,39.2,"female",0 638 | 1,47.83,53.4,"male",0 639 | 6,18.15,28.6,"female",0 640 | 5,22.43,35.6,"female",0 641 | 4,14.41,25.4,"male",0 642 | 6,16.76,34.9,"female",0 643 | 5,26.06,35.6,"female",0 644 | 3,17.48,34.2,"female",0 645 | 2,39.01,44.7,"female",0 646 | 3,45.41,47.8,"female",0 647 | 1,13.07,23.8,"male",0 648 | 2,5.31,31,"male",0 649 | 10,43.06,43.1,"male",0 650 | 1,38.17,40.6,"female",0 651 | 5,49.83,49.2,"male",1 652 | 2,43.15,46.6,"male",0 653 | 2,5.91,26.6,"male",0 654 | 2,34.5,38.2,"female",0 655 | 1,41.51,43,"male",0 656 | 5,15.52,29.7,"male",0 657 | 6,23.91,33.2,"female",0 658 | 6,20.92,31.7,"male",0 659 | 7,39.08,38.6,"female",0 660 | 9,33.99,41.5,"female",0 661 | 1,32.96,39.5,"male",0 662 | 1,6.73,17.4,"male",0 663 | 5,12.76,21.3,"female",0 664 | 2,17.42,36.4,"female",0 665 | 1,29.43,33.7,"male",1 666 | 2,32.82,41.5,"female",0 667 | 2,47.38,56,"male",0 668 | 1,36.58,39,"male",0 669 | 1,33.08,36.4,"female",0 670 | 2,7.01,26.6,"male",0 671 | 1,18.13,26.7,"male",0 672 | 2,12.71,34.3,"male",0 673 | 2,15.42,32.8,"female",0 674 | 3,31.42,39.1,"male",0 675 | 1,29.28,32,"male",0 676 | 2,17.2,33.4,"female",0 677 | 2,26.34,46,"male",0 678 | 1,49.19,50.6,"male",0 679 | 4,9.21,27.4,"male",0 680 | 7,5.66,16,"male",0 681 | 2,9,32.6,"male",0 682 | 1,23.88,29.2,"male",0 683 | 2,11.46,28.9,"male",0 684 | 2,21.95,38.4,"female",0 685 | 8,37.85,35,"female",0 686 | 9,32.97,41.4,"male",0 687 | 1,29.65,31.9,"male",0 688 | 5,12.78,26.7,"male",0 689 | 3,40.33,49.1,"male",0 690 | 3,22.11,34.8,"female",0 691 | 2,26.25,40.8,"male",1 692 | 2,15.54,32.2,"female",0 693 | 5,29.27,35,"female",0 694 | 2,29.49,40.5,"female",0 695 | 8,31.39,33,"male",0 696 | 2,49.81,49.2,"female",0 697 | 10,11.42,26.6,"male",0 698 | 2,22.98,39.8,"male",0 699 | 2,41.8,44.9,"female",0 700 | 2,11.05,27,"male",0 701 | 1,20.13,28,"male",0 702 | 1,6.3,21.6,"male",0 703 | 1,28.46,36.4,"male",0 704 | 2,39.88,48,"male",1 705 | 2,36.56,46.3,"male",0 706 | 2,13.36,26.1,"male",0 707 | 2,30.01,44.6,"female",0 708 | 1,7.74,22.7,"male",0 709 | 1,39.89,45,"male",0 710 | 3,32.9,42.9,"female",1 711 | 3,49.85,52.4,"female",0 712 | 1,25.55,29,"female",0 713 | 1,41.46,35.7,"female",0 714 | 3,20.02,26.7,"male",0 715 | 6,48.08,53.7,"male",0 716 | 1,24.46,25.8,"male",0 717 | 1,48.69,44.7,"female",0 718 | 3,41.67,45.2,"female",0 719 | 4,26.85,34.7,"male",1 720 | 1,7.91,19.2,"male",0 721 | 5,44.07,45.2,"male",0 722 | 3,48.52,50.8,"male",0 723 | 1,37.75,38.3,"female",0 724 | 2,39.15,45.9,"female",0 725 | 5,39.08,45.6,"female",0 726 | 1,19.25,32.4,"male",0 727 | 1,34.91,34.9,"female",0 728 | 1,28.81,36.5,"female",0 729 | 5,21.76,36.7,"male",0 730 | 1,13.94,28.6,"male",0 731 | 1,46.05,48,"female",0 732 | 2,48.46,49.9,"female",0 733 | 2,48.62,53.7,"female",0 734 | 1,9.44,17.7,"male",0 735 | 1,20.57,23.2,"female",0 736 | 1,13.11,25.5,"male",0 737 | 1,28.3,34,"female",0 738 | 4,38.86,43.5,"male",0 739 | 2,27.33,37.9,"female",0 740 | 3,5.49,23.3,"male",0 741 | 1,26.16,30.3,"female",0 742 | 1,37.98,39.3,"female",0 743 | 6,21.59,36.4,"male",0 744 | 1,5.25,26.5,"male",0 745 | 2,48.25,53.5,"male",0 746 | 1,18,33.3,"female",0 747 | 1,22.08,28.7,"female",0 748 | 1,47.37,45.3,"female",0 749 | 2,13.64,37.1,"female",0 750 | 2,31.15,42.3,"male",0 751 | 1,48.14,45.7,"male",0 752 | 2,27.38,43,"female",0 753 | 1,15.31,23.3,"female",0 754 | 1,5.45,19,"female",0 755 | 7,6.13,17.4,"male",0 756 | 1,6.09,22.3,"male",0 757 | 1,46.75,50.9,"female",0 758 | 1,8.19,20.2,"female",0 759 | 1,8.55,23,"female",0 760 | 3,7.74,30.9,"male",0 761 | 1,46.74,45.2,"male",0 762 | 2,8.18,26.5,"female",0 763 | 2,41.18,49.9,"female",0 764 | 1,5.62,23.3,"male",0 765 | 5,15.38,27,"female",0 766 | 5,25.23,36.6,"female",0 767 | 1,48.52,44.4,"female",0 768 | 1,46.8,45.6,"female",0 769 | 2,17.18,32.1,"male",0 770 | 1,36.82,32.4,"female",0 771 | 6,33.74,43.4,"male",0 772 | 6,39.97,56.9,"male",0 773 | 1,20.15,26.1,"female",0 774 | 2,14.97,34.2,"female",0 775 | 5,43.07,50.1,"male",0 776 | 1,6.89,22.9,"male",0 777 | 5,10.32,25.3,"male",0 778 | 5,20.46,32.9,"female",0 779 | 5,15.12,23.4,"female",0 780 | 4,47.11,48.8,"male",0 781 | 3,28.3,38.3,"male",0 782 | 5,33.05,41.4,"male",0 783 | 2,13.4,35.9,"male",0 784 | 8,31.09,26,"female",0 785 | 4,5.59,23.9,"male",0 786 | 4,14.14,23.5,"male",0 787 | 1,31.75,36.9,"male",0 788 | 1,45.15,45.6,"female",1 789 | 1,8.54,17,"male",0 790 | 1,5.18,22.3,"male",0 791 | 3,33.84,45.3,"female",0 792 | 2,44.46,49.5,"female",0 793 | 1,26.53,32.2,"male",0 794 | 1,15.82,26.6,"female",0 795 | 1,39.01,39.9,"female",0 796 | 3,48.33,48.7,"male",1 797 | 2,8.47,29.8,"male",0 798 | 7,32.04,38.8,"female",0 799 | 1,29.37,38.7,"female",0 800 | 1,23.03,23.3,"female",0 801 | 1,49.38,47.7,"male",0 802 | 2,23.45,33.9,"male",0 803 | 1,40.05,42.6,"male",0 804 | 3,46.74,50.1,"female",0 805 | 2,48.51,55.1,"male",0 806 | 1,45.41,42.7,"male",0 807 | 3,12.32,32.5,"female",0 808 | 1,28.97,33.3,"female",0 809 | 1,7.35,22.3,"male",0 810 | 5,20.12,30.2,"male",0 811 | 2,12.49,31.9,"male",0 812 | 2,27.56,38.5,"female",0 813 | 4,7.97,25.1,"female",0 814 | 7,38.04,42.6,"female",0 815 | 1,34.32,39.1,"female",0 816 | 1,47.67,47.5,"male",0 817 | 1,21.71,27.9,"female",0 818 | 4,13.4,28.7,"male",0 819 | 2,19.28,31.9,"female",0 820 | 1,12.69,26.1,"male",0 821 | 2,44.52,47.7,"female",0 822 | 1,18.53,24.9,"female",0 823 | 4,32.79,31.1,"female",0 824 | 2,23.93,35.3,"female",0 825 | 5,47.51,56.3,"male",0 826 | 1,25.68,37.5,"female",0 827 | 7,19.68,27.5,"female",0 828 | 8,38.01,31.3,"female",0 829 | 5,31.13,39.7,"female",0 830 | 3,34.23,45,"female",0 831 | 6,16.05,33.9,"female",0 832 | 4,10.53,26.4,"female",0 833 | 2,9.89,29.1,"male",0 834 | 8,49.05,43.4,"female",0 835 | 1,6.97,21.8,"female",0 836 | 6,5.16,22.7,"female",0 837 | 1,7.84,24.9,"male",0 838 | 4,24.28,34.2,"male",1 839 | 5,21.67,34.8,"female",0 840 | 4,27.98,43.1,"male",0 841 | 2,23.6,32.5,"male",0 842 | 3,23.91,38.5,"female",0 843 | 1,22.67,31.7,"male",0 844 | 6,36.55,43.5,"female",0 845 | 10,11.44,26.9,"male",0 846 | 2,43.07,46,"male",0 847 | 6,33.08,47.4,"male",0 848 | 2,48.8,50.7,"female",0 849 | 1,27.05,30.6,"male",0 850 | 1,7.51,23.7,"female",0 851 | 4,28.97,38.2,"female",0 852 | 5,20.65,31.9,"male",0 853 | 7,31.37,36.8,"female",0 854 | 4,40.46,45.5,"female",0 855 | 3,20.78,34.3,"male",0 856 | 6,5.81,25,"female",0 857 | 2,26,38.8,"female",0 858 | 5,10.39,23.3,"male",0 859 | 2,10.59,29.5,"female",0 860 | 2,32.34,44.5,"female",0 861 | 1,40.15,37,"female",0 862 | 4,30.68,41.8,"male",1 863 | 4,22.98,35.1,"male",0 864 | 1,34.31,37.5,"male",0 865 | 6,23.77,34,"female",0 866 | 1,37.58,37.9,"male",0 867 | 3,18.88,36.4,"male",0 868 | 1,15.6,27,"male",0 869 | 5,34.04,42.3,"female",0 870 | 2,12.25,32.2,"male",0 871 | 3,47.61,53.1,"female",0 872 | 2,12.51,32.7,"female",0 873 | 6,42.94,44.9,"male",0 874 | 1,21.23,31.6,"male",0 875 | 2,29.59,39.6,"male",0 876 | 1,22.76,26.2,"female",0 877 | 4,5.48,23.8,"male",0 878 | 1,35.76,38.3,"male",0 879 | 2,48.64,53.1,"male",0 880 | 5,5.69,20.3,"male",0 881 | 1,48.93,46.9,"male",0 882 | 6,9.47,23.6,"female",0 883 | 1,27.48,34.3,"male",0 884 | 1,10.42,25.6,"male",0 885 | 4,33.5,35.3,"female",0 886 | 2,32.76,43,"female",0 887 | 4,14.03,18.6,"female",0 888 | 2,22.87,27.9,"female",0 889 | 1,42.42,45.2,"female",0 890 | 4,19.07,27.4,"male",0 891 | 1,31.9,34.8,"male",0 892 | 3,42.89,44.2,"male",0 893 | 3,34.44,39.1,"male",0 894 | 1,38.92,40.4,"female",0 895 | 1,37.1,38.9,"female",0 896 | 7,24.51,26.2,"male",0 897 | 4,28.93,32.8,"male",0 898 | 4,9.51,29.3,"female",0 899 | 6,30.74,39.6,"female",0 900 | 1,18.8,28.5,"male",0 901 | 2,14.03,30.9,"male",0 902 | 1,5.16,19.5,"male",0 903 | 6,49.09,54,"male",0 904 | 2,32.84,45.7,"female",0 905 | 5,33.02,38.5,"male",0 906 | 4,30.49,40.7,"female",0 907 | 2,28.74,39.7,"female",0 908 | 2,29.85,37.5,"male",0 909 | 2,32.28,37.1,"female",0 910 | 1,47.67,47.6,"male",0 911 | 3,21.57,36.5,"female",0 912 | 5,11.04,30.7,"female",0 913 | 3,14.77,27.9,"female",0 914 | 6,45.86,46,"female",0 915 | 4,22.42,31.7,"female",0 916 | 2,33.74,48,"male",0 917 | 1,24.76,34.7,"male",0 918 | 3,18.65,30.2,"female",0 919 | 1,18.16,24.4,"female",0 920 | 8,40.57,34.9,"male",0 921 | 1,21.1,31.4,"male",0 922 | 1,5.27,22.1,"male",0 923 | 1,34.55,33.8,"male",1 924 | 7,22.05,30,"female",0 925 | 5,36.53,39.7,"female",0 926 | 1,10.41,21,"male",0 927 | 3,34.72,42.1,"male",0 928 | 8,37.08,36,"female",1 929 | 3,42.07,49.9,"female",0 930 | 1,25.46,36.4,"female",0 931 | 4,5.18,23.8,"male",0 932 | 1,29.54,37.9,"male",0 933 | 1,25.95,32.7,"male",0 934 | 1,48.83,43.2,"male",0 935 | 3,31.1,39.5,"female",0 936 | 1,46.07,47.5,"female",0 937 | 1,36.65,41.7,"male",0 938 | 1,34.69,44.8,"female",0 939 | 1,41.73,40.1,"male",0 940 | 1,20.3,34.2,"male",0 941 | 4,39.7,44.8,"male",0 942 | 4,22.87,36.2,"male",0 943 | 1,35.64,40.7,"male",0 944 | 5,34,33.5,"male",0 945 | 5,42.88,46,"female",0 946 | 6,47.37,47.1,"male",1 947 | 2,22.67,38,"male",0 948 | 8,38.96,30,"female",0 949 | 6,44.24,42.7,"male",0 950 | 1,15.8,23.6,"female",1 951 | 1,12.03,23.1,"female",0 952 | 2,26.11,37.1,"male",0 953 | 1,10.68,21.5,"female",0 954 | 2,10.44,31.3,"male",0 955 | 1,40.75,40.3,"male",0 956 | 9,38.63,48.4,"female",0 957 | 4,13.58,24.2,"female",0 958 | 1,18.29,27.7,"male",0 959 | 4,18.12,32.1,"female",0 960 | 2,27.74,42,"female",0 961 | 4,36,35.3,"female",0 962 | 3,29.23,39.5,"male",0 963 | 2,7.82,26.7,"female",0 964 | 1,13.06,23.2,"male",0 965 | 1,28.76,36.8,"female",0 966 | 1,32.52,43.9,"female",0 967 | 5,32.78,41,"female",0 968 | 6,24.82,36.3,"female",0 969 | 5,39.92,41.5,"female",0 970 | 5,20.67,34.3,"female",0 971 | 5,39.09,42,"male",0 972 | 1,40.24,41.3,"male",0 973 | 2,45.57,55.8,"female",0 974 | 2,46.99,48.5,"male",1 975 | 2,47.27,54.4,"male",0 976 | 1,24.31,25.2,"female",0 977 | 2,29.85,42.6,"female",1 978 | 2,43.56,48.3,"male",0 979 | 1,16.63,29.5,"female",0 980 | 1,9.7,23.1,"male",0 981 | 1,47.38,51.7,"female",1 982 | 1,38.17,39,"male",0 983 | 2,12.04,28.9,"female",0 984 | 7,7.75,19.8,"female",0 985 | 1,41.96,45.8,"male",0 986 | 1,44.13,40.6,"male",0 987 | 4,36.9,46.7,"female",0 988 | 4,30.77,36.5,"male",0 989 | 4,31.78,39.5,"female",0 990 | 6,48.76,44.9,"male",1 991 | 4,6.63,22.1,"female",0 992 | 4,24.92,36,"female",0 993 | 2,44.42,46.7,"female",0 994 | 3,13,29.8,"male",0 995 | 2,39.17,44.6,"male",0 996 | 1,13.02,26.5,"male",0 997 | 2,21.34,40.9,"male",0 998 | 1,24.89,35.3,"female",0 999 | 3,9.75,25.1,"male",0 1000 | 3,21.06,32,"male",0 1001 | 2,29.47,44.3,"male",0 1002 | -------------------------------------------------------------------------------- /ggplot-intro.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | -------------------------------------------------------------------------------- /ggplot_intro_paperplanes.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Data visualisation with ggplot2" 3 | author: "Francisco Rodriguez-Sanchez (@frod_san)" 4 | fontsize: 9pt 5 | output: 6 | beamer_presentation: 7 | df_print: kable 8 | fig_caption: no 9 | fig_height: 2.5 10 | fig_width: 3.5 11 | includes: 12 | in_header: header.tex 13 | latex_engine: pdflatex 14 | slide_level: 2 15 | theme: metropolis 16 | --- 17 | 18 | 19 | ```{r knitr_setup, include=FALSE, cache=FALSE} 20 | 21 | library(knitr) 22 | 23 | ### Chunk options ### 24 | 25 | ## Text results 26 | opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, eval = TRUE, size = 'footnotesize') 27 | 28 | ## Code decoration 29 | opts_chunk$set(tidy = FALSE, comment = NA, highlight = TRUE, prompt = FALSE) 30 | 31 | # ## Cache 32 | #opts_chunk$set(cache = TRUE, cache.path = "knitr_output/cache/") 33 | 34 | # ## Plots 35 | #opts_chunk$set(fig.path = "knitr_output/figures/") 36 | opts_chunk$set(fig.align = 'center') 37 | 38 | ### Hooks ### 39 | ## Crop plot margins 40 | #knit_hooks$set(crop = hook_pdfcrop) 41 | 42 | ## Reduce font size 43 | # see http://stackoverflow.com/a/39961605 44 | knit_hooks$set(smallfont = function(before, options, envir) { 45 | if (before) return(paste0("\n \\", options$size, "\n\n")) 46 | else return("\n\n \\normalsize \n") 47 | }) 48 | 49 | ``` 50 | 51 | 52 | ## Always plot data! 53 | 54 | ```{r echo=FALSE} 55 | library(ggplot2) 56 | library(datasauRus) 57 | ggplot(subset(datasaurus_dozen, dataset != "x_shape"), aes(x = x, y = y)) + 58 | facet_wrap(~dataset, ncol = 4) + 59 | geom_point(size = 1) + 60 | theme_bw() + 61 | theme(legend.position = "none", strip.text = element_blank()) 62 | 63 | ``` 64 | 65 | https://github.com/stephlocke/datasauRus 66 | 67 | 68 | 69 | ## Made with ggplot 70 | 71 | ```{r} 72 | include_graphics("images/ggraph1.png") 73 | ``` 74 | 75 | https://github.com/thomasp85/ggraph 76 | 77 | 78 | ## Made with ggplot 79 | 80 | ```{r} 81 | include_graphics("images/bike_pollution_web.png") 82 | ``` 83 | 84 | http://spatial.ly/2012/02/great-maps-ggplot2/ 85 | 86 | 87 | ## Made with ggplot 88 | 89 | ```{r out.height="3in", out.width="4in"} 90 | include_graphics("images/heatmap_rudis.png") 91 | ``` 92 | 93 | https://rud.is/b/2016/02/14/making-faceted-heatmaps-with-ggplot2/ 94 | 95 | 96 | ## Made with ggplot 97 | 98 | ```{r out.height="3in", out.width="4in"} 99 | include_graphics("images/cloropleth_rudis.png") 100 | ``` 101 | 102 | https://rud.is/b/2016/03/29/easier-composite-u-s-choropleths-with-albersusa/ 103 | 104 | 105 | 106 | ## Made with ggplot 107 | 108 | ```{r} 109 | include_graphics("images/ggtree.png") 110 | ``` 111 | 112 | https://guangchuangyu.github.io/ggtree/ 113 | 114 | 115 | ## Made with ggplot 116 | 117 | ```{r} 118 | include_graphics("images/plants.png") 119 | ``` 120 | 121 | https://github.com/marcusvolz/mathart 122 | 123 | 124 | ## Why ggplot 125 | 126 | - Extremely powerful and flexible 127 | 128 | - Consistent (grammar of graphics) 129 | 130 | - Very powerful user base and active development 131 | 132 | 133 | ## At the beginnning it's hard, but then it pays off 134 | 135 | \begincols 136 | \begincol 137 | ```{r out.width="2in", out.height="2in"} 138 | include_graphics("images/learningcurve1.png") 139 | ``` 140 | \endcol 141 | 142 | \begincol 143 | ```{r out.width="2in", out.height="2in"} 144 | include_graphics("images/learningcurve2.png") 145 | ``` 146 | \endcol 147 | \endcols 148 | 149 | Source: https://github.com/jennybc/ggplot2-tutorial 150 | 151 | 152 | ## Very good documentation and tutorials 153 | 154 | 155 | - [Official ggplot2 documentation](https://ggplot2.tidyverse.org/reference/) 156 | - [ggplot2 book](https://github.com/hadley/ggplot2-book) 157 | - [R graphics cookbook](http://shop.oreilly.com/product/0636920023135.do) and [Cookbook for R](http://www.cookbook-r.com/Graphs/) 158 | - [Beautiful plotting in R: A ggplot2 cheatsheet](http://zevross.com/blog/2014/08/04/beautiful-plotting-in-r-a-ggplot2-cheatsheet-3/) 159 | - [Introduction to ggplot2](https://opr.princeton.edu/workshops/Downloads/2015Jan_ggplot2Koffman.pdf) 160 | - [Tutorial: ggplot2](http://bbs.ceb-institute.org/wp-content/uploads/2011/09/handout_ggplot2.pdf) 161 | - [How to format plots for publication using ggplot2](http://www.noamross.net/blog/2013/11/20/formatting-plots-for-pubs.html) 162 | - [Visualising data with ggplot2](https://onepager.togaware.com/GGPlot2O.pdf) 163 | - [Data Visualization with R and ggplot2](https://github.com/pablobarbera/Rdataviz) 164 | - [ggplot2 tutorial](https://github.com/jennybc/ggplot2-tutorial) 165 | - [Data visualisation chapter in R for Data Science](http://r4ds.had.co.nz/data-visualisation.html) 166 | - [The complete ggplot2 tutorial](http://r-statistics.co/Complete-Ggplot2-Tutorial-Part1-With-R-Code.html) 167 | - [Data visualization: a practical introduction (K. Healy)](http://socviz.co/) 168 | - [Fundamentals of data visualization (C. Wilke)](http://serialmentor.com/dataviz/) 169 | 170 | 171 | ## Cheatsheet 172 | 173 | ```{r} 174 | include_graphics("images/cheatsheet.png") 175 | ``` 176 | 177 | https://www.rstudio.com/resources/cheatsheets/ 178 | 179 | 180 | ## Repos of figures + code 181 | 182 | - [R graph catalog](http://shiny.stat.ubc.ca/r-graph-catalog/) 183 | 184 | - [From Data to Viz](https://www.data-to-viz.com/) 185 | 186 | - [The R graph gallery](http://www.r-graph-gallery.com/) 187 | 188 | - [R graph gallery](http://rgraphgallery.blogspot.com/) 189 | 190 | - [Cookbook for R: Graphs](http://www.cookbook-r.com/Graphs/) 191 | 192 | - [Graphical data analysis with R](http://www.gradaanwr.net/) 193 | 194 | - [IEG figures](https://github.com/PJordano-Lab/R-figures) 195 | 196 | 197 | 198 | 199 | ## Find answers for all your questions in Stack Overflow 200 | 201 | \begincols 202 | \begincol 203 | ```{r} 204 | include_graphics("images/so.png") 205 | ``` 206 | \endcol 207 | 208 | \begincol 209 | ```{r} 210 | include_graphics("images/so2.png") 211 | ``` 212 | \endcol 213 | \endcols 214 | 215 | 216 | 217 | 218 | 219 | 220 | # Building a ggplot figure 221 | 222 | ## Our example dataset: paper planes flying experiment 223 | 224 | ```{r echo=c(1,3)} 225 | library(paperplanes) 226 | data(paperplanes) 227 | head(paperplanes) 228 | ``` 229 | 230 | 231 | --- 232 | 233 | Ensuring `paper` is factor, not numeric 234 | 235 | ```{r echo=TRUE} 236 | paperplanes$paper <- as.factor(paperplanes$paper) 237 | ``` 238 | 239 | 240 | ## Data must be a tidy data frame 241 | 242 | ```{r out.width="3.5in", out.height="3.5in"} 243 | include_graphics("images/tidy-1.png") 244 | ``` 245 | 246 | ```{r out.width="3.5in", out.height="3.5in"} 247 | include_graphics("images/tidy-9b.png") 248 | ``` 249 | 250 | http://r4ds.had.co.nz/tidy-data.html 251 | 252 | 253 | ## Calling ggplot 254 | 255 | ```{r echo=TRUE, cache=FALSE} 256 | library(ggplot2) 257 | ggplot(paperplanes) 258 | ``` 259 | 260 | 261 | ----- 262 | 263 | ```{r eval=FALSE, echo=TRUE} 264 | ggplot(paperplanes) 265 | ``` 266 | 267 | First argument is a tidy data frame 268 | 269 | 270 | ## What variables as axes? 271 | 272 | ```{r echo=TRUE} 273 | ggplot(paperplanes) + 274 | aes(x = age, y = distance) 275 | ``` 276 | 277 | Note syntax: + followed by new line 278 | 279 | 280 | ---- 281 | 282 | ```{r echo=TRUE, eval=FALSE} 283 | ggplot(paperplanes) + 284 | aes(x = age, y = distance) 285 | ``` 286 | 287 | **Aesthetics** (`aes`) map data variables (*age*, *distance*) to graphic elements (*axes*) 288 | 289 | ```{r out.width="4in", out.height="3in"} 290 | include_graphics("images/aesthetics_Wilke.png") 291 | ``` 292 | 293 | http://serialmentor.com/dataviz/aesthetic-mapping.html 294 | 295 | 296 | 297 | 298 | 299 | ## Adding layers (geoms) 300 | 301 | ```{r echo=TRUE, eval=TRUE} 302 | ggplot(paperplanes) + 303 | aes(x = age, y = distance) + 304 | geom_point() 305 | ``` 306 | 307 | 308 | ## Changing point size and type 309 | 310 | ```{r echo=TRUE} 311 | ggplot(paperplanes) + 312 | aes(x = age, y = distance) + 313 | geom_point(size = 2) 314 | ``` 315 | 316 | Check out `geom_point` help [here](https://ggplot2.tidyverse.org/reference/geom_point.html) 317 | 318 | 319 | ## Changing point size and type 320 | 321 | ```{r echo=TRUE} 322 | ggplot(paperplanes) + 323 | aes(x = age, y = distance) + 324 | geom_point(size = 2, shape = 8) 325 | ``` 326 | 327 | 328 | ## Changing point size and type 329 | 330 | ```{r echo=TRUE} 331 | ggplot(paperplanes) + 332 | aes(x = age, y = distance) + 333 | geom_point(size = 2, shape = 16, colour = "blue") 334 | ``` 335 | 336 | 337 | ## Map geom aesthetics (e.g. colour) to variable 338 | 339 | ```{r echo=TRUE} 340 | ggplot(paperplanes) + 341 | aes(x = age, y = distance) + 342 | geom_point(aes(colour = paper)) 343 | ``` 344 | 345 | 346 | ---- 347 | 348 | Note difference between 349 | 350 | ```{r eval=FALSE, echo=TRUE} 351 | geom_point(colour = "blue") 352 | # colour is given a concrete value ('blue') 353 | ``` 354 | 355 | ```{r eval=FALSE, echo=TRUE} 356 | geom_point(aes(colour = gender)) 357 | # colour maps a *variable* (using `aes`) 358 | ``` 359 | 360 | 361 | ---- 362 | 363 | \begincols 364 | \begincol 365 | 366 | This works: 367 | 368 | ```{r echo=TRUE} 369 | ggplot(paperplanes) + 370 | aes(x = age, y = distance) + 371 | geom_point(aes(colour = paper)) 372 | ``` 373 | 374 | \endcol 375 | 376 | \begincol 377 | 378 | This doesn't work: 379 | 380 | ```{r echo=TRUE, eval=FALSE} 381 | ggplot(paperplanes) + 382 | aes(x = age, y = distance) + 383 | geom_point(colour = paper) 384 | ``` 385 | 386 | *Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint, : * 387 | *object 'paper' not found* 388 | 389 | . 390 | 391 | . 392 | 393 | 'paper' is a variable in dataframe 394 | 395 | . 396 | 397 | **Must use `aes`** 398 | 399 | \endcol 400 | \endcols 401 | 402 | 403 | 404 | 405 | ## Map geom aesthetics (colour, shape) to variable 406 | 407 | ```{r echo=TRUE} 408 | ggplot(paperplanes) + 409 | aes(x = age, y = distance) + 410 | geom_point(aes(colour = paper, shape = paper)) 411 | ``` 412 | 413 | 414 | ## Map geom aesthetics (colour, shape) to variable 415 | 416 | ```{r echo=TRUE} 417 | ggplot(paperplanes) + 418 | aes(x = age, y = distance) + 419 | geom_point(aes(colour = paper, shape = gender)) 420 | ``` 421 | 422 | 423 | ## Change colour scale 424 | 425 | ```{r echo=TRUE} 426 | ggplot(paperplanes) + 427 | aes(x = age, y = distance) + 428 | geom_point(aes(colour = paper)) + 429 | scale_colour_manual(values = c("orange", "blue")) 430 | ``` 431 | 432 | 433 | 434 | 435 | ```{r echo=FALSE, eval=FALSE} 436 | ggplot(paperplanes) + 437 | aes(x = age, y = distance) + 438 | geom_point(aes(colour = paper)) + 439 | scale_colour_brewer(type = "qual", palette = 6) 440 | ``` 441 | 442 | 443 | 444 | ## Change axis labels: xlab & ylab 445 | 446 | 447 | ```{r echo=TRUE} 448 | ggplot(paperplanes) + 449 | aes(x = age, y = distance) + 450 | geom_point(aes(colour = paper)) + 451 | labs(x = "Age (years)", y = "Distance (m)") 452 | ``` 453 | 454 | 455 | 456 | ## Set title 457 | 458 | ```{r echo=TRUE} 459 | ggplot(paperplanes) + 460 | aes(x = age, y = distance) + 461 | geom_point(aes(colour = paper)) + 462 | labs(x = "Age (years)", y = "Distance (m)") + 463 | labs(title = "Distance flown by age") 464 | ``` 465 | 466 | 467 | ## Adding more layers 468 | 469 | ```{r echo=TRUE} 470 | ggplot(paperplanes) + 471 | aes(x = age, y = distance) + 472 | geom_point() + 473 | geom_smooth(method = "lm") 474 | ``` 475 | 476 | 477 | ## Adding more layers 478 | 479 | ```{r echo=1} 480 | ggplot(paperplanes) + 481 | aes(x = age, y = distance) + 482 | geom_point() + 483 | geom_smooth(method = "lm") + 484 | geom_vline(xintercept = c(20, 40, 60)) 485 | ``` 486 | 487 | 488 | ## Adding more layers 489 | 490 | ```{r echo=1} 491 | ggplot(paperplanes) + 492 | aes(x = age, y = distance) + 493 | geom_point() + 494 | geom_smooth(method = "lm") + 495 | geom_vline(xintercept = c(20, 40, 60)) + 496 | geom_hline(yintercept = 10) 497 | ``` 498 | 499 | 500 | ## Summary 501 | 502 | ```{r eval=FALSE, echo=TRUE} 503 | ggplot(paperplanes) + # Name of (tidy) data frame 504 | aes(x = age, y = distance) + # Aesthetics (variables to map in axes) 505 | geom_point() # Geoms: geometric objects 506 | ``` 507 | 508 | 509 | 510 | ## Exercise: Make a plot like this one 511 | 512 | ```{r} 513 | ggplot(paperplanes) + 514 | aes(x = gender, y = distance) + 515 | geom_boxplot() + 516 | labs(x = "Gender", y = "Distance (m)", 517 | title = "Distance flown by gender") 518 | ``` 519 | 520 | 521 | ## Exercise: Make a plot like this one 522 | 523 | ```{r} 524 | ggplot(paperplanes) + 525 | aes(x = gender, y = distance) + 526 | geom_violin() + 527 | labs(x = "Gender", y = "Distance (m)", 528 | title = "Distance flown by gender") 529 | ``` 530 | 531 | 532 | ## Exercise: Make a plot like this one 533 | 534 | ```{r} 535 | ggplot(paperplanes) + 536 | aes(x = gender, y = distance) + 537 | geom_violin(fill = "orange") + 538 | geom_point() + 539 | labs(x = "Gender", y = "Distance (m)", 540 | title = "Distance flown by gender") 541 | ``` 542 | 543 | 544 | ## Exercise: Make a plot like this one 545 | 546 | ```{r} 547 | ggplot(paperplanes) + 548 | aes(x = distance) + 549 | geom_density(aes(colour = gender, fill = gender), alpha = 0.5) + 550 | labs(x = "Distance (m)", 551 | title = "Distances flown by gender") 552 | ``` 553 | 554 | 555 | ## Exercise: Make a plot like this one 556 | 557 | ```{r} 558 | ggplot(paperplanes) + 559 | aes(x = age, y = distance, colour = paper) + 560 | geom_point() + 561 | geom_smooth(method = "lm") 562 | ``` 563 | 564 | 565 | 566 | # ggplot2 figures can be assigned to R objects 567 | 568 | ## Assigning ggplot objects 569 | 570 | ```{r echo=TRUE} 571 | myplot <- ggplot(paperplanes) + 572 | aes(x = age, y = distance) 573 | myplot + geom_point() 574 | ``` 575 | 576 | 577 | ## Assigning ggplot objects 578 | 579 | ```{r echo=TRUE} 580 | myplot <- ggplot(paperplanes) + 581 | aes(x = age, y = distance) 582 | myplot <- myplot + geom_point() 583 | myplot 584 | ``` 585 | 586 | 587 | ## Assigning ggplot objects 588 | 589 | ```{r echo=TRUE} 590 | baseplot <- ggplot(paperplanes) + 591 | aes(x = age, y = distance) 592 | scatterplot <- baseplot + geom_point() 593 | labelled <- scatterplot + labs(x = "Age (years)", y = "Distance (m)") 594 | labelled 595 | ``` 596 | 597 | 598 | 599 | 600 | 601 | 602 | # Themes: changing plot appearance 603 | 604 | 605 | ## myplot 606 | 607 | ```{r echo=1} 608 | myplot <- ggplot(paperplanes) + 609 | aes(x = age, y = distance, colour = paper) + 610 | geom_point() 611 | myplot 612 | ``` 613 | 614 | 615 | ## theme_classic 616 | 617 | ```{r echo=TRUE} 618 | myplot + theme_classic() 619 | ``` 620 | 621 | 622 | ## theme_minimal 623 | 624 | ```{r echo=TRUE} 625 | myplot + theme_minimal() 626 | ``` 627 | 628 | 629 | ## Lots of themes out there 630 | 631 | ```{r echo=TRUE} 632 | library(ggthemes) 633 | myplot + theme_economist() 634 | ``` 635 | 636 | 637 | 638 | ## Lots of themes out there 639 | 640 | ```{r echo=TRUE} 641 | myplot + theme_wsj() 642 | ``` 643 | 644 | 645 | 646 | 647 | ## Editing themes 648 | 649 | ```{r echo=TRUE, eval=FALSE} 650 | ?theme 651 | ``` 652 | 653 | - `element_blank` 654 | - `element_text` 655 | - `element_line` 656 | - `element_rect` (borders & backgrounds) 657 | 658 | 659 | 660 | ## Exercise: make a plot like this one 661 | 662 | ```{r} 663 | ggplot(paperplanes) + 664 | aes(x = age, y = distance, colour = paper) + 665 | geom_point() + 666 | labs(x = "Age (years)", y = "Distance (m)", 667 | title = "Changing plot appearance") + 668 | theme(axis.title.x = element_text(colour = "blue"), 669 | axis.title.y = element_text(colour = "red"), 670 | plot.title = element_text(size = 16), 671 | legend.key = element_rect(fill = "white"), 672 | legend.position = "bottom" 673 | ) 674 | ``` 675 | 676 | 677 | ## Easily changing appearance with ggthemeassist (Rstudio addin) 678 | 679 | https://github.com/calligross/ggthemeassist 680 | 681 | ```{r} 682 | myplot 683 | ``` 684 | 685 | 686 | ## Easily changing appearance with ggedit 687 | 688 | https://github.com/metrumresearchgroup/ggedit 689 | 690 | ```{r} 691 | myplot 692 | ``` 693 | 694 | 695 | ## esquisse: ggplot2 builder addin 696 | 697 | https://github.com/dreamRs/esquisse 698 | 699 | [![](images/esquisse_code.png)](https://raw.githubusercontent.com/dreamRs/esquisse/master/man/figures/esquisse.gif) 700 | 701 | 702 | 703 | 704 | ## Think twice before editing plots out of R 705 | 706 | ```{r out.height="3in", out.width="4in"} 707 | include_graphics("images/trevor_tweet.png") 708 | ``` 709 | 710 | http://mbjoseph.github.io/2015/02/26/plotting.html 711 | 712 | serialmentor.com/dataviz/choosing-the-right-visualization-software.html 713 | 714 | 715 | ## Think twice before editing plots out of R 716 | 717 | Referee #3: "Please increase font size in all figures" 718 | 719 | ```{r echo=TRUE} 720 | myplot + 721 | theme(axis.title = element_text(size = 18)) 722 | ``` 723 | 724 | 725 | 726 | ## Publication-quality plots 727 | 728 | ```{r echo=TRUE} 729 | library(cowplot) 730 | myplot 731 | ``` 732 | 733 | 734 | ---- 735 | 736 | Some publication themes: 737 | 738 | https://gist.github.com/Pakillo/c2c7ea11c528cc2ee20f#themes 739 | 740 | 741 | 742 | 743 | # Composite figures 744 | 745 | ## Composite figures: cowplot 746 | 747 | ```{r echo=TRUE, out.width='4in', out.height='3in'} 748 | library(cowplot) 749 | plot1 <- ggplot(paperplanes) + aes(age, distance) + geom_point() 750 | plot2 <- ggplot(paperplanes) + aes(gender, distance) + geom_boxplot() 751 | plot_grid(plot1, plot2, labels = "AUTO") 752 | ``` 753 | 754 | 755 | ## Composite figures 756 | 757 | ```{r echo=3, out.width='3in', out.height='5in'} 758 | plot1 <- ggplot(paperplanes) + aes(age, distance) + geom_point() 759 | plot2 <- ggplot(paperplanes) + aes(gender, distance) + geom_boxplot() 760 | plot_grid(plot1, plot2, labels = "AUTO", ncol = 1) 761 | ``` 762 | 763 | 764 | ## Composite figures: patchwork 765 | 766 | ```{r} 767 | include_graphics("images/patchwork.PNG") 768 | ``` 769 | 770 | https://github.com/thomasp85/patchwork 771 | 772 | 773 | ## Composite figures: egg 774 | 775 | ```{r} 776 | include_graphics("images/egg.png") 777 | ``` 778 | 779 | https://cran.r-project.org/web/packages/egg/index.html 780 | 781 | 782 | 783 | ## Saving plot 784 | 785 | ```{r echo=TRUE, eval=FALSE} 786 | ggsave("myplot.pdf") 787 | ``` 788 | 789 | ```{r echo=TRUE, eval=FALSE} 790 | save_plot("myplot.pdf") 791 | ``` 792 | 793 | 794 | # Facetting (small multiples) 795 | 796 | ## Facetting 797 | 798 | ```{r echo=TRUE, out.width='3in', out.height='2.5in'} 799 | ggplot(paperplanes) + aes(age, distance) + 800 | geom_point() + theme_bw(base_size = 12) + 801 | facet_wrap(~paper) 802 | ``` 803 | 804 | 805 | 806 | ## Facetting 807 | 808 | ```{r echo=TRUE, out.width='3in', out.height='2.5in'} 809 | ggplot(paperplanes) + 810 | geom_histogram(aes(distance)) + 811 | theme_minimal(base_size = 8) + 812 | facet_wrap(~paper, nrow = 2) 813 | ``` 814 | 815 | 816 | ## Interactivity: plotly 817 | 818 | ```{r echo=TRUE, eval=FALSE} 819 | library(plotly) 820 | myplot <- ggplot(paperplanes) + 821 | aes(age, distance)) + 822 | geom_point() 823 | ggplotly(myplot) 824 | ``` 825 | 826 | 827 | ## Animated graphs 828 | 829 | https://github.com/thomasp85/gganimate 830 | 831 | [![](images/gganimate.png)](https://raw.githubusercontent.com/thomasp85/gganimate/master/man/figures/README-unnamed-chunk-4-1.gif) 832 | 833 | 834 | ## Automatic label placement 835 | 836 | ```{r} 837 | include_graphics("images/ggrepel.png") 838 | ``` 839 | 840 | https://cran.r-project.org/package=ggrepel 841 | 842 | 843 | ## Many extensions! 844 | 845 | https://www.ggplot2-exts.org/ 846 | 847 | ```{r} 848 | include_graphics("images/ggexts.PNG") 849 | ``` 850 | 851 | 852 | 853 | # Summary 854 | 855 | 856 | ## Grammar of graphics 857 | 858 | - **Data** (tidy data frame) 859 | 860 | - **Layers** (*geoms*: points, lines, polygons...) 861 | 862 | - **Aesthetics** mappings (x, y, size, colour...) 863 | 864 | - **Scales** (colour, size, shape...) 865 | 866 | - **Facets** (small multiples) 867 | 868 | - **Themes** (appearance) 869 | 870 | - **Coordinate system** (Cartesian, polar, map projections...) 871 | 872 | 873 | 874 | 875 | 876 | ## Exercise: make a plot like this one 877 | 878 | ```{r} 879 | ggplot(paperplanes) + 880 | aes(factor(paper), distance) + 881 | geom_violin() 882 | ``` 883 | 884 | 885 | 886 | ## Exercise: make a plot like this one 887 | 888 | ```{r fig.height=4, fig.width=5} 889 | ggplot(paperplanes) + 890 | aes(age, distance) + 891 | geom_point() + 892 | geom_smooth() + 893 | theme_minimal(base_size = 8) + 894 | facet_wrap(~gender, nrow = 2) + 895 | labs(x = "Age (years)", y = "Distance (m)", 896 | title = "Distance flown by age and gender") 897 | ``` 898 | 899 | 900 | ## Exercise: make a plot like this one 901 | 902 | ```{r fig.height=4, fig.width=5} 903 | ggplot(paperplanes) + 904 | aes(age, distance) + 905 | geom_point(aes(colour = gender)) + 906 | geom_smooth(aes(colour = gender)) + 907 | theme_minimal(base_size = 12) + 908 | labs(x = "Age (years)", y = "Distance (m)", 909 | title = "Distance flown by age and gender") 910 | ``` 911 | 912 | 913 | ## Exercise: make a plot like this one 914 | 915 | ```{r out.height="3.5in"} 916 | ggplot(paperplanes) + 917 | geom_histogram(aes(age)) + 918 | facet_wrap(~gender, nrow = 2) + 919 | labs(x = "Age (years)", y = "Number of individuals", 920 | title = "Age distribution per gender") + 921 | theme(plot.title = element_text(hjust = 0.5)) 922 | ``` 923 | 924 | 925 | 926 | ```{r include=FALSE, eval=FALSE} 927 | library(rotl) 928 | library(ggtree) 929 | lauraceae <- tnrs_match_names(c("Quercus suber", "Quercus ilex", "Pinus pinea", "Laurus nobilis")) 930 | lautree <- tol_induced_subtree(ott_ids = unlist(ott_id(lauraceae))) 931 | ggtree(lautree) + geom_tiplab() 932 | ``` 933 | 934 | 935 | ## Exercise: make a plot like this one 936 | 937 | Data from http://www.columbia.edu/~mhs119/Sensitivity+SL+CO2/Table.txt 938 | 939 | ```{r cache=TRUE, fig.width=6} 940 | hansen <- read.table("http://www.columbia.edu/~mhs119/Sensitivity+SL+CO2/Table.txt", 941 | header = FALSE, dec = ".", nrows = 17604, skip = 9) 942 | hansen <- hansen[, c(3,6)] 943 | names(hansen) <- c("MyrBP", "Tabs") 944 | hansen$logtime <- log10(hansen$MyrBP) 945 | 946 | 947 | timebreaks <- c(0.001, 0.01, 0.1, 1, 10, 66) # in MyrBP 948 | timebreaks.log <- log10(timebreaks) 949 | time.labels <- latex2exp::TeX(c("10^{-3}", "10^{-2}", 950 | "10^{-1}", "1", "10", "66")) 951 | 952 | temp <- ggplot(hansen, aes(x = logtime, y = Tabs)) + 953 | ylim(9, 30) + 954 | labs(x = "Millions of years BP", y = "Temperature (ºC)") + 955 | theme(axis.text.x = element_text(size = 10)) + 956 | geom_line(colour = "Dark Red") + 957 | scale_x_continuous(breaks = timebreaks.log, 958 | labels = time.labels, 959 | trans = "reverse") 960 | 961 | 962 | epochs.start <- c(0.0117, 2.58, 5.333, 23.03, 33.9, 56, 66) # from geoscale 963 | 964 | temp.paleo <- temp + 965 | geom_vline(xintercept = log10(epochs.start), linetype = "dashed", size = 0.2) + 966 | annotate("text", label = c("P", "Eo", "Ol", "Mi", "Pli", "Ple", "Hol"), 967 | x = c(1.78, 1.63, 1.44, 1.07, 0.58, -0.7, -2.9), 968 | y = 30, size = 3) 969 | temp.paleo 970 | ``` 971 | 972 | 973 | ## Exercise: make a plot like this one 974 | 975 | ```{r out.width="2in", out.height="3in"} 976 | include_graphics("images/christmas_tree.png") 977 | ``` 978 | 979 | 980 | ## END 981 | 982 | 983 | ![](images/CC-BY-NC-SA_logo.png) 984 | 985 | Slides and source code available at https://github.com/Pakillo/ggplot-intro 986 | 987 | 988 | -------------------------------------------------------------------------------- /ggplot_intro_paperplanes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/ggplot_intro_paperplanes.pdf -------------------------------------------------------------------------------- /ggplot_intro_trees.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Data visualisation with ggplot2" 3 | author: "Francisco Rodriguez-Sanchez (@frod_san)" 4 | fontsize: 9pt 5 | output: 6 | beamer_presentation: 7 | df_print: kable 8 | fig_caption: no 9 | fig_height: 2.5 10 | fig_width: 3.5 11 | includes: 12 | in_header: header.tex 13 | latex_engine: pdflatex 14 | slide_level: 2 15 | theme: metropolis 16 | --- 17 | 18 | 19 | ```{r knitr_setup, include=FALSE, cache=FALSE} 20 | 21 | library(knitr) 22 | 23 | ### Chunk options ### 24 | 25 | ## Text results 26 | opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, eval = TRUE, size = 'footnotesize') 27 | 28 | ## Code decoration 29 | opts_chunk$set(tidy = FALSE, comment = NA, highlight = TRUE, prompt = FALSE) 30 | 31 | # ## Cache 32 | #opts_chunk$set(cache = TRUE, cache.path = "knitr_output/cache/") 33 | 34 | # ## Plots 35 | #opts_chunk$set(fig.path = "knitr_output/figures/") 36 | opts_chunk$set(fig.align = 'center') 37 | 38 | ### Hooks ### 39 | ## Crop plot margins 40 | #knit_hooks$set(crop = hook_pdfcrop) 41 | 42 | ## Reduce font size 43 | # see http://stackoverflow.com/a/39961605 44 | knit_hooks$set(smallfont = function(before, options, envir) { 45 | if (before) return(paste0("\n \\", options$size, "\n\n")) 46 | else return("\n\n \\normalsize \n") 47 | }) 48 | 49 | ``` 50 | 51 | 52 | ## Always plot data! 53 | 54 | ```{r echo=FALSE} 55 | library(ggplot2) 56 | library(datasauRus) 57 | ggplot(subset(datasaurus_dozen, dataset != "x_shape"), aes(x = x, y = y)) + 58 | facet_wrap(~dataset, ncol = 4) + 59 | geom_point(size = 1) + 60 | theme_bw() + 61 | theme(legend.position = "none", strip.text = element_blank()) 62 | 63 | ``` 64 | 65 | https://github.com/stephlocke/datasauRus 66 | 67 | 68 | 69 | ## Made with ggplot 70 | 71 | ```{r} 72 | include_graphics("images/ggraph1.png") 73 | ``` 74 | 75 | https://github.com/thomasp85/ggraph 76 | 77 | 78 | ## Made with ggplot 79 | 80 | ```{r} 81 | include_graphics("images/bike_pollution_web.png") 82 | ``` 83 | 84 | http://spatial.ly/2012/02/great-maps-ggplot2/ 85 | 86 | 87 | ## Made with ggplot 88 | 89 | ```{r out.height="3in", out.width="4in"} 90 | include_graphics("images/heatmap_rudis.png") 91 | ``` 92 | 93 | https://rud.is/b/2016/02/14/making-faceted-heatmaps-with-ggplot2/ 94 | 95 | 96 | ## Made with ggplot 97 | 98 | ```{r out.height="3in", out.width="4in"} 99 | include_graphics("images/cloropleth_rudis.png") 100 | ``` 101 | 102 | https://rud.is/b/2016/03/29/easier-composite-u-s-choropleths-with-albersusa/ 103 | 104 | 105 | 106 | ## Made with ggplot 107 | 108 | ```{r} 109 | include_graphics("images/ggtree.png") 110 | ``` 111 | 112 | https://guangchuangyu.github.io/ggtree/ 113 | 114 | 115 | ## Made with ggplot 116 | 117 | ```{r} 118 | include_graphics("images/plants.png") 119 | ``` 120 | 121 | https://github.com/marcusvolz/mathart 122 | 123 | 124 | ## Why ggplot 125 | 126 | - Extremely powerful and flexible 127 | 128 | - Consistent (grammar of graphics) 129 | 130 | - Very powerful user base and active development 131 | 132 | 133 | ## At the beginnning it's hard, but then it pays off 134 | 135 | \begincols 136 | \begincol 137 | ```{r out.width="2in", out.height="2in"} 138 | include_graphics("images/learningcurve1.png") 139 | ``` 140 | \endcol 141 | 142 | \begincol 143 | ```{r out.width="2in", out.height="2in"} 144 | include_graphics("images/learningcurve2.png") 145 | ``` 146 | \endcol 147 | \endcols 148 | 149 | Source: https://github.com/jennybc/ggplot2-tutorial 150 | 151 | 152 | ## Very good documentation and tutorials 153 | 154 | 155 | - [Official ggplot2 documentation](https://ggplot2.tidyverse.org/reference/) 156 | - [ggplot2 book](https://github.com/hadley/ggplot2-book) 157 | - [R graphics cookbook](http://shop.oreilly.com/product/0636920023135.do) and [Cookbook for R](http://www.cookbook-r.com/Graphs/) 158 | - [Beautiful plotting in R: A ggplot2 cheatsheet](http://zevross.com/blog/2014/08/04/beautiful-plotting-in-r-a-ggplot2-cheatsheet-3/) 159 | - [Introduction to ggplot2](https://opr.princeton.edu/workshops/Downloads/2015Jan_ggplot2Koffman.pdf) 160 | - [Tutorial: ggplot2](http://bbs.ceb-institute.org/wp-content/uploads/2011/09/handout_ggplot2.pdf) 161 | - [How to format plots for publication using ggplot2](http://www.noamross.net/blog/2013/11/20/formatting-plots-for-pubs.html) 162 | - [Visualising data with ggplot2](https://onepager.togaware.com/GGPlot2O.pdf) 163 | - [Data Visualization with R and ggplot2](https://github.com/pablobarbera/Rdataviz) 164 | - [ggplot2 tutorial](https://github.com/jennybc/ggplot2-tutorial) 165 | - [Data visualisation chapter in R for Data Science](http://r4ds.had.co.nz/data-visualisation.html) 166 | - [The complete ggplot2 tutorial](http://r-statistics.co/Complete-Ggplot2-Tutorial-Part1-With-R-Code.html) 167 | - [Data visualization: a practical introduction (K. Healy)](http://socviz.co/) 168 | - [Fundamentals of data visualization (C. Wilke)](http://serialmentor.com/dataviz/) 169 | 170 | 171 | ## Cheatsheet 172 | 173 | ```{r} 174 | include_graphics("images/cheatsheet.png") 175 | ``` 176 | 177 | https://www.rstudio.com/resources/cheatsheets/ 178 | 179 | 180 | ## Repos of figures + code 181 | 182 | - [R graph catalog](http://shiny.stat.ubc.ca/r-graph-catalog/) 183 | 184 | - [From Data to Viz](https://www.data-to-viz.com/) 185 | 186 | - [The R graph gallery](http://www.r-graph-gallery.com/) 187 | 188 | - [R graph gallery](http://rgraphgallery.blogspot.com/) 189 | 190 | - [Cookbook for R: Graphs](http://www.cookbook-r.com/Graphs/) 191 | 192 | - [Graphical data analysis with R](http://www.gradaanwr.net/) 193 | 194 | - [IEG figures](https://github.com/PJordano-Lab/R-figures) 195 | 196 | 197 | 198 | 199 | ## Find answers for all your questions in Stack Overflow 200 | 201 | \begincols 202 | \begincol 203 | ```{r} 204 | include_graphics("images/so.png") 205 | ``` 206 | \endcol 207 | 208 | \begincol 209 | ```{r} 210 | include_graphics("images/so2.png") 211 | ``` 212 | \endcol 213 | \endcols 214 | 215 | 216 | 217 | 218 | # Building a ggplot figure 219 | 220 | ## Our example dataset: tree heights and DBH 221 | 222 | http://tinyurl.com/treesdata 223 | 224 | - One species 225 | - 10 plots 226 | - 1000 trees 227 | - Number of trees per plot ranging from 4 to 392 228 | 229 | ```{r echo=TRUE} 230 | trees <- read.csv("data/trees.csv") 231 | summary(trees[, 1:3]) 232 | ``` 233 | 234 | 235 | ## Data must be a tidy data frame 236 | 237 | ```{r out.width="3.5in", out.height="3.5in"} 238 | include_graphics("images/tidy-1.png") 239 | ``` 240 | 241 | 242 | ```{r out.width="3.5in", out.height="3.5in"} 243 | include_graphics("images/tidy-9b.png") 244 | ``` 245 | 246 | http://r4ds.had.co.nz/tidy-data.html 247 | 248 | 249 | ## Calling ggplot 250 | 251 | ```{r echo=TRUE, cache=FALSE} 252 | library(ggplot2) 253 | ggplot(trees) 254 | ``` 255 | 256 | 257 | ----- 258 | 259 | ```{r eval=FALSE, echo=TRUE} 260 | ggplot(trees) 261 | ``` 262 | 263 | First argument is a tidy data frame 264 | 265 | 266 | ## What variables as axes? 267 | 268 | ```{r echo=TRUE} 269 | ggplot(trees) + 270 | aes(x = dbh, y = height) 271 | ``` 272 | 273 | Note syntax: + followed by new line 274 | 275 | ---- 276 | 277 | ```{r echo=TRUE, eval=FALSE} 278 | ggplot(trees) + 279 | aes(x = dbh, y = height) 280 | ``` 281 | 282 | **Aesthetics** (`aes`) map data variables (*dbh*, *height*) to graphic elements (*axes*) 283 | 284 | ```{r out.width="4in", out.height="3in"} 285 | include_graphics("images/aesthetics_Wilke.png") 286 | ``` 287 | 288 | http://serialmentor.com/dataviz/aesthetic-mapping.html 289 | 290 | 291 | 292 | ## Adding layers (geoms) 293 | 294 | ```{r echo=TRUE, eval=TRUE} 295 | ggplot(trees) + 296 | aes(x = dbh, y = height) + 297 | geom_point() 298 | ``` 299 | 300 | 301 | ## Changing point size 302 | 303 | ```{r echo=TRUE} 304 | ggplot(trees) + 305 | aes(x = dbh, y = height) + 306 | geom_point(size = 2) 307 | ``` 308 | 309 | Check out `geom_point` help [here](https://ggplot2.tidyverse.org/reference/geom_point.html) 310 | 311 | 312 | 313 | ## Changing point size and type 314 | 315 | ```{r echo=TRUE} 316 | ggplot(trees) + 317 | aes(x = dbh, y = height) + 318 | geom_point(size = 2, shape = 18) 319 | ``` 320 | 321 | 322 | ## Changing point size and type 323 | 324 | ```{r echo=TRUE} 325 | ggplot(trees) + 326 | aes(x = dbh, y = height) + 327 | geom_point(size = 2, shape = 18, colour = 'blue') 328 | ``` 329 | 330 | 331 | ## Map geom aesthetics (e.g. colour) to variable 332 | 333 | ```{r echo=TRUE, fig.width=5} 334 | ggplot(trees) + 335 | aes(x = dbh, y = height) + 336 | geom_point(aes(colour = sex)) 337 | ``` 338 | 339 | 340 | 341 | ---- 342 | 343 | Note difference between 344 | 345 | ```{r eval=FALSE, echo=TRUE} 346 | geom_point(colour = "blue") 347 | # colour is given a concrete value ('blue') 348 | ``` 349 | 350 | ```{r eval=FALSE, echo=TRUE} 351 | geom_point(aes(colour = sex)) 352 | # colour maps a *variable* (using `aes`) 353 | ``` 354 | 355 | 356 | ---- 357 | 358 | \begincols 359 | \begincol 360 | 361 | This works: 362 | 363 | ```{r echo=TRUE} 364 | ggplot(trees) + 365 | aes(x = dbh, y = height) + 366 | geom_point(aes(colour = sex)) 367 | ``` 368 | 369 | \endcol 370 | 371 | \begincol 372 | 373 | This doesn't work: 374 | 375 | ```{r echo=TRUE, eval=FALSE} 376 | ggplot(trees) + 377 | aes(x = dbh, y = height) + 378 | geom_point(colour = sex) 379 | ``` 380 | 381 | *Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint, : * 382 | *object 'sex' not found* 383 | 384 | . 385 | 386 | . 387 | 388 | 'sex' is a variable in dataframe 389 | 390 | . 391 | 392 | **Must use `aes`** 393 | 394 | \endcol 395 | \endcols 396 | 397 | 398 | 399 | 400 | ## Map geom aesthetics (colour, shape) to variable 401 | 402 | ```{r echo=TRUE, fig.width=5} 403 | ggplot(trees) + 404 | aes(x = dbh, y = height) + 405 | geom_point(aes(colour = sex, shape = sex)) 406 | ``` 407 | 408 | 409 | ## Map geom aesthetics (colour, shape) to variable 410 | 411 | ```{r echo=TRUE} 412 | ggplot(trees) + 413 | aes(x = dbh, y = height) + 414 | geom_point(aes(colour = plot, shape = sex)) 415 | ``` 416 | 417 | 418 | ----- 419 | 420 | Ensuring 'plot' is a factor, not numeric 421 | 422 | ```{r echo=TRUE} 423 | trees$plot <- as.factor(trees$plot) 424 | ``` 425 | 426 | 427 | ## Map geom aesthetics (colour, shape) to variable 428 | 429 | ```{r echo=TRUE, fig.width=5} 430 | ggplot(trees) + 431 | aes(x = dbh, y = height) + 432 | geom_point(aes(colour = plot, shape = sex)) 433 | ``` 434 | 435 | 436 | 437 | ## Change colour scale 438 | 439 | ```{r echo=TRUE, fig.width=5} 440 | ggplot(trees) + 441 | aes(x = dbh, y = height) + 442 | geom_point(aes(colour = sex)) + 443 | scale_colour_manual(values = c("orange", "blue")) 444 | ``` 445 | 446 | 447 | 448 | ## Change axis labels: xlab & ylab 449 | 450 | ```{r echo=TRUE} 451 | ggplot(trees) + 452 | aes(x = dbh, y = height) + 453 | geom_point() + 454 | labs(x = "Diameter at Breast Height (cm)", y = "Height (m)") 455 | ``` 456 | 457 | 458 | 459 | ## Set title 460 | 461 | ```{r echo=TRUE, fig.width=5} 462 | ggplot(trees) + 463 | aes(x = dbh, y = height) + 464 | geom_point(aes(colour = sex)) + 465 | labs(x = "Diameter at Breast Height (cm)", y = "Height (m)") + 466 | labs(title = "Tree allometry") 467 | ``` 468 | 469 | 470 | ## Adding more layers 471 | 472 | ```{r echo=TRUE, fig.width=5} 473 | ggplot(trees) + 474 | aes(x = dbh, y = height) + 475 | geom_point() + 476 | geom_smooth(method = "lm") 477 | ``` 478 | 479 | 480 | ## Adding more layers 481 | 482 | ```{r echo=TRUE, fig.width=5} 483 | ggplot(trees) + 484 | aes(x = dbh, y = height) + 485 | geom_point() + 486 | geom_smooth(method = "lm") + 487 | geom_vline(xintercept = c(10, 20, 30, 40, 50)) 488 | ``` 489 | 490 | 491 | ## Adding more layers 492 | 493 | ```{r echo=TRUE, fig.width=5} 494 | ggplot(trees) + 495 | aes(x = dbh, y = height) + 496 | geom_point() + 497 | geom_smooth(method = "lm") + 498 | geom_vline(xintercept = c(10, 20, 30, 40, 50)) + 499 | geom_hline(yintercept = c(20, 30, 40, 50)) 500 | ``` 501 | 502 | 503 | 504 | ## Summary 505 | 506 | ```{r eval=FALSE, echo=TRUE} 507 | ggplot(trees) + # Name of (tidy) data frame 508 | aes(x = dbh, y = height) + # Aesthetics (variables to map in axes) 509 | geom_point() # Geoms: geometric objects 510 | ``` 511 | 512 | 513 | 514 | ## Exercise: Make a plot like this one 515 | 516 | ```{r fig.width=5} 517 | ggplot(trees) + 518 | aes(x = plot, y = height) + 519 | geom_boxplot() + 520 | labs(x = "Study plot", y = "Height (m)") + 521 | labs(title = "Tree heights per plot") 522 | ``` 523 | 524 | 525 | ## Exercise: Make a plot like this one 526 | 527 | ```{r fig.width=5} 528 | ggplot(trees) + 529 | aes(x = plot, y = height) + 530 | geom_violin() + 531 | labs(x = "Study plot", y = "Height (m)") + 532 | labs(title = "Tree heights per plot") + 533 | geom_point() 534 | ``` 535 | 536 | 537 | ## Exercise: Make a plot like this one 538 | 539 | ```{r fig.width=5} 540 | ggplot(trees) + 541 | aes(x = height) + 542 | geom_density(aes(colour = sex, fill = sex), alpha = 0.5) + 543 | labs(x = "Height (m)", title = "Distribution of heights") 544 | ``` 545 | 546 | 547 | ## Exercise: Make a plot like this one 548 | 549 | ```{r fig.width=5} 550 | ggplot(trees) + 551 | aes(x = dbh) + 552 | geom_density(aes(colour = sex, fill = sex), alpha = 0.5) + 553 | labs(x = "DBH (cm)", title = "Distribution of diameters") 554 | ``` 555 | 556 | 557 | 558 | ## Exercise: Make a plot like this one 559 | 560 | ```{r fig.width=5} 561 | ggplot(trees) + 562 | aes(x = dbh, y = height, colour = sex) + 563 | geom_point() + 564 | geom_smooth(method = "lm") 565 | ``` 566 | 567 | 568 | ## Exercise: Make a plot like this one 569 | 570 | ```{r fig.width=5} 571 | ggplot(trees) + 572 | aes(x = dbh, y = height) + 573 | geom_point() + 574 | geom_smooth(aes(colour = sex), method = "lm") 575 | ``` 576 | 577 | 578 | # ggplot2 figures can be assigned to R objects 579 | 580 | ## Assigning ggplot objects 581 | 582 | ```{r echo=TRUE} 583 | myplot <- ggplot(trees) + 584 | aes(x = dbh, y = height) 585 | myplot + geom_point() 586 | ``` 587 | 588 | 589 | ## Assigning ggplot objects 590 | 591 | ```{r echo=TRUE} 592 | myplot <- ggplot(trees) + 593 | aes(x = dbh, y = height) 594 | myplot <- myplot + geom_point() 595 | myplot 596 | ``` 597 | 598 | 599 | ## Assigning ggplot objects 600 | 601 | ```{r echo=TRUE} 602 | baseplot <- ggplot(trees) + 603 | aes(x = dbh, y = height) 604 | scatterplot <- baseplot + geom_point() 605 | labelled <- scatterplot + labs(x = "DBH (cm)", y = "Height (m)") 606 | labelled 607 | ``` 608 | 609 | 610 | 611 | 612 | # Themes: changing plot appearance 613 | 614 | 615 | ## myplot 616 | 617 | ```{r echo=1} 618 | myplot <- ggplot(trees) + 619 | aes(x = dbh, y = height) + 620 | geom_point() 621 | myplot 622 | ``` 623 | 624 | 625 | ## theme_classic 626 | 627 | ```{r echo=TRUE} 628 | myplot + theme_classic() 629 | ``` 630 | 631 | 632 | ## theme_minimal 633 | 634 | ```{r echo=TRUE} 635 | myplot + theme_minimal() 636 | ``` 637 | 638 | 639 | ## Lots of themes out there 640 | 641 | ```{r echo=TRUE} 642 | library(ggthemes) 643 | myplot + theme_economist() 644 | ``` 645 | 646 | 647 | 648 | ## Lots of themes out there 649 | 650 | ```{r echo=TRUE} 651 | myplot + theme_wsj() 652 | ``` 653 | 654 | 655 | 656 | ## Editing themes 657 | 658 | ```{r echo=TRUE, eval=FALSE} 659 | ?theme 660 | ``` 661 | 662 | - `element_blank` 663 | - `element_text` 664 | - `element_line` 665 | - `element_rect` (borders & backgrounds) 666 | 667 | 668 | 669 | ## Exercise: make a plot like this one 670 | 671 | ```{r fig.width=5} 672 | ggplot(trees) + 673 | aes(x = dbh, y = height, colour = sex) + 674 | geom_point() + 675 | labs(x = "DBH (cm)", y = "Height (m)") + 676 | labs(title = "Changing plot appearance") + 677 | theme(axis.title.x = element_text(colour = "blue"), 678 | axis.title.y = element_text(colour = "red"), 679 | plot.title = element_text(size = 16), 680 | legend.key = element_rect(fill = "white"), 681 | legend.position = "bottom" 682 | ) 683 | ``` 684 | 685 | 686 | 687 | ## Easily changing appearance with ggthemeassist (Rstudio addin) 688 | 689 | https://github.com/calligross/ggthemeassist 690 | 691 | ```{r} 692 | myplot 693 | ``` 694 | 695 | 696 | ## Easily changing appearance with ggedit 697 | 698 | https://github.com/metrumresearchgroup/ggedit 699 | 700 | ```{r} 701 | myplot 702 | ``` 703 | 704 | 705 | ## esquisse: ggplot2 builder addin 706 | 707 | https://github.com/dreamRs/esquisse 708 | 709 | [![](images/esquisse_code.png)](https://raw.githubusercontent.com/dreamRs/esquisse/master/man/figures/esquisse.gif) 710 | 711 | 712 | 713 | 714 | ## Think twice before editing plots out of R 715 | 716 | ```{r out.height="3in", out.width="4in"} 717 | include_graphics("images/trevor_tweet.png") 718 | ``` 719 | 720 | http://mbjoseph.github.io/2015/02/26/plotting.html 721 | 722 | serialmentor.com/dataviz/choosing-the-right-visualization-software.html 723 | 724 | 725 | ## Think twice before editing plots out of R 726 | 727 | Referee #3: "Please increase font size in all figures" 728 | 729 | ```{r echo=TRUE} 730 | myplot + 731 | theme(axis.title = element_text(size = 18)) 732 | ``` 733 | 734 | 735 | 736 | 737 | ## Publication-quality plots 738 | 739 | ```{r echo=TRUE} 740 | library(cowplot) 741 | myplot 742 | ``` 743 | 744 | 745 | ---- 746 | 747 | Some publication themes: 748 | 749 | https://gist.github.com/Pakillo/c2c7ea11c528cc2ee20f#themes 750 | 751 | 752 | 753 | # Composite figures 754 | 755 | ## Composite figures: cowplot 756 | 757 | ```{r echo=TRUE, out.width='4in', out.height='3in'} 758 | library(cowplot) 759 | plot1 <- ggplot(trees) + aes(dbh, height) + geom_point() 760 | plot2 <- ggplot(trees) + aes(factor(plot), height) + geom_boxplot() 761 | plot_grid(plot1, plot2, labels = "AUTO") 762 | ``` 763 | 764 | 765 | ## Composite figures 766 | 767 | ```{r echo=3, out.width='3in', out.height='5in'} 768 | plot1 <- ggplot(trees) + aes(dbh, height) + geom_point() 769 | plot2 <- ggplot(trees) + aes(factor(plot), height) + geom_boxplot() 770 | plot_grid(plot1, plot2, labels = "AUTO", ncol = 1) 771 | ``` 772 | 773 | 774 | ## Composite figures: patchwork 775 | 776 | ```{r} 777 | include_graphics("images/patchwork.PNG") 778 | ``` 779 | 780 | https://github.com/thomasp85/patchwork 781 | 782 | 783 | ## Composite figures: egg 784 | 785 | ```{r} 786 | include_graphics("images/egg.png") 787 | ``` 788 | 789 | https://cran.r-project.org/web/packages/egg/index.html 790 | 791 | 792 | 793 | ## Saving plot 794 | 795 | ```{r echo=TRUE, eval=FALSE} 796 | ggsave("myplot.pdf") 797 | ``` 798 | 799 | ```{r echo=TRUE, eval=FALSE} 800 | save_plot("myplot.pdf") 801 | ``` 802 | 803 | 804 | # Facetting (small multiples) 805 | 806 | ## Facetting 807 | 808 | ```{r echo=TRUE, fig.width=5, fig.height=3} 809 | ggplot(trees) + aes(dbh, height) + 810 | geom_point() + theme_minimal(base_size = 8) + 811 | facet_wrap(~plot) 812 | ``` 813 | 814 | 815 | ## Facetting 816 | 817 | ```{r echo=TRUE, fig.width=5, fig.height=3} 818 | ggplot(trees) + 819 | geom_histogram(aes(height)) + theme_minimal(base_size = 8) + 820 | facet_wrap(~plot, nrow = 2) 821 | ``` 822 | 823 | 824 | ## Interactivity: plotly 825 | 826 | ```{r echo=TRUE, eval=FALSE} 827 | library(plotly) 828 | myplot <- ggplot(trees) + 829 | aes(x = dbh, y = height) + 830 | geom_point() 831 | ggplotly(myplot) 832 | ``` 833 | 834 | 835 | ## Animated graphs 836 | 837 | https://github.com/thomasp85/gganimate 838 | 839 | [![](images/gganimate.png)](https://raw.githubusercontent.com/thomasp85/gganimate/master/man/figures/README-unnamed-chunk-4-1.gif) 840 | 841 | 842 | 843 | ## Automatic label placement 844 | 845 | ```{r} 846 | include_graphics("images/ggrepel.png") 847 | ``` 848 | 849 | https://cran.r-project.org/package=ggrepel 850 | 851 | 852 | ## Many extensions! 853 | 854 | https://www.ggplot2-exts.org/ 855 | 856 | ```{r} 857 | include_graphics("images/ggexts.PNG") 858 | ``` 859 | 860 | 861 | 862 | 863 | # Summary 864 | 865 | 866 | ## Grammar of graphics 867 | 868 | - **Data** (tidy data frame) 869 | 870 | - **Layers** (*geoms*: points, lines, polygons...) 871 | 872 | - **Aesthetics** mappings (x, y, size, colour...) 873 | 874 | - **Scales** (colour, size, shape...) 875 | 876 | - **Facets** (small multiples) 877 | 878 | - **Themes** (appearance) 879 | 880 | - **Coordinate system** (Cartesian, polar, map projections...) 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | ## Exercise: make a plot like this one 890 | 891 | ```{r} 892 | ggplot(trees) + 893 | aes(sex, height) + 894 | geom_violin() 895 | ``` 896 | 897 | 898 | 899 | ## Exercise: make a plot like this one 900 | 901 | ```{r fig.height=4, fig.width=5} 902 | ggplot(trees) + 903 | aes(dbh, height) + 904 | geom_point() + 905 | geom_smooth() + 906 | theme_minimal(base_size = 8) + 907 | facet_wrap(~sex, nrow = 2) + 908 | labs(x = "DBH (cm)", y = "Height (m)", 909 | title = "Tree allometry") 910 | ``` 911 | 912 | 913 | ## Exercise: make a plot like this one 914 | 915 | ```{r fig.height=4, fig.width=5} 916 | ggplot(trees) + 917 | aes(dbh, height) + 918 | geom_point(aes(colour = sex)) + 919 | geom_smooth(aes(colour = sex)) + 920 | theme_minimal(base_size = 12) + 921 | labs(x = "DBH (cm)", y = "Height (m)", 922 | title = "Tree allometry") 923 | ``` 924 | 925 | 926 | ## Exercise: make a plot like this one 927 | 928 | ```{r out.height="3.5in"} 929 | ggplot(trees) + 930 | geom_histogram(aes(height)) + 931 | facet_wrap(~sex, nrow = 2) + 932 | labs(x = "Height (m)", y = "Number of trees", 933 | title = "Tree allometry") + 934 | theme(plot.title = element_text(hjust = 0.5)) 935 | ``` 936 | 937 | 938 | 939 | ```{r include=FALSE, eval=FALSE} 940 | library(rotl) 941 | library(ggtree) 942 | lauraceae <- tnrs_match_names(c("Quercus suber", "Quercus ilex", "Pinus pinea", "Laurus nobilis")) 943 | lautree <- tol_induced_subtree(ott_ids = unlist(ott_id(lauraceae))) 944 | ggtree(lautree) + geom_tiplab() 945 | ``` 946 | 947 | 948 | 949 | 950 | ## Exercise: make a plot like this one 951 | 952 | ```{r fig.height=4, fig.width=5} 953 | ggplot(trees) + 954 | geom_histogram(aes(height, group = sex, fill = sex)) + 955 | theme_minimal(base_size = 8) + 956 | facet_wrap(~plot) + 957 | labs(x = "Height (m)", y = "Number of trees") + 958 | labs(title = "Distribution of heights by sex and plot") 959 | ``` 960 | 961 | 962 | ## Exercise: make a plot like this one 963 | 964 | Data from http://www.columbia.edu/~mhs119/Sensitivity+SL+CO2/Table.txt 965 | 966 | ```{r cache=TRUE, fig.width=6} 967 | hansen <- read.table("http://www.columbia.edu/~mhs119/Sensitivity+SL+CO2/Table.txt", 968 | header = FALSE, dec = ".", nrows = 17604, skip = 9) 969 | hansen <- hansen[, c(3,6)] 970 | names(hansen) <- c("MyrBP", "Tabs") 971 | hansen$logtime <- log10(hansen$MyrBP) 972 | 973 | 974 | timebreaks <- c(0.001, 0.01, 0.1, 1, 10, 66) # in MyrBP 975 | timebreaks.log <- log10(timebreaks) 976 | time.labels <- latex2exp::TeX(c("10^{-3}", "10^{-2}", 977 | "10^{-1}", "1", "10", "66")) 978 | 979 | temp <- ggplot(hansen, aes(x = logtime, y = Tabs)) + 980 | ylim(9, 30) + 981 | labs(x = "Millions of years BP", y = "Temperature (ºC)") + 982 | theme(axis.text.x = element_text(size = 10)) + 983 | geom_line(colour = "Dark Red") + 984 | scale_x_continuous(breaks = timebreaks.log, 985 | labels = time.labels, 986 | trans = "reverse") 987 | 988 | 989 | epochs.start <- c(0.0117, 2.58, 5.333, 23.03, 33.9, 56, 66) # from geoscale 990 | 991 | temp.paleo <- temp + 992 | geom_vline(xintercept = log10(epochs.start), linetype = "dashed", size = 0.2) + 993 | annotate("text", label = c("P", "Eo", "Ol", "Mi", "Pli", "Ple", "Hol"), 994 | x = c(1.78, 1.63, 1.44, 1.07, 0.58, -0.7, -2.9), 995 | y = 30, size = 3) 996 | temp.paleo 997 | ``` 998 | 999 | 1000 | ## Exercise: make a plot like this one 1001 | 1002 | ```{r out.width="2in", out.height="3in"} 1003 | include_graphics("images/christmas_tree.png") 1004 | ``` 1005 | 1006 | 1007 | 1008 | ## END 1009 | 1010 | 1011 | ![](images/CC-BY-NC-SA_logo.png) 1012 | 1013 | Slides and source code available at https://github.com/Pakillo/ggplot-intro 1014 | 1015 | 1016 | -------------------------------------------------------------------------------- /ggplot_intro_trees.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/ggplot_intro_trees.pdf -------------------------------------------------------------------------------- /ggplot_xaringan.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Data visualisation with ggplot2" 3 | # subtitle: "A subtitle" 4 | author: "Francisco Rodríguez-Sánchez" 5 | institute: "https://frodriguezsanchez.net" 6 | date: "@frod_san" 7 | output: 8 | xaringan::moon_reader: 9 | lib_dir: libs 10 | seal: true 11 | nature: 12 | ratio: '16:9' 13 | highlightStyle: github 14 | highlightLines: true 15 | countIncrementalSlides: false 16 | --- 17 | 18 | ```{r setup, include=FALSE} 19 | options(htmltools.dir.version = FALSE) 20 | options(knitr.table.format = "html") 21 | 22 | library(knitr) 23 | knit_hooks$set(crop = hook_pdfcrop) 24 | opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE, 25 | crop = TRUE, cache = TRUE, comment = "") 26 | 27 | opts_chunk$set(out.width = "70%", fig.align = "center", dpi = 150, 28 | fig.width = 4) 29 | ``` 30 | 31 | 32 | 33 | ```{css, echo=FALSE} 34 | 35 | .remark-slide-number { 36 | display: none; 37 | } 38 | 39 | .remark-slide-content { 40 | padding-top: 10px; 41 | padding-left: 80px; 42 | padding-right: 80px; 43 | padding-bottom: 20px; 44 | } 45 | 46 | .remark-slide-content p, ul, ol, li { 47 | font-size: 22px; 48 | } 49 | 50 | 51 | .remark-code, .remark-inline-code { 52 | background: #f0f0f0; 53 | } 54 | 55 | .remark-code { 56 | font-size: 18px; 57 | } 58 | 59 | .hugecode .remark-code { font-size: 200% } 60 | .largecode .remark-code { font-size: 130% } 61 | .smallcode .remark-code{ font-size: 70% } 62 | .tinycode .remark-code { font-size: 50% } 63 | 64 | .huge { font-size: 200% } 65 | .large { font-size: 130% } 66 | .small { font-size: 70% } 67 | .tiny { font-size: 50% } 68 | 69 | ``` 70 | 71 | 72 | ## Always plot data! 73 | 74 | ```{r echo=FALSE} 75 | include_graphics("images/DinoSequential.gif") 76 | ``` 77 | 78 | https://github.com/stephlocke/datasauRus 79 | 80 | --- 81 | 82 | ## Made with ggplot 83 | 84 | ```{r out.width="60%"} 85 | include_graphics("images/ggraph1.png") 86 | ``` 87 | 88 | https://github.com/thomasp85/ggraph 89 | 90 | --- 91 | 92 | ## Made with ggplot 93 | 94 | ```{r} 95 | include_graphics("images/bike_pollution_web.png") 96 | ``` 97 | 98 | http://spatial.ly/2012/02/great-maps-ggplot2/ 99 | 100 | --- 101 | 102 | ## Made with ggplot 103 | 104 | ```{r } 105 | include_graphics("images/heatmap_rudis.png") 106 | ``` 107 | 108 | https://rud.is/b/2016/02/14/making-faceted-heatmaps-with-ggplot2/ 109 | 110 | --- 111 | 112 | ## Made with ggplot 113 | 114 | ```{r } 115 | include_graphics("images/cloropleth_rudis.png") 116 | ``` 117 | 118 | https://rud.is/b/2016/03/29/easier-composite-u-s-choropleths-with-albersusa/ 119 | 120 | 121 | --- 122 | 123 | ## Made with ggplot 124 | 125 | ```{r out.width="40%"} 126 | include_graphics("images/plants.png") 127 | ``` 128 | 129 | https://github.com/marcusvolz/mathart 130 | 131 | --- 132 | 133 | ## Why ggplot 134 | 135 | - Extremely powerful and flexible 136 | 137 | - Consistent (grammar of graphics) 138 | 139 | - Very powerful user base and active development 140 | 141 | 142 | 143 | --- 144 | 145 | ## Very good documentation and tutorials 146 | 147 | - [Official ggplot2 documentation](https://ggplot2.tidyverse.org/reference/) 148 | 149 | - [ggplot2 book](https://ggplot2-book.org/) 150 | 151 | - [Data visualisation chapter in R for Data Science](http://r4ds.had.co.nz/data-visualisation.html) 152 | 153 | - [R graphics cookbook](https://r-graphics.org/) and [Cookbook for R](http://www.cookbook-r.com/Graphs/) 154 | 155 | - [Data visualization: a practical introduction (K. Healy)](http://socviz.co/) 156 | 157 | - [Fundamentals of data visualization (C. Wilke)](http://serialmentor.com/dataviz/) 158 | 159 | 160 | --- 161 | 162 | ## Cheatsheet 163 | 164 | ```{r out.width="50%"} 165 | include_graphics("images/cheatsheet.png") 166 | ``` 167 | 168 | https://www.rstudio.com/resources/cheatsheets/ 169 | 170 | --- 171 | 172 | ## Repos of figures + code 173 | 174 | - [From Data to Viz](https://www.data-to-viz.com/) 175 | 176 | - [The R graph gallery](http://www.r-graph-gallery.com/) 177 | 178 | - [R graphics cookbook](https://r-graphics.org/) 179 | 180 | - [Cookbook for R: Graphs](http://www.cookbook-r.com/Graphs/) 181 | 182 | - [Graphical data analysis with R](http://www.gradaanwr.net/) 183 | 184 | - [R graph catalog](https://shiny.srvanderplas.com/r-graph-catalog/) 185 | 186 | 187 | 188 | --- 189 | 190 | ## Find answers in Stack Overflow, Rstudio Community, R4DS... 191 | 192 | ```{r out.width="40%"} 193 | include_graphics("images/so2.png") 194 | ``` 195 | 196 | 197 | 198 | 199 | 200 | --- 201 | class: middle, center 202 | 203 | # Building a ggplot figure 204 | 205 | --- 206 | 207 | ## Our example dataset: paper planes flying experiment 208 | 209 | ```{r echo=TRUE} 210 | library(paperplanes) 211 | data(paperplanes) 212 | head(paperplanes) 213 | ``` 214 | 215 | 216 | --- 217 | 218 | ## Ensuring 'paper' is factor, not numeric 219 | 220 | Using dplyr: 221 | 222 | ```{r echo=c(-1)} 223 | library(dplyr) 224 | paperplanes <- paperplanes %>% 225 | mutate(paper = as.factor(paper)) 226 | ``` 227 | 228 | 229 | R base: 230 | 231 | ```{r echo=TRUE} 232 | paperplanes$paper <- as.factor(paperplanes$paper) 233 | ``` 234 | 235 | --- 236 | 237 | ## Data must be a tidy data frame 238 | 239 | ```{r } 240 | include_graphics("images/tidy-1.png") 241 | ``` 242 | 243 | ```{r } 244 | include_graphics("images/tidy-9b.png") 245 | ``` 246 | 247 | http://r4ds.had.co.nz/tidy-data.html 248 | 249 | 250 | 251 | --- 252 | 253 | ## Calling ggplot 254 | 255 | .pull-left[ 256 | ```{r echo=TRUE, fig.show = 'hide'} 257 | library(ggplot2) 258 | ggplot(paperplanes) 259 | ``` 260 | ] 261 | 262 | .pull-right[ 263 | ```{r echo = FALSE, out.width="100%", fig.asp = 0.9} 264 | ggplot(paperplanes) 265 | ``` 266 | ] 267 | 268 | 269 | --- 270 | 271 | ## First argument is a tidy data frame 272 | 273 | .largecode[ 274 | ```{r eval=FALSE, echo=TRUE} 275 | ggplot(paperplanes) 276 | ``` 277 | ] 278 | 279 | 280 | --- 281 | 282 | ## What variables as axes? 283 | 284 | Note syntax: + followed by new line 285 | 286 | .pull-left[ 287 | ```{r echo=TRUE, fig.show='hide'} 288 | ggplot(paperplanes) + 289 | aes(x = age, y = distance) #<< 290 | ``` 291 | ] 292 | 293 | .pull-right[ 294 | ```{r echo=FALSE, out.width="100%", fig.asp = 0.9} 295 | ggplot(paperplanes) + 296 | aes(x = age, y = distance) 297 | ``` 298 | ] 299 | 300 | --- 301 | 302 | ## Aesthetics (*aes*) map data variables (*age*, *distance*) to graphic elements (*axes*) 303 | 304 | ```{r echo=TRUE, eval=FALSE} 305 | ggplot(paperplanes) + 306 | aes(x = age, y = distance) #<< 307 | ``` 308 | 309 | ```{r } 310 | include_graphics("images/aesthetics_Wilke.png") 311 | ``` 312 | 313 | http://serialmentor.com/dataviz/aesthetic-mapping.html 314 | 315 | 316 | 317 | 318 | --- 319 | 320 | ## Add layers (geoms) 321 | 322 | .pull-left[ 323 | ```{r echo=TRUE, fig.show='hide'} 324 | ggplot(paperplanes) + 325 | aes(x = age, y = distance) + 326 | geom_point() #<< 327 | ``` 328 | ] 329 | 330 | .pull-right[ 331 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 332 | ggplot(paperplanes) + 333 | aes(x = age, y = distance) + 334 | geom_point() #<< 335 | ``` 336 | ] 337 | 338 | --- 339 | 340 | ## Change point size and type 341 | 342 | .pull-left[ 343 | ```{r echo=TRUE, fig.show='hide'} 344 | ggplot(paperplanes) + 345 | aes(x = age, y = distance) + 346 | geom_point(size = 2) #<< 347 | ``` 348 | ] 349 | 350 | .pull-right[ 351 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 352 | ggplot(paperplanes) + 353 | aes(x = age, y = distance) + 354 | geom_point(size = 2) #<< 355 | ``` 356 | ] 357 | 358 | Check out `geom_point` help [here](https://ggplot2.tidyverse.org/reference/geom_point.html) 359 | 360 | --- 361 | 362 | ## Change point size and type 363 | 364 | .pull-left[ 365 | ```{r echo=TRUE, fig.show='hide'} 366 | ggplot(paperplanes) + 367 | aes(x = age, y = distance) + 368 | geom_point(size = 2, shape = 8) #<< 369 | ``` 370 | ] 371 | 372 | .pull-right[ 373 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 374 | ggplot(paperplanes) + 375 | aes(x = age, y = distance) + 376 | geom_point(size = 2, shape = 8) #<< 377 | ``` 378 | ] 379 | 380 | 381 | --- 382 | 383 | ## Change point size and type 384 | 385 | .pull-left[ 386 | ```{r echo=TRUE, fig.show='hide'} 387 | ggplot(paperplanes) + 388 | aes(x = age, y = distance) + 389 | geom_point(size = 2, shape = 16, 390 | colour = "blue") #<< 391 | ``` 392 | ] 393 | 394 | .pull-right[ 395 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 396 | ggplot(paperplanes) + 397 | aes(x = age, y = distance) + 398 | geom_point(size = 2, shape = 16, 399 | colour = "blue") #<< 400 | ``` 401 | ] 402 | 403 | --- 404 | 405 | ## Map geom aesthetics (e.g. colour) to variable 406 | 407 | .pull-left[ 408 | ```{r echo=TRUE, fig.show='hide'} 409 | ggplot(paperplanes) + 410 | aes(x = age, y = distance) + 411 | geom_point(aes(colour = paper)) #<< 412 | ``` 413 | ] 414 | 415 | .pull-right[ 416 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 417 | ggplot(paperplanes) + 418 | aes(x = age, y = distance) + 419 | geom_point(aes(colour = paper)) #<< 420 | ``` 421 | ] 422 | 423 | 424 | 425 | --- 426 | class: middle, center 427 | 428 | ### Remember: 429 | 430 | ## 'aes' relates some graphical characteristic 431 | 432 | ## (colour, size, shape...) 433 | 434 | ## to a variable in the data 435 | 436 | 437 | --- 438 | class: middle, left 439 | 440 | Note difference between 441 | 442 | ```{r eval=FALSE, echo=TRUE} 443 | geom_point(colour = "blue") 444 | # colour is given a concrete value ('blue') 445 | ``` 446 | 447 | ```{r eval=FALSE, echo=TRUE} 448 | geom_point(aes(colour = gender)) 449 | # colour maps a *variable* in the data (gender) USING `aes` 450 | ``` 451 | 452 | 453 | --- 454 | 455 | .pull-left[ 456 | **This works:** 457 | 458 | ```{r echo=TRUE, out.width="100%", fig.asp = 0.9} 459 | ggplot(paperplanes) + 460 | aes(x = age, y = distance) + 461 | geom_point(aes(colour = paper)) #<< 462 | ``` 463 | ] 464 | 465 | .pull-right[ 466 | **This doesn't work:** 467 | 468 | ```{r echo=TRUE, eval=FALSE} 469 | ggplot(paperplanes) + 470 | aes(x = age, y = distance) + 471 | geom_point(colour = paper) #<< 472 | ``` 473 | 474 | *Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomPoint, : * 475 | *object 'paper' not found* 476 | 477 |
478 | 479 | 'paper' is a variable in dataframe, hence 480 | 481 |
482 | 483 | **must use `aes`** 484 | ] 485 | 486 | 487 | --- 488 | 489 | ## Map geom aesthetics (colour, shape) to variable 490 | 491 | .pull-left[ 492 | ```{r echo=TRUE, fig.show='hide'} 493 | ggplot(paperplanes) + 494 | aes(x = age, y = distance) + 495 | geom_point(aes(colour = paper, 496 | shape = paper)) #<< 497 | ``` 498 | ] 499 | 500 | .pull-right[ 501 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 502 | ggplot(paperplanes) + 503 | aes(x = age, y = distance) + 504 | geom_point(aes(colour = paper, 505 | shape = paper)) #<< 506 | ``` 507 | ] 508 | 509 | --- 510 | 511 | ## Map geom aesthetics (colour, shape) to variable 512 | 513 | .pull-left[ 514 | ```{r echo=TRUE, fig.show='hide'} 515 | ggplot(paperplanes) + 516 | aes(x = age, y = distance) + 517 | geom_point(aes(colour = paper, 518 | shape = gender)) #<< 519 | ``` 520 | ] 521 | 522 | .pull-right[ 523 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 524 | ggplot(paperplanes) + 525 | aes(x = age, y = distance) + 526 | geom_point(aes(colour = paper, 527 | shape = gender)) #<< 528 | ``` 529 | ] 530 | 531 | 532 | --- 533 | 534 | ## Change colour scale 535 | 536 | .pull-left[ 537 | ```{r echo=TRUE, fig.show='hide'} 538 | ggplot(paperplanes) + 539 | aes(x = age, y = distance) + 540 | geom_point(aes(colour = paper)) + 541 | scale_colour_manual(values = c("orange", "blue")) #<< 542 | ``` 543 | ] 544 | 545 | .pull-right[ 546 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 547 | ggplot(paperplanes) + 548 | aes(x = age, y = distance) + 549 | geom_point(aes(colour = paper)) + 550 | scale_colour_manual(values = c("orange", "blue")) #<< 551 | ``` 552 | ] 553 | 554 | 555 | 556 | ```{r echo=FALSE, eval=FALSE} 557 | ggplot(paperplanes) + 558 | aes(x = age, y = distance) + 559 | geom_point(aes(colour = paper)) + 560 | scale_colour_brewer(type = "qual", palette = 6) 561 | ``` 562 | 563 | 564 | --- 565 | 566 | ## Change axis labels: xlab & ylab 567 | 568 | .pull-left[ 569 | ```{r echo=TRUE, fig.show='hide'} 570 | ggplot(paperplanes) + 571 | aes(x = age, y = distance) + 572 | geom_point(aes(colour = paper)) + 573 | labs(x = "Age (years)", #<< 574 | y = "Distance (m)") #<< 575 | ``` 576 | ] 577 | 578 | .pull-right[ 579 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 580 | ggplot(paperplanes) + 581 | aes(x = age, y = distance) + 582 | geom_point(aes(colour = paper)) + 583 | labs(x = "Age (years)", #<< 584 | y = "Distance (m)") #<< 585 | ``` 586 | ] 587 | 588 | 589 | --- 590 | 591 | ## Set title 592 | 593 | .pull-left[ 594 | ```{r echo=TRUE, fig.show='hide'} 595 | ggplot(paperplanes) + 596 | aes(x = age, y = distance) + 597 | geom_point(aes(colour = paper)) + 598 | labs(x = "Age (years)", 599 | y = "Distance (m)") + 600 | labs(title = "Distance flown by age") #<< 601 | ``` 602 | ] 603 | 604 | .pull-right[ 605 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 606 | ggplot(paperplanes) + 607 | aes(x = age, y = distance) + 608 | geom_point(aes(colour = paper)) + 609 | labs(x = "Age (years)", 610 | y = "Distance (m)") + 611 | labs(title = "Distance flown by age") #<< 612 | ``` 613 | ] 614 | 615 | 616 | --- 617 | 618 | ## Adding more layers 619 | 620 | .pull-left[ 621 | ```{r echo=TRUE, fig.show='hide'} 622 | ggplot(paperplanes) + 623 | aes(x = age, y = distance) + 624 | geom_point(aes(colour = paper)) + 625 | labs(x = "Age (years)", 626 | y = "Distance (m)") + 627 | labs(title = "Distance flown by age") + 628 | geom_smooth(method = "lm") #<< 629 | ``` 630 | ] 631 | 632 | .pull-right[ 633 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 634 | ggplot(paperplanes) + 635 | aes(x = age, y = distance) + 636 | geom_point(aes(colour = paper)) + 637 | labs(x = "Age (years)", 638 | y = "Distance (m)") + 639 | labs(title = "Distance flown by age") + 640 | geom_smooth(method = "lm") #<< 641 | ``` 642 | ] 643 | 644 | 645 | 646 | --- 647 | 648 | ## Adding more layers 649 | 650 | .pull-left[ 651 | ```{r echo=TRUE, fig.show='hide'} 652 | ggplot(paperplanes) + 653 | aes(x = age, y = distance) + 654 | geom_point(aes(colour = paper)) + 655 | labs(x = "Age (years)", 656 | y = "Distance (m)") + 657 | labs(title = "Distance flown by age") + 658 | geom_smooth(method = "lm") + 659 | geom_vline(xintercept = c(20, 40, 60)) #<< 660 | ``` 661 | ] 662 | 663 | .pull-right[ 664 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 665 | ggplot(paperplanes) + 666 | aes(x = age, y = distance) + 667 | geom_point(aes(colour = paper)) + 668 | labs(x = "Age (years)", 669 | y = "Distance (m)") + 670 | labs(title = "Distance flown by age") + 671 | geom_smooth(method = "lm") + 672 | geom_vline(xintercept = c(20, 40, 60)) #<< 673 | ``` 674 | ] 675 | 676 | 677 | --- 678 | 679 | ## Adding more layers 680 | 681 | .pull-left[ 682 | ```{r echo=TRUE, fig.show='hide'} 683 | ggplot(paperplanes) + 684 | aes(x = age, y = distance) + 685 | geom_point(aes(colour = paper)) + 686 | labs(x = "Age (years)", 687 | y = "Distance (m)") + 688 | labs(title = "Distance flown by age") + 689 | geom_smooth(method = "lm") + 690 | geom_vline(xintercept = c(20, 40, 60)) + 691 | geom_hline(yintercept = 10) #<< 692 | ``` 693 | ] 694 | 695 | .pull-right[ 696 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 697 | ggplot(paperplanes) + 698 | aes(x = age, y = distance) + 699 | geom_point(aes(colour = paper)) + 700 | labs(x = "Age (years)", 701 | y = "Distance (m)") + 702 | labs(title = "Distance flown by age") + 703 | geom_smooth(method = "lm") + 704 | geom_vline(xintercept = c(20, 40, 60)) + 705 | geom_hline(yintercept = 10) #<< 706 | ``` 707 | ] 708 | 709 | 710 | --- 711 | 712 | ## Summary 713 | 714 | ```{r eval=FALSE, echo=TRUE} 715 | ggplot(paperplanes) + # Name of (tidy) data frame 716 | aes(x = age, y = distance) + # Aesthetics (variables to map in axes) 717 | geom_point() # Geoms: geometric objects 718 | ``` 719 | 720 | 721 | --- 722 | 723 | ## Exercise: Make a plot like this one 724 | 725 | ```{r out.width="50%", fig.asp = 0.9} 726 | ggplot(paperplanes) + 727 | aes(x = gender, y = distance) + 728 | geom_boxplot() + 729 | labs(x = "Gender", y = "Distance (m)", 730 | title = "Distance flown by gender") 731 | ``` 732 | 733 | 734 | --- 735 | 736 | ## Exercise: Make a plot like this one 737 | 738 | ```{r out.width="50%", fig.asp = 0.9} 739 | ggplot(paperplanes) + 740 | aes(x = gender, y = distance) + 741 | geom_violin() + 742 | labs(x = "Gender", y = "Distance (m)", 743 | title = "Distance flown by gender") 744 | ``` 745 | 746 | 747 | --- 748 | 749 | ## Exercise: Make a plot like this one 750 | 751 | ```{r out.width="50%", fig.asp = 0.9} 752 | ggplot(paperplanes) + 753 | aes(x = gender, y = distance) + 754 | geom_violin(fill = "orange") + 755 | geom_point() + 756 | labs(x = "Gender", y = "Distance (m)", 757 | title = "Distance flown by gender") 758 | ``` 759 | 760 | --- 761 | 762 | ## Exercise: Make a plot like this one 763 | 764 | ```{r out.width="50%", fig.asp = 0.9} 765 | ggplot(paperplanes) + 766 | aes(x = distance) + 767 | geom_density(aes(colour = gender, fill = gender), alpha = 0.5) + 768 | labs(x = "Distance (m)", 769 | title = "Distances flown by gender") 770 | ``` 771 | 772 | 773 | --- 774 | 775 | ## Exercise: Make a plot like this one 776 | 777 | ```{r out.width="50%", fig.asp = 0.9} 778 | ggplot(paperplanes) + 779 | aes(x = age, y = distance, colour = paper) + 780 | geom_point() + 781 | geom_smooth(method = "lm") 782 | ``` 783 | 784 | 785 | --- 786 | class: middle, center 787 | 788 | # ggplot2 figures can be assigned to R objects 789 | 790 | --- 791 | 792 | ## Assigning ggplot objects 793 | 794 | ```{r echo=TRUE, out.width="30%", fig.asp = 0.9} 795 | myplot <- ggplot(paperplanes) + 796 | aes(x = age, y = distance) 797 | myplot + geom_point() 798 | ``` 799 | 800 | 801 | --- 802 | 803 | ## Assigning ggplot objects 804 | 805 | ```{r echo=TRUE, out.width="30%", fig.asp = 0.9} 806 | myplot <- ggplot(paperplanes) + 807 | aes(x = age, y = distance) 808 | myplot <- myplot + geom_point() 809 | myplot 810 | ``` 811 | 812 | 813 | --- 814 | 815 | ## Assigning ggplot objects 816 | 817 | ```{r echo=TRUE, out.width="30%", fig.asp = 0.9} 818 | baseplot <- ggplot(paperplanes) + 819 | aes(x = age, y = distance) 820 | scatterplot <- baseplot + geom_point() 821 | labelled <- scatterplot + labs(x = "Age (years)", y = "Distance (m)") 822 | labelled 823 | ``` 824 | 825 | 826 | --- 827 | class: inverse, middle, center 828 | 829 | # Themes: changing plot appearance 830 | 831 | 832 | --- 833 | 834 | ## Create 'myplot' 835 | 836 | .pull-left[ 837 | ```{r echo=TRUE, fig.show='hide'} 838 | myplot <- ggplot(paperplanes) + 839 | aes(x = age, 840 | y = distance, 841 | colour = paper) + 842 | geom_point() 843 | 844 | myplot 845 | ``` 846 | ] 847 | 848 | .pull-right[ 849 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 850 | myplot <- ggplot(paperplanes) + 851 | aes(x = age, 852 | y = distance, 853 | colour = paper) + 854 | geom_point() 855 | myplot 856 | ``` 857 | ] 858 | 859 | 860 | 861 | --- 862 | 863 | ## Use theme_classic 864 | 865 | ```{r echo=TRUE, fig.asp = 0.9, out.width="50%"} 866 | myplot + theme_classic() 867 | ``` 868 | 869 | --- 870 | 871 | ## theme_minimal 872 | 873 | ```{r echo=TRUE, fig.asp = 0.9, out.width="50%"} 874 | myplot + theme_minimal() 875 | ``` 876 | 877 | --- 878 | 879 | ## Lots of themes out there 880 | 881 | ```{r echo=TRUE, fig.asp = 0.9, out.width="50%"} 882 | library(ggthemes) 883 | myplot + theme_economist() 884 | ``` 885 | 886 | 887 | --- 888 | 889 | ## Lots of themes out there 890 | 891 | ```{r echo=TRUE, fig.asp = 0.9, out.width="50%"} 892 | myplot + theme_wsj() 893 | ``` 894 | 895 | 896 | --- 897 | 898 | ## Editing themes 899 | 900 | ```{r echo=TRUE, eval=FALSE} 901 | ?theme 902 | ``` 903 | 904 | - `element_blank` 905 | 906 | - `element_text` 907 | 908 | - `element_line` 909 | 910 | - `element_rect` (borders & backgrounds) 911 | 912 | 913 | --- 914 | 915 | ## Exercise: make a plot like this one 916 | 917 | ```{r out.width="50%", fig.asp = 0.9} 918 | ggplot(paperplanes) + 919 | aes(x = age, y = distance, colour = paper) + 920 | geom_point() + 921 | labs(x = "Age (years)", y = "Distance (m)", 922 | title = "Changing plot appearance") + 923 | theme(axis.title.x = element_text(colour = "blue"), 924 | axis.title.y = element_text(colour = "red"), 925 | plot.title = element_text(size = 16), 926 | legend.key = element_rect(fill = "white"), 927 | legend.position = "bottom" 928 | ) 929 | ``` 930 | 931 | 932 | --- 933 | 934 | ## Easily changing appearance with ggthemeassist (Rstudio addin) 935 | 936 | https://github.com/calligross/ggthemeassist 937 | 938 | ```{r out.width="80%"} 939 | include_graphics("images/ggThemeAssist2.gif") 940 | ``` 941 | 942 | --- 943 | 944 | ## Easily changing appearance with ggedit 945 | 946 | https://github.com/yonicd/ggedit 947 | 948 | 949 | 950 | --- 951 | 952 | ## esquisse: ggplot2 builder addin 953 | 954 | https://github.com/dreamRs/esquisse 955 | 956 | ```{r out.width="60%"} 957 | include_graphics("https://raw.githubusercontent.com/dreamRs/esquisse/master/man/figures/esquisse.gif") 958 | ``` 959 | 960 | 961 | 962 | 963 | --- 964 | 965 | ## Think twice before editing plots out of R 966 | 967 |
968 | 969 | ```{r out.width="60%"} 970 | include_graphics("images/trevor_tweet.png") 971 | ``` 972 | 973 |
974 | 975 | [Why I think twice before editing plots out of R](https://mbjoseph.github.io/posts/2018-12-27-why-i-think-twice-before-editing-plots-in-powerpoint-illustrator-inkscape-etc/) 976 | 977 | [Choosing the right visualization software](serialmentor.com/dataviz/choosing-the-right-visualization-software.html) 978 | 979 | --- 980 | 981 | ## Think twice before editing plots out of R 982 | 983 | Referee #3: "Please increase font size in all figures" 984 | 985 | ```{r echo=TRUE, fig.asp = 0.9, out.width="50%"} 986 | myplot + 987 | theme(axis.title = element_text(size = 18)) 988 | ``` 989 | 990 | 991 | --- 992 | 993 | ## Publication-quality plots 994 | 995 | ```{r echo=TRUE, fig.asp = 0.9, out.width="50%"} 996 | library(cowplot) 997 | myplot + theme_cowplot() 998 | ``` 999 | 1000 | 1001 | --- 1002 | 1003 | Some publication themes: 1004 | 1005 | https://gist.github.com/Pakillo/c2c7ea11c528cc2ee20f#themes 1006 | 1007 | 1008 | 1009 | --- 1010 | class: inverse, middle, center 1011 | 1012 | # Composite figures 1013 | 1014 | 1015 | --- 1016 | 1017 | ## Composite figures: cowplot 1018 | 1019 | ```{r echo=TRUE, out.width="50%", fig.asp=0.65} 1020 | library(cowplot) 1021 | plot1 <- ggplot(paperplanes) + aes(age, distance) + geom_point() 1022 | plot2 <- ggplot(paperplanes) + aes(gender, distance) + geom_boxplot() 1023 | plot_grid(plot1, plot2, labels = "AUTO") #<< 1024 | ``` 1025 | 1026 | 1027 | --- 1028 | 1029 | ## Composite figures 1030 | 1031 | ```{r echo=3, out.width="20%"} 1032 | plot1 <- ggplot(paperplanes) + aes(age, distance) + geom_point() 1033 | plot2 <- ggplot(paperplanes) + aes(gender, distance) + geom_boxplot() 1034 | plot_grid(plot1, plot2, labels = "AUTO", ncol = 1) 1035 | ``` 1036 | 1037 | 1038 | --- 1039 | 1040 | ## Composite figures: patchwork 1041 | 1042 | ```{r out.width="50%"} 1043 | include_graphics("images/patchwork.PNG") 1044 | ``` 1045 | 1046 | https://github.com/thomasp85/patchwork 1047 | 1048 | 1049 | --- 1050 | 1051 | ## Composite figures: egg 1052 | 1053 | ```{r} 1054 | include_graphics("images/egg.png") 1055 | ``` 1056 | 1057 | https://cran.r-project.org/web/packages/egg/index.html 1058 | 1059 | 1060 | --- 1061 | class: middle, center 1062 | 1063 | ## Saving plot 1064 | 1065 | ```{r echo=TRUE, eval=FALSE} 1066 | ggsave("myplot.pdf") 1067 | ``` 1068 | 1069 | ```{r echo=TRUE, eval=FALSE} 1070 | save_plot("myplot.pdf") 1071 | ``` 1072 | 1073 | 1074 | --- 1075 | class: inverse, middle, center 1076 | 1077 | # Facetting (small multiples) 1078 | 1079 | 1080 | --- 1081 | 1082 | ## Facetting 1083 | 1084 | .pull-left[ 1085 | ```{r echo=TRUE, fig.show='hide'} 1086 | ggplot(paperplanes) + 1087 | aes(x = age, 1088 | y = distance) + 1089 | geom_point() + 1090 | theme_bw(base_size = 12) + 1091 | facet_wrap(~paper) #<< 1092 | ``` 1093 | ] 1094 | 1095 | .pull-right[ 1096 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 1097 | ggplot(paperplanes) + 1098 | aes(x = age, 1099 | y = distance) + 1100 | geom_point() + 1101 | theme_bw(base_size = 12) + 1102 | facet_wrap(~paper) #<< 1103 | ``` 1104 | ] 1105 | 1106 | --- 1107 | 1108 | ## Facetting 1109 | 1110 | .pull-left[ 1111 | ```{r echo=TRUE, fig.show='hide'} 1112 | ggplot(paperplanes) + 1113 | geom_histogram(aes(distance)) + 1114 | theme_minimal(base_size = 8) + 1115 | facet_wrap(~paper, nrow = 2) #<< 1116 | ``` 1117 | ] 1118 | 1119 | .pull-right[ 1120 | ```{r echo=FALSE, fig.asp = 0.9, out.width="100%"} 1121 | ggplot(paperplanes) + 1122 | geom_histogram(aes(distance)) + 1123 | theme_minimal(base_size = 8) + 1124 | facet_wrap(~paper, nrow = 2) #<< 1125 | ``` 1126 | ] 1127 | 1128 | 1129 | 1130 | --- 1131 | 1132 | ## Interactivity: plotly 1133 | 1134 | .pull-left[ 1135 | ```{r echo=TRUE, eval = FALSE} 1136 | library(plotly) 1137 | 1138 | myplot <- ggplot(paperplanes) + 1139 | aes(age, distance) + 1140 | geom_point() 1141 | 1142 | ggplotly(myplot) 1143 | ``` 1144 | ] 1145 | 1146 | .pull-right[ 1147 | ```{r echo=FALSE, out.width="100%", fig.asp = 0.9} 1148 | library(plotly) 1149 | 1150 | myplot <- ggplot(paperplanes) + 1151 | aes(age, distance) + 1152 | geom_point() 1153 | 1154 | ggplotly(myplot) 1155 | ``` 1156 | ] 1157 | 1158 | --- 1159 | 1160 | ## Animated graphs 1161 | 1162 | https://github.com/thomasp85/gganimate 1163 | 1164 | [![](images/gganimate.png)](https://raw.githubusercontent.com/thomasp85/gganimate/master/man/figures/README-unnamed-chunk-4-1.gif) 1165 | 1166 | 1167 | --- 1168 | 1169 | ## Automatic label placement 1170 | 1171 | ```{r} 1172 | include_graphics("images/ggrepel.png") 1173 | ``` 1174 | 1175 | https://cran.r-project.org/package=ggrepel 1176 | 1177 | 1178 | --- 1179 | 1180 | ## Many extensions! 1181 | 1182 | https://exts.ggplot2.tidyverse.org/gallery/ 1183 | 1184 | ```{r} 1185 | include_graphics("images/ggexts.PNG") 1186 | ``` 1187 | 1188 | 1189 | --- 1190 | class: inverse, middle, center 1191 | 1192 | # Summary 1193 | 1194 | 1195 | --- 1196 | 1197 | ## Grammar of graphics 1198 | 1199 | - **Data** (tidy data frame) 1200 | 1201 | - **Layers** (*geoms*: points, lines, polygons...) 1202 | 1203 | - **Aesthetics** mappings (x, y, size, colour...) 1204 | 1205 | - **Scales** (colour, size, shape...) 1206 | 1207 | - **Facets** (small multiples) 1208 | 1209 | - **Themes** (appearance) 1210 | 1211 | - **Coordinate system** (Cartesian, polar, map projections...) 1212 | 1213 | 1214 | 1215 | 1216 | --- 1217 | 1218 | ## Exercise: make a plot like this one 1219 | 1220 | ```{r fig.asp = 0.9, out.width="50%"} 1221 | ggplot(paperplanes) + 1222 | aes(factor(paper), distance) + 1223 | geom_violin() 1224 | ``` 1225 | 1226 | 1227 | --- 1228 | 1229 | ## Exercise: make a plot like this one 1230 | 1231 | ```{r fig.asp = 0.9, out.width="50%"} 1232 | ggplot(paperplanes) + 1233 | aes(age, distance) + 1234 | geom_point() + 1235 | geom_smooth() + 1236 | theme_minimal(base_size = 8) + 1237 | facet_wrap(~gender, nrow = 2) + 1238 | labs(x = "Age (years)", y = "Distance (m)", 1239 | title = "Distance flown by age and gender") 1240 | ``` 1241 | 1242 | 1243 | --- 1244 | 1245 | ## Exercise: make a plot like this one 1246 | 1247 | ```{r fig.asp = 0.9, out.width="50%"} 1248 | ggplot(paperplanes) + 1249 | aes(age, distance) + 1250 | geom_point(aes(colour = gender)) + 1251 | geom_smooth(aes(colour = gender)) + 1252 | theme_minimal(base_size = 12) + 1253 | labs(x = "Age (years)", y = "Distance (m)", 1254 | title = "Distance flown by age and gender") 1255 | ``` 1256 | 1257 | 1258 | --- 1259 | 1260 | ## Exercise: make a plot like this one 1261 | 1262 | ```{r fig.asp = 0.9, out.width="50%"} 1263 | ggplot(paperplanes) + 1264 | geom_histogram(aes(age)) + 1265 | facet_wrap(~gender, nrow = 2) + 1266 | labs(x = "Age (years)", y = "Number of individuals", 1267 | title = "Age distribution per gender") + 1268 | theme(plot.title = element_text(hjust = 0.5)) 1269 | ``` 1270 | 1271 | 1272 | 1273 | ```{r include=FALSE, eval=FALSE} 1274 | library(rotl) 1275 | library(ggtree) 1276 | lauraceae <- tnrs_match_names(c("Quercus suber", "Quercus ilex", "Pinus pinea", "Laurus nobilis")) 1277 | lautree <- tol_induced_subtree(ott_ids = unlist(ott_id(lauraceae))) 1278 | ggtree(lautree) + geom_tiplab() 1279 | ``` 1280 | 1281 | 1282 | --- 1283 | 1284 | ## Exercise: make a plot like this one 1285 | 1286 | Data from http://www.columbia.edu/~mhs119/Sensitivity+SL+CO2/Table.txt 1287 | 1288 | ```{r cache=TRUE, fig.asp = 0.6, out.width="80%"} 1289 | hansen <- read.table("http://www.columbia.edu/~mhs119/Sensitivity+SL+CO2/Table.txt", 1290 | header = FALSE, dec = ".", nrows = 17604, skip = 9) 1291 | hansen <- hansen[, c(3,6)] 1292 | names(hansen) <- c("MyrBP", "Tabs") 1293 | hansen$logtime <- log10(hansen$MyrBP) 1294 | 1295 | 1296 | timebreaks <- c(0.001, 0.01, 0.1, 1, 10, 66) # in MyrBP 1297 | timebreaks.log <- log10(timebreaks) 1298 | time.labels <- latex2exp::TeX(c("10^{-3}", "10^{-2}", 1299 | "10^{-1}", "1", "10", "66")) 1300 | 1301 | temp <- ggplot(hansen, aes(x = logtime, y = Tabs)) + 1302 | ylim(9, 30) + 1303 | labs(x = "Millions of years BP", y = "Temperature (ºC)") + 1304 | theme_cowplot() + 1305 | theme(axis.text.x = element_text(size = 10)) + 1306 | geom_line(colour = "Dark Red") + 1307 | scale_x_continuous(breaks = timebreaks.log, 1308 | labels = time.labels, 1309 | trans = "reverse") 1310 | 1311 | 1312 | epochs.start <- c(0.0117, 2.58, 5.333, 23.03, 33.9, 56, 66) # from geoscale 1313 | 1314 | temp.paleo <- temp + 1315 | geom_vline(xintercept = log10(epochs.start), linetype = "dashed", size = 0.2) + 1316 | annotate("text", label = c("P", "Eo", "Ol", "Mi", "Pli", "Ple", "Hol"), 1317 | x = c(1.78, 1.63, 1.44, 1.07, 0.58, -0.7, -2.9), 1318 | y = 30, size = 2) 1319 | temp.paleo 1320 | ``` 1321 | 1322 | 1323 | --- 1324 | 1325 | ## Exercise: make a plot like this one 1326 | 1327 | ```{r out.width="50%"} 1328 | include_graphics("images/christmas_tree.png") 1329 | ``` 1330 | 1331 | --- 1332 | 1333 | ## END 1334 | 1335 | 1336 | ![](images/CC-BY-NC-SA_logo.png) 1337 | 1338 | Slides and source code available at https://github.com/Pakillo/ggplot-intro 1339 | 1340 | 1341 | -------------------------------------------------------------------------------- /ggplot_xaringan.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/ggplot_xaringan.pdf -------------------------------------------------------------------------------- /header.tex: -------------------------------------------------------------------------------- 1 | 2 | % Allowing for slides with 2 columns 3 | \def\begincols{\begin{columns}[c]} 4 | \def\endcols{\end{columns}} 5 | \def\begincol{\begin{column}{0.5\textwidth}} 6 | \def\endcol{\end{column}} 7 | 8 | 9 | 10 | % Reducing black space between R code and output 11 | % \setlength{\topsep}{0pt}{} 12 | \setlength{\emergencystretch}{0em} 13 | \setlength{\parskip}{2pt} 14 | \setlength{\partopsep}{1pt} 15 | 16 | 17 | 18 | 19 | %%% Reducing font size of R code and output 20 | %%% code below from http://stackoverflow.com/a/38324868 21 | %%% see also http://stackoverflow.com/a/39961605 22 | 23 | % %% change fontsize of R code 24 | % \let\oldShaded\Shaded 25 | % \let\endoldShaded\endShaded 26 | % \renewenvironment{Shaded}{\footnotesize\oldShaded}{\endoldShaded} 27 | % 28 | % %% change fontsize of output 29 | % \let\oldverbatim\verbatim 30 | % \let\endoldverbatim\endverbatim 31 | % \renewenvironment{verbatim}{\footnotesize\oldverbatim}{\endoldverbatim} 32 | % %%% 33 | 34 | 35 | % code below taken from D. Eddelbuettel 36 | % https://github.com/eddelbuettel/samples-rmarkdown-metropolis/blob/master/header.tex 37 | 38 | %% If you have the Fira font installed, to actually have it used it 39 | %% via rmarkdown you need to declare it here 40 | % \setsansfont[ItalicFont={Fira Sans Light Italic},BoldFont={Fira Sans},BoldItalicFont={Fira Sans Italic}]{Fira Sans Light} 41 | % \setmonofont[BoldFont={Fira Mono Medium}]{Fira Mono} 42 | % FRS: but this seems not able to print equations well... 43 | 44 | %% You can set various Metropolis options via \metroset{} here 45 | %\metroset{....} 46 | 47 | %% You can redefine colours, mostly by borrowing from Beamer 48 | %\setbeamercolor{frametitle}{bg=blue} 49 | 50 | %% You also use hyperref, and pick colors 51 | \hypersetup{colorlinks,citecolor=blue,filecolor=blue,linkcolor=blue,urlcolor=blue} 52 | 53 | %% when rendered with rmarkdown, somehow the unicode char for the dot 54 | %% disappears so we redefine it here 55 | %\renewcommand{\textbullet}{$\cdot$} 56 | %\renewcommand{\itemBullet}{▸} % unicode U+25b8 'black right pointing small triangle' 57 | 58 | %% The institute macro puts a small line for affiliation at the bottom 59 | %\institute{Institute of Institutionalism} 60 | 61 | %% We can also place a logo 62 | %\titlegraphic{\hfill\includegraphics[height=1cm]{someLogo.pdf}} 63 | -------------------------------------------------------------------------------- /images/CC-BY-NC-SA_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/CC-BY-NC-SA_logo.png -------------------------------------------------------------------------------- /images/Statistical plots decision chart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/Statistical plots decision chart.jpg -------------------------------------------------------------------------------- /images/aesthetics_Wilke.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/aesthetics_Wilke.png -------------------------------------------------------------------------------- /images/bike_pollution_web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/bike_pollution_web.png -------------------------------------------------------------------------------- /images/cheatsheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/cheatsheet.png -------------------------------------------------------------------------------- /images/christmas_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/christmas_tree.png -------------------------------------------------------------------------------- /images/cloropleth_rudis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/cloropleth_rudis.png -------------------------------------------------------------------------------- /images/egg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/egg.png -------------------------------------------------------------------------------- /images/esquisse_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/esquisse_code.png -------------------------------------------------------------------------------- /images/gganimate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/gganimate.png -------------------------------------------------------------------------------- /images/ggexts.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/ggexts.PNG -------------------------------------------------------------------------------- /images/ggplot2-tutorial-slides.045.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/ggplot2-tutorial-slides.045.png -------------------------------------------------------------------------------- /images/ggraph1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/ggraph1.png -------------------------------------------------------------------------------- /images/ggrepel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/ggrepel.png -------------------------------------------------------------------------------- /images/ggtree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/ggtree.png -------------------------------------------------------------------------------- /images/heatmap_rudis.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/heatmap_rudis.png -------------------------------------------------------------------------------- /images/learningcurve1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/learningcurve1.png -------------------------------------------------------------------------------- /images/learningcurve2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/learningcurve2.png -------------------------------------------------------------------------------- /images/network_plot_final.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/network_plot_final.png -------------------------------------------------------------------------------- /images/patchwork.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/patchwork.PNG -------------------------------------------------------------------------------- /images/plants.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/plants.png -------------------------------------------------------------------------------- /images/plants.png.REMOVED.git-id: -------------------------------------------------------------------------------- 1 | 75d01077ab04187e7b4622c324fb70c493916895 -------------------------------------------------------------------------------- /images/so.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/so.png -------------------------------------------------------------------------------- /images/so2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/so2.png -------------------------------------------------------------------------------- /images/tidy-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/tidy-1.png -------------------------------------------------------------------------------- /images/tidy-9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/tidy-9.png -------------------------------------------------------------------------------- /images/tidy-9b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/tidy-9b.png -------------------------------------------------------------------------------- /images/trevor_tweet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Pakillo/ggplot-intro/07995eb6339502021d3619970064856faa6158e6/images/trevor_tweet.png -------------------------------------------------------------------------------- /plotly.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "plotly demo" 3 | author: "FRS" 4 | output: html_document 5 | --- 6 | 7 | 8 | ```{r} 9 | library(paperplanes) 10 | library(ggplot2) 11 | myplot <- ggplot(paperplanes) + 12 | aes(x = age, y = distance) + 13 | geom_point(aes(colour = gender), size = 4) + 14 | labs(x = "Age (years)", y = "Distance (m)", 15 | title = "my title") 16 | myplot 17 | ``` 18 | 19 | ```{r} 20 | library(plotly) 21 | ggplotly(myplot) 22 | ``` 23 | 24 | --------------------------------------------------------------------------------