├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── lint.yaml │ ├── pkgdown.yaml │ └── test-coverage.yaml ├── .gitignore ├── .lintr ├── DESCRIPTION ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── PrettyCols.Rproj ├── R ├── PrettyCols-package.R ├── PrettyColsPalettes.R ├── colorblind_friendly.R ├── colourblind_friendly.R ├── prettycols.R ├── print_palette.R ├── scale_color_pretty_c.R ├── scale_color_pretty_d.R ├── scale_color_pretty_div.R ├── scale_colour_pretty_c.R ├── scale_colour_pretty_d.R ├── scale_colour_pretty_div.R ├── scale_fill_pretty_c.R ├── scale_fill_pretty_d.R ├── scale_fill_pretty_div.R ├── view_all_palettes.R └── writeJSON.R ├── README.md ├── _pkgdown.yml ├── codecov.yml ├── cran-comments.md ├── man ├── PrettyCols-package.Rd ├── PrettyColsPalettes.Rd ├── colorblind_friendly.Rd ├── colourblind_friendly.Rd ├── figures │ ├── lifecycle-archived.svg │ ├── lifecycle-defunct.svg │ ├── lifecycle-deprecated.svg │ ├── lifecycle-experimental.svg │ ├── lifecycle-maturing.svg │ ├── lifecycle-questioning.svg │ ├── lifecycle-soft-deprecated.svg │ ├── lifecycle-stable.svg │ ├── lifecycle-superseded.svg │ └── logo.png ├── prettycols.Rd ├── scale_color_pretty_c.Rd ├── scale_color_pretty_d.Rd ├── scale_color_pretty_div.Rd ├── scale_colour_pretty_c.Rd ├── scale_colour_pretty_d.Rd ├── scale_colour_pretty_div.Rd ├── scale_fill_pretty_c.Rd ├── scale_fill_pretty_d.Rd ├── scale_fill_pretty_div.Rd └── view_all_palettes.Rd ├── tests ├── testthat.R └── testthat │ ├── test-display.R │ ├── test-palettes.R │ └── test-scales.R └── vignettes ├── .gitignore ├── available-palettes.Rmd ├── colourblind-friendly-palettes.Rmd ├── using-with-ggplot2.Rmd └── viewing-palettes.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^PrettyCols\.Rproj$ 2 | ^\.Rproj\.user$ 3 | .lintr 4 | .github 5 | ^_pkgdown\.yml$ 6 | ^docs$ 7 | ^pkgdown$ 8 | ^\.github$ 9 | ^LICENSE\.md$ 10 | ^codecov\.yml$ 11 | cran-comments.md 12 | ^CRAN-SUBMISSION$ 13 | Python/ 14 | ^revdep$ 15 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | R_KEEP_PKG_SOURCE: yes 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::rcmdcheck 27 | needs: check 28 | 29 | - uses: r-lib/actions/check-r-package@v2 30 | -------------------------------------------------------------------------------- /.github/workflows/lint.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: lint 10 | 11 | jobs: 12 | lint: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | steps: 17 | - uses: actions/checkout@v2 18 | 19 | - uses: r-lib/actions/setup-r@v2 20 | with: 21 | use-public-rspm: true 22 | 23 | - uses: r-lib/actions/setup-r-dependencies@v2 24 | with: 25 | extra-packages: any::lintr, local::. 26 | needs: lint 27 | 28 | - name: Lint 29 | run: lintr::lint_package() 30 | shell: Rscript {0} 31 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/master/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | release: 7 | types: [published] 8 | workflow_dispatch: 9 | 10 | name: pkgdown 11 | 12 | jobs: 13 | pkgdown: 14 | runs-on: ubuntu-latest 15 | env: 16 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-pandoc@v2 21 | 22 | - uses: r-lib/actions/setup-r@v2 23 | with: 24 | use-public-rspm: true 25 | 26 | - uses: r-lib/actions/setup-r-dependencies@v2 27 | with: 28 | extra-packages: any::pkgdown, local::. 29 | needs: website 30 | 31 | - name: Deploy package 32 | run: | 33 | git config --local user.name "$GITHUB_ACTOR" 34 | git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" 35 | Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' 36 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: test-coverage 10 | 11 | jobs: 12 | test-coverage: 13 | runs-on: ubuntu-latest 14 | env: 15 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | 20 | - uses: r-lib/actions/setup-r@v2 21 | with: 22 | use-public-rspm: true 23 | 24 | - uses: r-lib/actions/setup-r-dependencies@v2 25 | with: 26 | extra-packages: any::covr 27 | needs: coverage 28 | 29 | - name: Test coverage 30 | run: covr::codecov(quiet = FALSE) 31 | shell: Rscript {0} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | docs 6 | inst/doc 7 | CRAN-SUBMISSION 8 | revdep/ 9 | -------------------------------------------------------------------------------- /.lintr: -------------------------------------------------------------------------------- 1 | linters: linters_with_defaults( 2 | line_length_linter = line_length_linter(160), 3 | T_and_F_symbol_linter(), 4 | assignment_linter(), 5 | object_name_linter = NULL, 6 | brace_linter = NULL 7 | ) 8 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: PrettyCols 2 | Title: Pretty Colour Palettes 3 | Version: 1.1.0.9003 4 | Authors@R: 5 | person(given = "Nicola", 6 | family = "Rennie", 7 | role = c("aut", "cre"), 8 | email = "nrennie35@gmail.com") 9 | Description: Defines aesthetically pleasing colour palettes. 10 | License: CC0 11 | Encoding: UTF-8 12 | Roxygen: list(markdown = TRUE) 13 | RoxygenNote: 7.3.2 14 | Depends: 15 | R (>= 3.6) 16 | Imports: 17 | ggplot2, 18 | graphics, 19 | grDevices, 20 | lifecycle 21 | Suggests: 22 | covr, 23 | jsonlite, 24 | knitr, 25 | markdown, 26 | purrr, 27 | rmarkdown, 28 | testthat (>= 3.0.0) 29 | Config/Needs/website: nrennie/nrenniepkgdown 30 | URL: https://nrennie.rbind.io/PrettyCols/, https://github.com/nrennie/PrettyCols 31 | BugReports: https://github.com/nrennie/PrettyCols/issues 32 | VignetteBuilder: knitr 33 | Config/testthat/edition: 3 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## creative commons 2 | 3 | # CC0 1.0 Universal 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED HEREUNDER. 6 | 7 | ### Statement of Purpose 8 | 9 | The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). 10 | 11 | Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. 12 | 13 | For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 14 | 15 | 1. __Copyright and Related Rights.__ A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: 16 | 17 | i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; 18 | 19 | ii. moral rights retained by the original author(s) and/or performer(s); 20 | 21 | iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; 22 | 23 | iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; 24 | 25 | v. rights protecting the extraction, dissemination, use and reuse of data in a Work; 26 | 27 | vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and 28 | 29 | vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 30 | 31 | 2. __Waiver.__ To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 32 | 33 | 3. __Public License Fallback.__ Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 34 | 35 | 4. __Limitations and Disclaimers.__ 36 | 37 | a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. 38 | 39 | b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. 40 | 41 | c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. 42 | 43 | d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. 44 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,palette) 4 | export(PrettyColsPalettes) 5 | export(colorblind_friendly) 6 | export(colourblind_friendly) 7 | export(prettycols) 8 | export(scale_color_pretty_c) 9 | export(scale_color_pretty_d) 10 | export(scale_color_pretty_div) 11 | export(scale_colour_pretty_c) 12 | export(scale_colour_pretty_d) 13 | export(scale_colour_pretty_div) 14 | export(scale_fill_pretty_c) 15 | export(scale_fill_pretty_d) 16 | export(scale_fill_pretty_div) 17 | export(view_all_palettes) 18 | importFrom(grDevices,rgb) 19 | importFrom(graphics,image) 20 | importFrom(graphics,par) 21 | importFrom(graphics,rect) 22 | importFrom(graphics,text) 23 | importFrom(lifecycle,deprecated) 24 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | # PrettyCols (development version) 2 | 3 | * Reformat `NEWS.md` 4 | * Fix bug in duplicate names 5 | * Add palettes 6 | * Update seasonal palettes 7 | * Add function to write JSON version 8 | 9 | # PrettyCols 1.1.0 10 | 11 | ## Breaking changes 12 | 13 | * Argument `name` in `scale_*_*()` functions is now used to define the title of the legend, to make this consistent with other {ggplot2} `scale` functions. If you have previously used e.g. `scale_fill_manual(name = "Bright")` to say you want to use the `"Bright"` palette, this will result in an error. Please use `scale_fill_manual(palette = "Bright")` instead. 14 | * Argument `legend_title` in `scale_*_*()` functions is deprecated. Please use `name` instead. For now, `legend_title` still works. 15 | 16 | ## Non-breaking changes 17 | 18 | * Move Python implementation to separate repository 19 | * Add `scale_*_pretty_div()` diverging scale functions 20 | * Changes examples to `mtcars` data 21 | * Remove `scale_name` from `discrete_scale()` calls 22 | * Add {lifecycle} to Imports 23 | * Removed {purrr} dependency 24 | * Add 8 new palettes 25 | 26 | # PrettyCols 1.0.1 27 | 28 | * Add 12 new palettes 29 | * Allow multiple selection of palettes 30 | * Filter by colourblind friendly palettes 31 | * Add `legend_title` argument to scale functions 32 | * Edit `print.palette` to add border 33 | * Update tests and vignettes 34 | * More informative error messages 35 | 36 | # PrettyCols 1.0.0 37 | 38 | * first CRAN submission 39 | * use CC0 license 40 | * remove `complementary_color()` 41 | * add examples to documentation 42 | 43 | # PrettyCols 0.0.7 44 | 45 | * add `view_all_palettes()` function 46 | * add `Autumn`, `Winter`, `Rainbow`, `Teals` and `TealGreens` palettes 47 | * update vignettes 48 | * edit layout of print function slightly 49 | * add basic tests using {testthat} 50 | 51 | # PrettyCols 0.0.6 52 | 53 | * update linting 54 | * update GitHub Actions 55 | * Add `Relax` palette 56 | 57 | # PrettyCols 0.0.5 58 | 59 | * update pkgdown site 60 | 61 | # PrettyCols 0.0.4 62 | 63 | * add new palettes 64 | * add R CMD checks 65 | 66 | # PrettyCols 0.0.3 67 | 68 | * add new palettes 69 | * add vignettes 70 | * add function for finding complementary colour 71 | 72 | # PrettyCols 0.0.2 73 | 74 | * update license 75 | 76 | # PrettyCols 0.0.1 77 | 78 | * initial package 79 | * add MoodyBlues palette 80 | -------------------------------------------------------------------------------- /PrettyCols.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | ProjectId: 799d3a8e-ace7-4b13-b1d8-8b367dc4269f 3 | 4 | RestoreWorkspace: No 5 | SaveWorkspace: No 6 | AlwaysSaveHistory: Default 7 | 8 | EnableCodeIndexing: Yes 9 | UseSpacesForTab: Yes 10 | NumSpacesForTab: 2 11 | Encoding: UTF-8 12 | 13 | RnwWeave: Sweave 14 | LaTeX: pdfLaTeX 15 | 16 | AutoAppendNewline: Yes 17 | StripTrailingWhitespace: Yes 18 | LineEndingConversion: Posix 19 | 20 | BuildType: Package 21 | PackageUseDevtools: Yes 22 | PackageInstallArgs: --no-multiarch --with-keep.source 23 | PackageRoxygenize: rd,collate,namespace 24 | -------------------------------------------------------------------------------- /R/PrettyCols-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | ## usethis namespace: start 5 | #' @importFrom lifecycle deprecated 6 | ## usethis namespace: end 7 | NULL 8 | -------------------------------------------------------------------------------- /R/PrettyColsPalettes.R: -------------------------------------------------------------------------------- 1 | #' Complete list of palettes. 2 | #' 3 | #' Use names(PrettyColsPalettes) to return all palette names. 4 | #' 5 | #' @export 6 | PrettyColsPalettes <- list( 7 | # sequential palettes 8 | Blues = list( 9 | c("#436f85", "#4c7d96", "#548ba7", "#6497b1", "#75a2ba", "#86aec2", "#97b9cb"), 10 | c(1, 2, 3, 4, 5, 6, 7), 11 | "seq", 12 | TRUE 13 | ), 14 | Purples = list( 15 | c("#432263", "#502876", "#5d2f89", "#6a359c", "#773baf", "#8444c0", "#9057c6"), 16 | c(1, 2, 3, 4, 5, 6, 7), 17 | "seq", 18 | TRUE 19 | ), 20 | Tangerines = list( 21 | c("#de7a00", "#F28500", "#FF9B21", "#FFB04F", "#FFC47D", "#ffd6a3", "#ffe1bd"), 22 | c(1, 2, 3, 4, 5, 6, 7), 23 | "seq", 24 | TRUE 25 | ), 26 | Greens = list( 27 | c("#416322", "#4e7628", "#5a892f", "#679c35", "#74af3b", "#80c044", "#8dc657"), 28 | c(1, 2, 3, 4, 5, 6, 7), 29 | "seq", 30 | TRUE 31 | ), 32 | Pinks = list( 33 | c("#860a4d", "#9e0c5b", "#b50e68", "#cd1076", "#e51284", "#ee2290", "#f03a9c"), 34 | c(1, 2, 3, 4, 5, 6, 7), 35 | "seq", 36 | TRUE 37 | ), 38 | Roses = list( 39 | c("#48282F", "#6C3C46", "#90505E", "#B56576", "#C38391", "#D2A2AC", "#E1C1C8"), 40 | c(1, 2, 3, 4, 5, 6, 7), 41 | "seq", 42 | TRUE 43 | ), 44 | Teals = list( 45 | c("#004c4c", "#006666", "#008080", "#329999", "#66b2b2", "#99cccc", "#cce5e5"), 46 | c(1, 2, 3, 4, 5, 6, 7), 47 | "seq", 48 | TRUE 49 | ), 50 | Yellows = list( 51 | c("#e6b400", "#E6C700", "#e8d119", "#ebd632", "#f0e066", "#f2e57f", "#f7efb2"), 52 | c(1, 2, 3, 4, 5, 6, 7), 53 | "seq", 54 | TRUE 55 | ), 56 | Reds = list( 57 | c("#B53737", "#BE5151", "#C76B6B", "#D08585", "#D99F9F", "#E3B9B9", "#ECD3D3"), 58 | c(1, 2, 3, 4, 5, 6, 7), 59 | "seq", 60 | TRUE 61 | ), 62 | Greys = list( 63 | c("#171517", "#363236", "#554F55", "#746D75", "#999399", "#BEBABE", "#E3E1E3"), 64 | c(1, 2, 3, 4, 5, 6, 7), 65 | "seq", 66 | TRUE 67 | ), 68 | Aubergines = list( 69 | c("#200116", "#361A2D", "#4C3344", "#624D5B", "#796673", "#8F808A", "#A599A1"), 70 | c(1, 2, 3, 4, 5, 6, 7), 71 | "seq", 72 | TRUE 73 | ), 74 | Browns = list( 75 | c("#24140E", "#542F22", "#844A36", "#B4654A", "#C88E7A", "#DCB7AA", "#F0E0DA"), 76 | c(1, 2, 3, 4, 5, 6, 7), 77 | "seq", 78 | TRUE 79 | ), 80 | # diverging palettes 81 | PurpleGreens = list( 82 | c("#420f75", "#7640a9", "#ad72d6", "#e7a8fb", "#f5f5f5", "#99ce64", "#659a32", "#326812", "#033800"), 83 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 84 | "div", 85 | TRUE 86 | ), 87 | PinkGreens = list( 88 | c("#7f0038", "#c31e6e", "#ef5faf", "#fcaade", "#f5f5f5", "#99ce64", "#659a32", "#326812", "#033800"), 89 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 90 | "div", 91 | TRUE 92 | ), 93 | TangerineBlues = list( 94 | c("#552000", "#8a4d00", "#c17d17", "#f8b150", "#f5f5f5", "#93c6e1", "#5f93ac", "#2e627a", "#00344a"), 95 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 96 | "div", 97 | TRUE 98 | ), 99 | PurpleTangerines = list( 100 | c("#420f75", "#7640a9", "#ad72d6", "#e7a8fb", "#f5f5f5", "#f8b150", "#c17d17", "#8a4d00", "#552000"), 101 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 102 | "div", 103 | TRUE 104 | ), 105 | PurplePinks = list( 106 | c("#420f75", "#7640a9", "#ad72d6", "#e7a8fb", "#f5f5f5", "#fcaade", "#ef5faf", "#c31e6e", "#7f0038"), 107 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 108 | "div", 109 | FALSE 110 | ), 111 | TealGreens = list( 112 | c("#00393a", "#0a6969", "#2d9c9c", "#6dcfcf", "#f5f5f5", "#99ce64", "#659a32", "#326812", "#033800"), 113 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 114 | "div", 115 | FALSE 116 | ), 117 | PurpleYellows = list( 118 | c("#420f75", "#7640a9", "#ad72d6", "#e7a8fb", "#f5f5f5", "#F2E8C4", "#EED682", "#EAC541", "#E6B400"), 119 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 120 | "div", 121 | TRUE 122 | ), 123 | RedBlues = list( 124 | c("#B53737", "#C66969", "#D79C9C", "#E8CFCF", "#f5f5f5", "#93c6e1", "#5f93ac", "#2e627a", "#00344a"), 125 | c(1, 2, 3, 4, 5, 6, 7, 8, 9), 126 | "div", 127 | TRUE 128 | ), 129 | # 5 qualitative colours 130 | Bold = list( 131 | c("#6497b1", "#6a359c", "#FFB04F", "#679c35", "#cd1076"), 132 | c(1, 2, 3, 4, 5), 133 | "qual", 134 | FALSE 135 | ), 136 | Dark = list( 137 | c("#436f85", "#432263", "#de7a00", "#416322", "#860a4d"), 138 | c(1, 2, 3, 4, 5), 139 | "qual", 140 | FALSE 141 | ), 142 | Light = list( 143 | c("#97b9cb", "#9057c6", "#ffe1bd", "#8dc657", "#f03a9c"), 144 | c(1, 2, 3, 4, 5), 145 | "qual", 146 | FALSE 147 | ), 148 | Beach = list( 149 | c("#0e7c7b", "#17bebb", "#d4f4dd", "#d62246", "#4b1d3f"), 150 | c(1, 2, 3, 4, 5), 151 | "qual", 152 | FALSE 153 | ), 154 | Fun = list( 155 | c("#134074", "#bfab25", "#4ea699", "#efb0a1", "#df2935"), 156 | c(1, 2, 3, 4, 5), 157 | "qual", 158 | TRUE 159 | ), 160 | Sea = list( 161 | c("#86CB92", "#71B48D", "#404E7C", "#3a3559", "#260F26"), 162 | c(1, 2, 3, 4, 5), 163 | "qual", 164 | TRUE 165 | ), 166 | Bright = list( 167 | c("#462255", "#FF8811", "#9DD9D2", "#046E8F", "#D44D5C"), 168 | c(1, 2, 3, 4, 5), 169 | "qual", 170 | FALSE 171 | ), 172 | Relax = list( 173 | c("#4B3F72", "#CBB3BF", "#FFC857", "#119DA4", "#19647E"), 174 | c(1, 2, 3, 4, 5), 175 | "qual", 176 | FALSE 177 | ), 178 | Lucent = list( 179 | c("#E01A4F", "#F15946", "#F9C22E", "#53B3CB", "#7DCFB6"), 180 | c(1, 2, 3, 4, 5), 181 | "qual", 182 | FALSE 183 | ), 184 | Lively = list( 185 | c("#413C58", "#D1495B", "#EDAE49", "#00798C", "#003D5B"), 186 | c(1, 2, 3, 4, 5), 187 | "qual", 188 | FALSE 189 | ), 190 | Joyful = list( 191 | c("#80A1C1", "#C94277", "#EEE3AB", "#274C77", "#5E8C61"), 192 | c(1, 2, 3, 4, 5), 193 | "qual", 194 | FALSE 195 | ), 196 | Coast = list( 197 | c("#16425B", "#48A9A6", "#E4DFDA", "#D4B483", "#C1666B"), 198 | c(1, 2, 3, 4, 5), 199 | "qual", 200 | FALSE 201 | ), 202 | Ocean = list( 203 | c("#0B132B", "#1C2541", "#3A506B", "#5BC0BE", "#6FFFE9"), 204 | c(1, 2, 3, 4, 5), 205 | "qual", 206 | FALSE 207 | ), 208 | Peppers = list( 209 | c("#8EA604", "#F5BB00", "#EC9F05", "#D76A03", "#BF3100"), 210 | c(1, 2, 3, 4, 5), 211 | "qual", 212 | FALSE 213 | ), 214 | Disco = list( 215 | c("#F75C03", "#D90368", "#04A777", "#820263", "#F4E409"), 216 | c(1, 2, 3, 4, 5), 217 | "qual", 218 | FALSE 219 | ), 220 | Prism = list( 221 | c("#D97E80", "#F5E466", "#FDFFFC", "#B1CFA3", "#7A9AB7"), 222 | c(1, 2, 3, 4, 5), 223 | "qual", 224 | FALSE 225 | ), 226 | # 6 qualitative colours 227 | Neon = list( 228 | c("#ff9062", "#fd6598", "#cb64c0", "#3294dd", "#75fb8a", "#d0eb60"), 229 | c(1, 2, 3, 4, 5, 6), 230 | "qual", 231 | FALSE 232 | ), 233 | Oasis = list( 234 | c("#AE8A1E", "#0C3A61", "#D60CB6", "#09CED0", "#4D08C5", "#F760BD"), 235 | c(1, 2, 3, 4, 5, 6), 236 | "qual", 237 | FALSE 238 | ), 239 | Celestial = list( 240 | c("#A053A1", "#DB778F", "#E69F52", "#09A39A", "#5869C7", "#004B67"), 241 | c(1, 2, 3, 4, 5, 6), 242 | "qual", 243 | FALSE 244 | ), 245 | Aurora = list( 246 | c("#53113F", "#6C1A41", "#ABEF07", "#059C59", "#295542", "#5C8797"), 247 | c(1, 2, 3, 4, 5, 6), 248 | "qual", 249 | FALSE 250 | ), 251 | # 12 qualitative colours 252 | Spring = list( 253 | c( 254 | "#CAF9A9", "#ECBBC2", "#B3EDAA", "#B2E3E7", "#D3ECDF", "#E5FCAA", 255 | "#F4FFC7", "#E9C7A2", "#E6B7AD", "#D2EDAD", "#EBD993", "#C4E2B8" 256 | ), 257 | c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 258 | "qual", 259 | FALSE 260 | ), 261 | Summer = list( 262 | c( 263 | "#808FBB", "#E0A662", "#785B57", "#AC9567", "#AE7F5B", "#968262", 264 | "#9993B5", "#837189", "#C57253", "#F79D50", "#C086BF", "#EC94CA" 265 | ), 266 | c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 267 | "qual", 268 | FALSE 269 | ), 270 | Autumn = list( 271 | c( 272 | "#915646", "#BA6E1D", "#CA9C2F", "#905C23", "#DBB053", "#5D6538", 273 | "#A14E17", "#7F603E", "#DA8E28", "#917836", "#972C0B", "#5A4E3E" 274 | ), 275 | c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 276 | "qual", 277 | FALSE 278 | ), 279 | Winter = list( 280 | c( 281 | "#829BAB", "#CDD4E0", "#9F9C9F", "#D0DEEC", "#8F9CA9", "#C9CDF5", 282 | "#BAD0E3", "#BBBCAE", "#E1E3E7", "#777E85", "#B7BFC7", "#D3E6EF" 283 | ), 284 | c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 285 | "qual", 286 | FALSE 287 | ), 288 | Rainbow = list( 289 | c( 290 | "#e51e32", "#ff782a", "#fda805", "#e2cf04", "#b1ca05", "#98c217", 291 | "#779815", "#029e77", "#09989c", "#059ccd", "#3f64ce", "#7e2b8e" 292 | ), 293 | c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 294 | "qual", 295 | FALSE 296 | ), 297 | Velvet = list( 298 | c( 299 | "#3C0C48", "#7A3886", "#4E105C", "#501196", "#6E4183", "#46135A", 300 | "#483B75", "#383071", "#39457D", "#78146C", "#890E5C", "#451130" 301 | ), 302 | c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), 303 | "qual", 304 | FALSE 305 | ) 306 | ) 307 | -------------------------------------------------------------------------------- /R/colorblind_friendly.R: -------------------------------------------------------------------------------- 1 | #' Returns a data frame of colorblind friendly colour palettes 2 | #' 3 | #' @param palettes List of palettes. Default PrettyColsPalettes. 4 | #' @examples 5 | #' colorblind_friendly() 6 | #' @return A data frame with two columns giving names and types of colourblind 7 | #' friendly palettes. 8 | #' @export 9 | 10 | colorblind_friendly <- function(palettes = PrettyColsPalettes) { 11 | cbf <- unlist(lapply(palettes, `[[`, 4)) 12 | cbf_palettes <- palettes[unname(which(cbf == TRUE))] 13 | cbf_palettes_df <- data.frame( 14 | name = names(cbf_palettes), 15 | type = unname(unlist(lapply(cbf_palettes, `[[`, 3))) 16 | ) 17 | return(cbf_palettes_df) 18 | } 19 | -------------------------------------------------------------------------------- /R/colourblind_friendly.R: -------------------------------------------------------------------------------- 1 | #' Returns a data frame of colourblind friendly colour palettes 2 | #' 3 | #' @param palettes List of palettes. Default PrettyColsPalettes. 4 | #' @examples 5 | #' colourblind_friendly() 6 | #' @return A data frame with two columns giving names and types of colourblind 7 | #' friendly palettes. 8 | #' @export 9 | 10 | colourblind_friendly <- function(palettes = PrettyColsPalettes) { 11 | cbf <- unlist(lapply(palettes, `[[`, 4)) 12 | cbf_palettes <- palettes[unname(which(cbf == TRUE))] 13 | cbf_palettes_df <- data.frame( 14 | name = names(cbf_palettes), 15 | type = unname(unlist(lapply(cbf_palettes, `[[`, 3))) 16 | ) 17 | return(cbf_palettes_df) 18 | } 19 | -------------------------------------------------------------------------------- /R/prettycols.R: -------------------------------------------------------------------------------- 1 | #' Generates the colour palettes 2 | #' 3 | #' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. 4 | #' @param n Number of desired colors. If number of requested colors is beyond the scope of the palette, 5 | #' colors are automatically interpolated. If n is not provided, the length of the palette is used. 6 | #' @param type Either "continuous" or "discrete". Use continuous if you want to automatically 7 | #' interpolate between colors. Default "discrete" 8 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, palette color order is reversed 9 | #' @return A character vector of hex colour codes. 10 | #' @examples 11 | #' prettycols("Blues") 12 | #' @export 13 | 14 | prettycols <- function(palette, 15 | n, 16 | type = "discrete", 17 | direction = 1) { 18 | `%notin%` <- Negate(`%in%`) 19 | 20 | palette_choice <- PrettyColsPalettes[[palette]] 21 | 22 | if (is.null(palette_choice) || is.numeric(palette)) { 23 | stop("Palette name does not exist. Use names(PrettyColsPalettes) to find valid palette name.") 24 | } 25 | 26 | if (missing(n)) { 27 | n <- length(palette_choice[[1]]) 28 | } 29 | 30 | if (direction %notin% c(1, -1)) { 31 | stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") 32 | } 33 | 34 | if (type %notin% c("discrete", "continuous")) { 35 | stop("Invalid palette type. Must be one of 'discrete' or 'continuous'.") 36 | } 37 | 38 | if (type == "discrete" && n > length(palette_choice[[1]])) { 39 | stop("Number of requested colors greater than what discrete palette can offer, use continuous instead.") 40 | } 41 | 42 | continuous <- if (direction == 1) { 43 | grDevices::colorRampPalette(palette_choice[[1]])(n) 44 | } else { 45 | grDevices::colorRampPalette(rev(palette_choice[[1]]))(n) 46 | } 47 | 48 | discrete <- if (direction == 1) { 49 | palette_choice[[1]][1:n] 50 | } else { 51 | rev(palette_choice[[1]])[1:n] 52 | } 53 | 54 | out <- switch(type, 55 | continuous = continuous, 56 | discrete = discrete 57 | ) 58 | 59 | structure(out, class = "palette", palette = palette) 60 | } 61 | -------------------------------------------------------------------------------- /R/print_palette.R: -------------------------------------------------------------------------------- 1 | # Function for printing palette 2 | #' @export 3 | #' @importFrom grDevices rgb 4 | #' @importFrom graphics rect par image text 5 | 6 | print.palette <- function(x, ...) { 7 | n <- length(x) 8 | old <- graphics::par(mar = c(0, 0, 0, 0)) 9 | on.exit(graphics::par(old)) 10 | graphics::image(1:n, 1, as.matrix(1:n), 11 | col = x, 12 | ylab = "", xaxt = "n", yaxt = "n", bty = "n" 13 | ) 14 | graphics::rect(0, 0.92, n + 1, 1.08, 15 | col = grDevices::rgb(0, 0, 0, 0.6), 16 | border = NA 17 | ) 18 | graphics::rect(0.5, 0.6, n + 0.5, 1.4, 19 | col = NA, 20 | lwd = 4, 21 | border = "black" 22 | ) 23 | graphics::text((n + 1) / 2, 1, 24 | labels = attr(x, "palette"), 25 | cex = 1.5, 26 | family = "sans", 27 | col = grDevices::rgb(1, 1, 1, 1) 28 | ) 29 | } 30 | -------------------------------------------------------------------------------- /R/scale_color_pretty_c.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. 3 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 4 | #' palette color order is reversed 5 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 6 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{scale_color_gradientn}} 7 | #' @return A ggproto object defining a continuous colour scale for use with ggplot2. 8 | #' @examples 9 | #' library(ggplot2) 10 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, color = wt)) + 11 | #' geom_point() + 12 | #' scale_color_pretty_c("Greens") 13 | #' @export 14 | 15 | scale_color_pretty_c <- function(palette, 16 | direction = 1, 17 | legend_title = NULL, ...) { 18 | if (missing(palette)) { 19 | stop("Please use the 'palette' argument to define which colour palette you want to use.") 20 | } 21 | 22 | if (!is.null(legend_title)) { 23 | lifecycle::deprecate_soft( 24 | when = "1.1.0", 25 | what = "scale_color_pretty_c(legend_title)", 26 | details = "Please use `name` to set the legend title instead." 27 | ) 28 | } 29 | 30 | `%notin%` <- Negate(`%in%`) 31 | 32 | palette_choice <- PrettyColsPalettes[[palette]] 33 | 34 | if (is.null(palette_choice) || is.numeric(palette)) { 35 | stop("Palette does not exist.") 36 | } 37 | 38 | if (direction %notin% c(1, -1)) { 39 | stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") 40 | } 41 | 42 | if (!is.null(legend_title)) { 43 | ggplot2::scale_color_gradientn( 44 | name = legend_title, 45 | colors = prettycols(palette = palette, direction = direction), ... 46 | ) 47 | } else { 48 | ggplot2::scale_color_gradientn( 49 | colors = prettycols(palette = palette, direction = direction), ... 50 | ) 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /R/scale_color_pretty_d.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. 3 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 4 | #' palette color order is reversed 5 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 6 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{discrete_scale}} 7 | #' @return A ggproto object defining a discrete colour scale for use with ggplot2. 8 | #' @examples 9 | #' library(ggplot2) 10 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, color = factor(cyl))) + 11 | #' geom_point() + 12 | #' scale_color_pretty_d("Bright") 13 | #' @export 14 | 15 | scale_color_pretty_d <- function(palette, 16 | direction = 1, 17 | legend_title = NULL, ...) { 18 | if (missing(palette)) { 19 | stop("Please use the 'palette' argument to define which colour palette you want to use.") 20 | } 21 | 22 | if (!is.null(legend_title)) { 23 | lifecycle::deprecate_soft( 24 | when = "1.1.0", 25 | what = "scale_color_pretty_d(legend_title)", 26 | details = "Please use `name` to set the legend title instead." 27 | ) 28 | } 29 | 30 | prettycols_disc <- function(palette, direction = 1) { 31 | `%notin%` <- Negate(`%in%`) 32 | 33 | palette_choice <- PrettyColsPalettes[[palette]] 34 | 35 | if (is.null(palette_choice) || is.numeric(palette)) { 36 | stop("Palette does not exist.") 37 | } 38 | 39 | if (direction %notin% c(1, -1)) { 40 | stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") 41 | } 42 | 43 | function(n) { 44 | if (direction == 1) { 45 | palette_choice[[1]][1:n] 46 | } else { 47 | rev(palette_choice[[1]])[1:n] 48 | } 49 | } 50 | } 51 | 52 | if (!is.null(legend_title)) { 53 | ggplot2::discrete_scale( 54 | name = legend_title, 55 | aesthetics = "colour", 56 | palette = prettycols_disc(palette = palette, direction = direction), ... 57 | ) 58 | } else { 59 | ggplot2::discrete_scale( 60 | aesthetics = "colour", 61 | palette = prettycols_disc(palette = palette, direction = direction), ... 62 | ) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /R/scale_color_pretty_div.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{view_all_palettes(type = "div")} to view 3 | #' options. Must be a diverging palette name. 4 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 5 | #' palette color order is reversed 6 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 7 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradient2}} 8 | #' @return A ggproto object defining a continuous colour scale for use with ggplot2. 9 | #' @examples 10 | #' library(ggplot2) 11 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, colour = wt)) + 12 | #' geom_point() + 13 | #' scale_color_pretty_div("PurpleYellows", midpoint = mean(mtcars$wt)) 14 | #' @export 15 | 16 | scale_color_pretty_div <- function(palette, 17 | direction = 1, 18 | legend_title = NULL, ...) { 19 | if (missing(palette)) { 20 | stop("Please use the 'palette' argument to define which colour palette you want to use.") 21 | } 22 | 23 | if (!is.null(legend_title)) { 24 | lifecycle::deprecate_soft( 25 | when = "1.1.0", 26 | what = "scale_color_pretty_div(legend_title)", 27 | details = "Please use `name` to set the legend title instead." 28 | ) 29 | } 30 | `%notin%` <- Negate(`%in%`) 31 | 32 | palette_choice <- PrettyColsPalettes[[palette]] 33 | 34 | if (is.null(palette_choice) || is.numeric(palette)) { 35 | stop("Palette does not exist.") 36 | } 37 | 38 | if (palette_choice[[3]] != "div") { 39 | stop("Palette must be a diverging palette.") 40 | } 41 | 42 | if (direction %notin% c(1, -1)) { 43 | stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") 44 | } 45 | 46 | if (direction == 1) { 47 | low_col <- palette_choice[[1]][1] 48 | high_col <- utils::tail(palette_choice[[1]], 1) 49 | } else { 50 | low_col <- utils::tail(palette_choice[[1]], 1) 51 | high_col <- palette_choice[[1]][1] 52 | } 53 | mid_col <- palette_choice[[1]][ceiling(length(palette_choice[[1]]) / 2)] 54 | 55 | 56 | if (!is.null(legend_title)) { 57 | ggplot2::scale_color_gradient2( 58 | name = legend_title, 59 | low = low_col, 60 | mid = mid_col, 61 | high = high_col, ... 62 | ) 63 | } else { 64 | ggplot2::scale_color_gradient2( 65 | low = low_col, 66 | mid = mid_col, 67 | high = high_col, ... 68 | ) 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /R/scale_colour_pretty_c.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. 3 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 4 | #' palette color order is reversed 5 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 6 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradientn}} 7 | #' @return A ggproto object defining a continuous colour scale for use with ggplot2. 8 | #' @examples 9 | #' library(ggplot2) 10 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, colour = wt)) + 11 | #' geom_point() + 12 | #' scale_colour_pretty_c("Greens") 13 | #' @export 14 | 15 | scale_colour_pretty_c <- scale_color_pretty_c 16 | -------------------------------------------------------------------------------- /R/scale_colour_pretty_d.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. 3 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 4 | #' palette color order is reversed 5 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 6 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{discrete_scale}} 7 | #' @return A ggproto object defining a discrete colour scale for use with ggplot2. 8 | #' @examples 9 | #' library(ggplot2) 10 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, colour = factor(cyl))) + 11 | #' geom_point() + 12 | #' scale_colour_pretty_d("Bright") 13 | #' @export 14 | 15 | scale_colour_pretty_d <- scale_color_pretty_d 16 | -------------------------------------------------------------------------------- /R/scale_colour_pretty_div.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{view_all_palettes(type = "div")} to view 3 | #' options. Must be a diverging palette name. 4 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 5 | #' palette color order is reversed 6 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 7 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradient2}} 8 | #' @return A ggproto object defining a continuous colour scale for use with ggplot2. 9 | #' @examples 10 | #' library(ggplot2) 11 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, colour = wt)) + 12 | #' geom_point() + 13 | #' scale_colour_pretty_div("PurpleYellows", midpoint = mean(mtcars$wt)) 14 | #' @export 15 | 16 | scale_colour_pretty_div <- scale_color_pretty_div 17 | -------------------------------------------------------------------------------- /R/scale_fill_pretty_c.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. 3 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 4 | #' palette color order is reversed 5 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 6 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{scale_fill_gradientn}} 7 | #' @return A ggproto object defining a continuous fill scale for use with ggplot2. 8 | #' @examples 9 | #' library(ggplot2) 10 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, fill = wt)) + 11 | #' geom_point(pch = 21) + 12 | #' scale_fill_pretty_c("Greens") 13 | #' @export 14 | 15 | scale_fill_pretty_c <- function(palette, 16 | direction = 1, 17 | legend_title = NULL, ...) { 18 | if (missing(palette)) { 19 | stop("Please use the 'palette' argument to define which colour palette you want to use.") 20 | } 21 | 22 | if (!is.null(legend_title)) { 23 | lifecycle::deprecate_soft( 24 | when = "1.1.0", 25 | what = "scale_fill_pretty_c(legend_title)", 26 | details = "Please use `name` to set the legend title instead." 27 | ) 28 | } 29 | 30 | `%notin%` <- Negate(`%in%`) 31 | 32 | palette_choice <- PrettyColsPalettes[[palette]] 33 | 34 | if (is.null(palette_choice) || is.numeric(palette)) { 35 | stop("Palette does not exist.") 36 | } 37 | 38 | if (direction %notin% c(1, -1)) { 39 | stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") 40 | } 41 | 42 | if (!is.null(legend_title)) { 43 | ggplot2::scale_fill_gradientn( 44 | name = legend_title, 45 | colors = prettycols(palette = palette, direction = direction), ... 46 | ) 47 | } else { 48 | ggplot2::scale_fill_gradientn(colors = prettycols(palette = palette, direction = direction), ...) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /R/scale_fill_pretty_d.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for colour ggplot2 2 | #' @param palette Name of Palette. Run \code{names(PrettyColsPalettes)} to view options. 3 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 4 | #' palette color order is reversed 5 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 6 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{discrete_scale}} 7 | #' @return A ggproto object defining a discrete fill scale for use with ggplot2. 8 | #' @examples 9 | #' library(ggplot2) 10 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, fill = factor(cyl))) + 11 | #' geom_point(pch = 21) + 12 | #' scale_fill_pretty_d("Bright") 13 | #' @export 14 | 15 | scale_fill_pretty_d <- function(palette, 16 | direction = 1, 17 | legend_title = NULL, ...) { 18 | if (missing(palette)) { 19 | stop("Please use the 'palette' argument to define which colour palette you want to use.") 20 | } 21 | 22 | if (!is.null(legend_title)) { 23 | lifecycle::deprecate_soft( 24 | when = "1.1.0", 25 | what = "scale_fill_pretty_d(legend_title)", 26 | details = "Please use `name` to set the legend title instead." 27 | ) 28 | } 29 | 30 | prettycols_disc <- function(palette, direction = 1) { 31 | `%notin%` <- Negate(`%in%`) 32 | 33 | palette_choice <- PrettyColsPalettes[[palette]] 34 | 35 | if (is.null(palette_choice) || is.numeric(palette)) { 36 | stop("Palette does not exist.") 37 | } 38 | 39 | if (direction %notin% c(1, -1)) { 40 | stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") 41 | } 42 | 43 | function(n) { 44 | if (direction == 1) { 45 | palette_choice[[1]][1:n] 46 | } else { 47 | rev(palette_choice[[1]])[1:n] 48 | } 49 | } 50 | } 51 | 52 | if (!is.null(legend_title)) { 53 | ggplot2::discrete_scale( 54 | name = legend_title, 55 | aesthetics = "fill", 56 | palette = prettycols_disc(palette = palette, direction = direction), ... 57 | ) 58 | } else { 59 | ggplot2::discrete_scale( 60 | aesthetics = "fill", 61 | palette = prettycols_disc(palette = palette, direction = direction), ... 62 | ) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /R/scale_fill_pretty_div.R: -------------------------------------------------------------------------------- 1 | #' Plotting with PrettyCols palettes for fill colour ggplot2 2 | #' @param palette Name of Palette. Run \code{view_all_palettes(type = "div")} to view 3 | #' options. Must be a diverging palette name. 4 | #' @param direction Sets order of colors. Default palette is 1. If direction is -1, 5 | #' palette color order is reversed 6 | #' @param legend_title `r lifecycle::badge("deprecated")` Deprecated in favour of `name`. 7 | #' @param ... Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradient2}} 8 | #' @return A ggproto object defining a continuous colour scale for use with ggplot2. 9 | #' @examples 10 | #' library(ggplot2) 11 | #' ggplot(data = mtcars, aes(x = mpg, y = disp, fill = wt)) + 12 | #' geom_point(pch = 21) + 13 | #' scale_fill_pretty_div("PurpleYellows", midpoint = mean(mtcars$wt)) 14 | #' @export 15 | 16 | scale_fill_pretty_div <- function(palette, 17 | direction = 1, 18 | legend_title = NULL, ...) { 19 | if (missing(palette)) { 20 | stop("Please use the 'palette' argument to define which colour palette you want to use.") 21 | } 22 | 23 | if (!is.null(legend_title)) { 24 | lifecycle::deprecate_soft( 25 | when = "1.1.0", 26 | what = "scale_fill_pretty_div(legend_title)", 27 | details = "Please use `name` to set the legend title instead." 28 | ) 29 | } 30 | 31 | `%notin%` <- Negate(`%in%`) 32 | 33 | palette_choice <- PrettyColsPalettes[[palette]] 34 | 35 | if (is.null(palette_choice) || is.numeric(palette)) { 36 | stop("Palette does not exist.") 37 | } 38 | 39 | if (palette_choice[[3]] != "div") { 40 | stop("Palette must be a diverging palette.") 41 | } 42 | 43 | if (direction %notin% c(1, -1)) { 44 | stop("Direction not valid. Please use 1 for standard palette or -1 for reversed palette.") 45 | } 46 | 47 | if (direction == 1) { 48 | low_col <- palette_choice[[1]][1] 49 | high_col <- utils::tail(palette_choice[[1]], 1) 50 | } else { 51 | low_col <- utils::tail(palette_choice[[1]], 1) 52 | high_col <- palette_choice[[1]][1] 53 | } 54 | mid_col <- palette_choice[[1]][ceiling(length(palette_choice[[1]]) / 2)] 55 | 56 | 57 | if (!is.null(legend_title)) { 58 | ggplot2::scale_fill_gradient2( 59 | name = legend_title, 60 | low = low_col, 61 | mid = mid_col, 62 | high = high_col, ... 63 | ) 64 | } else { 65 | ggplot2::scale_fill_gradient2( 66 | low = low_col, 67 | mid = mid_col, 68 | high = high_col, ... 69 | ) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /R/view_all_palettes.R: -------------------------------------------------------------------------------- 1 | #' Prints all available colour palettes 2 | #' 3 | #' @param type Type of colour palettes to view. Either all palettes, sequential palettes, 4 | #' diverging palettes, or qualitative palettes. Types must be at least one of c("all", "seq", "div", "qual"). 5 | #' Default "all". 6 | #' @param colourblind_friendly Boolean whether or not to return only colourblind friendly 7 | #' palettes. Default `FALSE`. 8 | #' @examples 9 | #' view_all_palettes(type = "seq") 10 | #' view_all_palettes(type = c("seq", "div")) 11 | #' view_all_palettes(type = "div", colourblind_friendly = TRUE) 12 | #' @return A plot of all colour palettes available in the package. 13 | #' @export 14 | 15 | view_all_palettes <- function(type = "all", 16 | colourblind_friendly = FALSE) { 17 | `%notin%` <- Negate(`%in%`) 18 | 19 | if (any(type %notin% c("all", "seq", "div", "qual"))) { 20 | stop("Invalid 'type'. Must be at least one of c('all', 'seq', 'div', 'qual').") 21 | } else { 22 | if (any(type %in% "all")) { 23 | if (colourblind_friendly == TRUE) { 24 | cbf <- unlist(lapply(PrettyColsPalettes, `[[`, 4)) 25 | to_print <- PrettyColsPalettes[unname(which(cbf == TRUE))] 26 | } else { 27 | to_print <- PrettyColsPalettes 28 | } 29 | n_all <- length(to_print) 30 | n_col <- min(4, floor(sqrt(n_all))) 31 | n_row <- ceiling(n_all / n_col) 32 | par(mfrow = c(n_row, n_col)) 33 | lapply(names(to_print), function(.x) print(prettycols(.x))) 34 | par(mfrow = c(1, 1)) 35 | } else { 36 | if (colourblind_friendly == TRUE) { 37 | cbf <- unlist(lapply(PrettyColsPalettes, `[[`, 4)) 38 | to_print <- PrettyColsPalettes[unname(which(cbf == TRUE))] 39 | } else { 40 | to_print <- PrettyColsPalettes 41 | } 42 | # filter palettes by type 43 | types <- unlist(lapply(to_print, `[[`, 3)) 44 | filtered_palettes <- to_print[unname(which(types %in% type))] 45 | n_all <- length(filtered_palettes) 46 | n_col <- min(3, floor(sqrt(n_all))) 47 | n_row <- ceiling(n_all / n_col) 48 | par(mfrow = c(n_row, n_col)) 49 | lapply(names(filtered_palettes), function(.x) print(prettycols(.x))) 50 | par(mfrow = c(1, 1)) 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /R/writeJSON.R: -------------------------------------------------------------------------------- 1 | #' Function to write R object to JSON 2 | #' @param file File name to save file as 3 | #' @noRd 4 | 5 | writeJSON <- function(file = "PrettyCols.js") { 6 | name_labels <- c("colors", "order", "type", "colorblindFriendly") # nolint 7 | purrr::map( 8 | .x = PrettyColsPalettes, 9 | .f = ~ setNames(.x, name_labels) 10 | ) |> 11 | jsonlite::write_json( 12 | path = file, 13 | pretty = TRUE, auto_unbox = TRUE 14 | ) 15 | js_txt <- readLines(file) 16 | js_txt[1] <- "PrettyCols={" 17 | writeLines(js_txt, con = file) 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![R-CMD-check](https://github.com/nrennie/PrettyCols/workflows/R-CMD-check/badge.svg)](https://github.com/nrennie/PrettyCols/actions) 3 | [![codecov](https://codecov.io/gh/nrennie/PrettyCols/branch/main/graph/badge.svg)](https://app.codecov.io/gh/nrennie/PrettyCols?branch=main) 4 | [![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/PrettyCols)](https://cran.r-project.org/package=PrettyCols) 5 | 6 | 7 | 8 | # PrettyCols 9 | 10 | {PrettyCols} is an R package containing aesthetically pleasing colour palettes. 11 | 12 | The structure of the package is based on code from the [{PNWColors}](https://github.com/jakelawlor/PNWColors), [{wesanderson}](https://github.com/karthik/wesanderson), and [{MetBrewer}](https://github.com/BlakeRMills/MetBrewer) packages. 13 | 14 | ## Installation 15 | 16 | {PrettyCols} is available on CRAN. Install using: 17 | ``` r 18 | install.packages("PrettyCols") 19 | ``` 20 | or install the development version from GitHub: 21 | ``` r 22 | remotes::install_github("nrennie/PrettyCols") 23 | ``` 24 | 25 | See [nrennie.rbind.io/PrettyCols](https://nrennie.rbind.io/PrettyCols/) for full documentation. 26 | 27 | If you have a suggestion of an additional feature, or find a bug, please file an issue on the [GitHub repository](https://github.com/nrennie/PrettyCols/issues). 28 | 29 | ## Using {PrettyCols} with other software. 30 | 31 | * A Python implementation of this package can be found at [github.com/nrennie/PrettyPyCols](https://github.com/nrennie/PrettyPyCols). 32 | 33 | * QGIS users can use {PrettyCols} through QGIS Style at [plugins.qgis.org/styles/192](https://plugins.qgis.org/styles/192/). Thanks to [@Heed725](https://github.com/Heed725) for the implementation! 34 | 35 | ## Contributor guidelines 36 | 37 | If you'd like to contribute to {PrettyCols}, I'd welcome your help. If you're making a PR, please follow the guidelines below, to make the collaboration easier: 38 | 39 | - You have updated the NEWS and version number in DESCRIPTION. 40 | - You have checked that R CMD check passes with no ERRORs or WARNINGs. If there is a NOTE - please outline what it is in the PR. 41 | - You have checked that `lintr::lint_package()` passes. 42 | - You have checked the list of packages in Imports is still in alphabetical order to enable better tracking of dependencies as the package grows. 43 | - You have not used the base R `|>` pipe (we're not quite ready to specify R 4.1 or higher as a dependency yet!). 44 | - If this is a feature request PR (not a bug fix) please make sure it relates to an issue that has not been assigned to someone else (and tag the issue in the PR description). 45 | 46 | If these checks fail, and there is no response from the PR author for 1 month, the PR will be automatically closed. 47 | 48 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://nrennie.github.io/PrettyCols/ 2 | template: 3 | package: nrenniepkgdown 4 | bootstrap: 5 5 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 0 notes 4 | 5 | ## Reverse dependencies 6 | 7 | There are currently no reverse dependencies for this package. 8 | -------------------------------------------------------------------------------- /man/PrettyCols-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PrettyCols-package.R 3 | \docType{package} 4 | \name{PrettyCols-package} 5 | \alias{PrettyCols} 6 | \alias{PrettyCols-package} 7 | \title{PrettyCols: Pretty Colour Palettes} 8 | \description{ 9 | \if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}} 10 | 11 | Defines aesthetically pleasing colour palettes. 12 | } 13 | \seealso{ 14 | Useful links: 15 | \itemize{ 16 | \item \url{https://nrennie.rbind.io/PrettyCols/} 17 | \item \url{https://github.com/nrennie/PrettyCols} 18 | \item Report bugs at \url{https://github.com/nrennie/PrettyCols/issues} 19 | } 20 | 21 | } 22 | \author{ 23 | \strong{Maintainer}: Nicola Rennie \email{nrennie35@gmail.com} 24 | 25 | } 26 | \keyword{internal} 27 | -------------------------------------------------------------------------------- /man/PrettyColsPalettes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PrettyColsPalettes.R 3 | \docType{data} 4 | \name{PrettyColsPalettes} 5 | \alias{PrettyColsPalettes} 6 | \title{Complete list of palettes.} 7 | \format{ 8 | An object of class \code{list} of length 46. 9 | } 10 | \usage{ 11 | PrettyColsPalettes 12 | } 13 | \description{ 14 | Use names(PrettyColsPalettes) to return all palette names. 15 | } 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/colorblind_friendly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colorblind_friendly.R 3 | \name{colorblind_friendly} 4 | \alias{colorblind_friendly} 5 | \title{Returns a data frame of colorblind friendly colour palettes} 6 | \usage{ 7 | colorblind_friendly(palettes = PrettyColsPalettes) 8 | } 9 | \arguments{ 10 | \item{palettes}{List of palettes. Default PrettyColsPalettes.} 11 | } 12 | \value{ 13 | A data frame with two columns giving names and types of colourblind 14 | friendly palettes. 15 | } 16 | \description{ 17 | Returns a data frame of colorblind friendly colour palettes 18 | } 19 | \examples{ 20 | colorblind_friendly() 21 | } 22 | -------------------------------------------------------------------------------- /man/colourblind_friendly.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/colourblind_friendly.R 3 | \name{colourblind_friendly} 4 | \alias{colourblind_friendly} 5 | \title{Returns a data frame of colourblind friendly colour palettes} 6 | \usage{ 7 | colourblind_friendly(palettes = PrettyColsPalettes) 8 | } 9 | \arguments{ 10 | \item{palettes}{List of palettes. Default PrettyColsPalettes.} 11 | } 12 | \value{ 13 | A data frame with two columns giving names and types of colourblind 14 | friendly palettes. 15 | } 16 | \description{ 17 | Returns a data frame of colourblind friendly colour palettes 18 | } 19 | \examples{ 20 | colourblind_friendly() 21 | } 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-archived.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: archived 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | archived 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-defunct.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: defunct 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | defunct 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-deprecated.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: deprecated 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | deprecated 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-experimental.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: experimental 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | experimental 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-maturing.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: maturing 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | maturing 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-questioning.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: questioning 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | questioning 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-soft-deprecated.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: soft-deprecated 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | soft-deprecated 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/lifecycle-stable.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: stable 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | lifecycle 21 | 22 | 25 | 26 | stable 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /man/figures/lifecycle-superseded.svg: -------------------------------------------------------------------------------- 1 | 2 | lifecycle: superseded 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | lifecycle 18 | 19 | superseded 20 | 21 | 22 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrennie/PrettyCols/d754b34d2e08dc9b85494c59cc99421ce5ef0651/man/figures/logo.png -------------------------------------------------------------------------------- /man/prettycols.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/prettycols.R 3 | \name{prettycols} 4 | \alias{prettycols} 5 | \title{Generates the colour palettes} 6 | \usage{ 7 | prettycols(palette, n, type = "discrete", direction = 1) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{names(PrettyColsPalettes)} to view options.} 11 | 12 | \item{n}{Number of desired colors. If number of requested colors is beyond the scope of the palette, 13 | colors are automatically interpolated. If n is not provided, the length of the palette is used.} 14 | 15 | \item{type}{Either "continuous" or "discrete". Use continuous if you want to automatically 16 | interpolate between colors. Default "discrete"} 17 | 18 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, palette color order is reversed} 19 | } 20 | \value{ 21 | A character vector of hex colour codes. 22 | } 23 | \description{ 24 | Generates the colour palettes 25 | } 26 | \examples{ 27 | prettycols("Blues") 28 | } 29 | -------------------------------------------------------------------------------- /man/scale_color_pretty_c.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_color_pretty_c.R 3 | \name{scale_color_pretty_c} 4 | \alias{scale_color_pretty_c} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_color_pretty_c(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{names(PrettyColsPalettes)} to view options.} 11 | 12 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 13 | palette color order is reversed} 14 | 15 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 16 | 17 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{scale_color_gradientn}}} 18 | } 19 | \value{ 20 | A ggproto object defining a continuous colour scale for use with ggplot2. 21 | } 22 | \description{ 23 | Plotting with PrettyCols palettes for colour ggplot2 24 | } 25 | \examples{ 26 | library(ggplot2) 27 | ggplot(data = mtcars, aes(x = mpg, y = disp, color = wt)) + 28 | geom_point() + 29 | scale_color_pretty_c("Greens") 30 | } 31 | -------------------------------------------------------------------------------- /man/scale_color_pretty_d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_color_pretty_d.R 3 | \name{scale_color_pretty_d} 4 | \alias{scale_color_pretty_d} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_color_pretty_d(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{names(PrettyColsPalettes)} to view options.} 11 | 12 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 13 | palette color order is reversed} 14 | 15 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 16 | 17 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{discrete_scale}}} 18 | } 19 | \value{ 20 | A ggproto object defining a discrete colour scale for use with ggplot2. 21 | } 22 | \description{ 23 | Plotting with PrettyCols palettes for colour ggplot2 24 | } 25 | \examples{ 26 | library(ggplot2) 27 | ggplot(data = mtcars, aes(x = mpg, y = disp, color = factor(cyl))) + 28 | geom_point() + 29 | scale_color_pretty_d("Bright") 30 | } 31 | -------------------------------------------------------------------------------- /man/scale_color_pretty_div.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_color_pretty_div.R 3 | \name{scale_color_pretty_div} 4 | \alias{scale_color_pretty_div} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_color_pretty_div(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{view_all_palettes(type = "div")} to view 11 | options. Must be a diverging palette name.} 12 | 13 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 14 | palette color order is reversed} 15 | 16 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 17 | 18 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradient2}}} 19 | } 20 | \value{ 21 | A ggproto object defining a continuous colour scale for use with ggplot2. 22 | } 23 | \description{ 24 | Plotting with PrettyCols palettes for colour ggplot2 25 | } 26 | \examples{ 27 | library(ggplot2) 28 | ggplot(data = mtcars, aes(x = mpg, y = disp, colour = wt)) + 29 | geom_point() + 30 | scale_color_pretty_div("PurpleYellows", midpoint = mean(mtcars$wt)) 31 | } 32 | -------------------------------------------------------------------------------- /man/scale_colour_pretty_c.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_colour_pretty_c.R 3 | \name{scale_colour_pretty_c} 4 | \alias{scale_colour_pretty_c} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_colour_pretty_c(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{names(PrettyColsPalettes)} to view options.} 11 | 12 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 13 | palette color order is reversed} 14 | 15 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 16 | 17 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradientn}}} 18 | } 19 | \value{ 20 | A ggproto object defining a continuous colour scale for use with ggplot2. 21 | } 22 | \description{ 23 | Plotting with PrettyCols palettes for colour ggplot2 24 | } 25 | \examples{ 26 | library(ggplot2) 27 | ggplot(data = mtcars, aes(x = mpg, y = disp, colour = wt)) + 28 | geom_point() + 29 | scale_colour_pretty_c("Greens") 30 | } 31 | -------------------------------------------------------------------------------- /man/scale_colour_pretty_d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_colour_pretty_d.R 3 | \name{scale_colour_pretty_d} 4 | \alias{scale_colour_pretty_d} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_colour_pretty_d(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{names(PrettyColsPalettes)} to view options.} 11 | 12 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 13 | palette color order is reversed} 14 | 15 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 16 | 17 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{discrete_scale}}} 18 | } 19 | \value{ 20 | A ggproto object defining a discrete colour scale for use with ggplot2. 21 | } 22 | \description{ 23 | Plotting with PrettyCols palettes for colour ggplot2 24 | } 25 | \examples{ 26 | library(ggplot2) 27 | ggplot(data = mtcars, aes(x = mpg, y = disp, colour = factor(cyl))) + 28 | geom_point() + 29 | scale_colour_pretty_d("Bright") 30 | } 31 | -------------------------------------------------------------------------------- /man/scale_colour_pretty_div.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_colour_pretty_div.R 3 | \name{scale_colour_pretty_div} 4 | \alias{scale_colour_pretty_div} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_colour_pretty_div(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{view_all_palettes(type = "div")} to view 11 | options. Must be a diverging palette name.} 12 | 13 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 14 | palette color order is reversed} 15 | 16 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 17 | 18 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradient2}}} 19 | } 20 | \value{ 21 | A ggproto object defining a continuous colour scale for use with ggplot2. 22 | } 23 | \description{ 24 | Plotting with PrettyCols palettes for colour ggplot2 25 | } 26 | \examples{ 27 | library(ggplot2) 28 | ggplot(data = mtcars, aes(x = mpg, y = disp, colour = wt)) + 29 | geom_point() + 30 | scale_colour_pretty_div("PurpleYellows", midpoint = mean(mtcars$wt)) 31 | } 32 | -------------------------------------------------------------------------------- /man/scale_fill_pretty_c.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_fill_pretty_c.R 3 | \name{scale_fill_pretty_c} 4 | \alias{scale_fill_pretty_c} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_fill_pretty_c(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{names(PrettyColsPalettes)} to view options.} 11 | 12 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 13 | palette color order is reversed} 14 | 15 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 16 | 17 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{scale_fill_gradientn}}} 18 | } 19 | \value{ 20 | A ggproto object defining a continuous fill scale for use with ggplot2. 21 | } 22 | \description{ 23 | Plotting with PrettyCols palettes for colour ggplot2 24 | } 25 | \examples{ 26 | library(ggplot2) 27 | ggplot(data = mtcars, aes(x = mpg, y = disp, fill = wt)) + 28 | geom_point(pch = 21) + 29 | scale_fill_pretty_c("Greens") 30 | } 31 | -------------------------------------------------------------------------------- /man/scale_fill_pretty_d.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_fill_pretty_d.R 3 | \name{scale_fill_pretty_d} 4 | \alias{scale_fill_pretty_d} 5 | \title{Plotting with PrettyCols palettes for colour ggplot2} 6 | \usage{ 7 | scale_fill_pretty_d(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{names(PrettyColsPalettes)} to view options.} 11 | 12 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 13 | palette color order is reversed} 14 | 15 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 16 | 17 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{discrete_scale}}} 18 | } 19 | \value{ 20 | A ggproto object defining a discrete fill scale for use with ggplot2. 21 | } 22 | \description{ 23 | Plotting with PrettyCols palettes for colour ggplot2 24 | } 25 | \examples{ 26 | library(ggplot2) 27 | ggplot(data = mtcars, aes(x = mpg, y = disp, fill = factor(cyl))) + 28 | geom_point(pch = 21) + 29 | scale_fill_pretty_d("Bright") 30 | } 31 | -------------------------------------------------------------------------------- /man/scale_fill_pretty_div.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_fill_pretty_div.R 3 | \name{scale_fill_pretty_div} 4 | \alias{scale_fill_pretty_div} 5 | \title{Plotting with PrettyCols palettes for fill colour ggplot2} 6 | \usage{ 7 | scale_fill_pretty_div(palette, direction = 1, legend_title = NULL, ...) 8 | } 9 | \arguments{ 10 | \item{palette}{Name of Palette. Run \code{view_all_palettes(type = "div")} to view 11 | options. Must be a diverging palette name.} 12 | 13 | \item{direction}{Sets order of colors. Default palette is 1. If direction is -1, 14 | palette color order is reversed} 15 | 16 | \item{legend_title}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Deprecated in favour of \code{name}.} 17 | 18 | \item{...}{Other arguments passed on to \code{\link[ggplot2]{scale_colour_gradient2}}} 19 | } 20 | \value{ 21 | A ggproto object defining a continuous colour scale for use with ggplot2. 22 | } 23 | \description{ 24 | Plotting with PrettyCols palettes for fill colour ggplot2 25 | } 26 | \examples{ 27 | library(ggplot2) 28 | ggplot(data = mtcars, aes(x = mpg, y = disp, fill = wt)) + 29 | geom_point(pch = 21) + 30 | scale_fill_pretty_div("PurpleYellows", midpoint = mean(mtcars$wt)) 31 | } 32 | -------------------------------------------------------------------------------- /man/view_all_palettes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/view_all_palettes.R 3 | \name{view_all_palettes} 4 | \alias{view_all_palettes} 5 | \title{Prints all available colour palettes} 6 | \usage{ 7 | view_all_palettes(type = "all", colourblind_friendly = FALSE) 8 | } 9 | \arguments{ 10 | \item{type}{Type of colour palettes to view. Either all palettes, sequential palettes, 11 | diverging palettes, or qualitative palettes. Types must be at least one of c("all", "seq", "div", "qual"). 12 | Default "all".} 13 | 14 | \item{colourblind_friendly}{Boolean whether or not to return only colourblind friendly 15 | palettes. Default \code{FALSE}.} 16 | } 17 | \value{ 18 | A plot of all colour palettes available in the package. 19 | } 20 | \description{ 21 | Prints all available colour palettes 22 | } 23 | \examples{ 24 | view_all_palettes(type = "seq") 25 | view_all_palettes(type = c("seq", "div")) 26 | view_all_palettes(type = "div", colourblind_friendly = TRUE) 27 | } 28 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/tests.html 7 | # * https://testthat.r-lib.org/reference/test_package.html#special-files 8 | 9 | library(testthat) 10 | library(PrettyCols) 11 | 12 | test_check("PrettyCols") 13 | -------------------------------------------------------------------------------- /tests/testthat/test-display.R: -------------------------------------------------------------------------------- 1 | test_that("palette display", { 2 | expect_silent(view_all_palettes()) 3 | expect_silent(view_all_palettes(type = "seq")) 4 | expect_silent(view_all_palettes(type = "all", colourblind_friendly = TRUE)) 5 | expect_silent(view_all_palettes(type = "seq", colourblind_friendly = TRUE)) 6 | expect_error(view_all_palettes(type = "sequential")) 7 | 8 | expect_error(prettycols("new_name")) 9 | expect_error(prettycols("Relax", n = 6)) 10 | expect_error(prettycols("Relax", type = "cont")) 11 | expect_error(prettycols("Relax", direction = 0)) 12 | expect_silent(prettycols("Relax", direction = -1)) 13 | 14 | expect_equal(ncol(colourblind_friendly()), 2) 15 | expect_equal(ncol(colorblind_friendly()), 2) 16 | }) 17 | -------------------------------------------------------------------------------- /tests/testthat/test-palettes.R: -------------------------------------------------------------------------------- 1 | test_that("palettes are valid", { 2 | expect_equal(length(names(PrettyColsPalettes)), length(unique(names(PrettyColsPalettes)))) 3 | 4 | }) 5 | -------------------------------------------------------------------------------- /tests/testthat/test-scales.R: -------------------------------------------------------------------------------- 1 | test_that("scales functions works", { 2 | fill_scale <- scale_fill_pretty_c(palette = "Greens") 3 | expect_equal(fill_scale$is_discrete(), FALSE) 4 | expect_error(scale_fill_pretty_c(palette = "Green")) 5 | expect_error(scale_fill_pretty_c(palette = "Greens", direction = 0)) 6 | 7 | fill_scale <- scale_fill_pretty_div(palette = "PinkGreens") 8 | expect_equal(fill_scale$is_discrete(), FALSE) 9 | expect_error(scale_fill_pretty_div(palette = "Teals")) 10 | expect_error(scale_fill_pretty_div(palette = "PinkGreens", direction = 0)) 11 | 12 | fill_scale <- scale_fill_pretty_d(palette = "Relax") 13 | expect_equal(fill_scale$is_discrete(), TRUE) 14 | fill_scale <- scale_fill_pretty_d(palette = "Relax", direction = -1) 15 | expect_equal(fill_scale$is_discrete(), TRUE) 16 | expect_error(scale_fill_pretty_d(palette = "Relaxing")) 17 | expect_error(scale_fill_pretty_d(palette = "Relax", direction = 0)) 18 | 19 | colour_scale <- scale_colour_pretty_c(palette = "Greens") 20 | expect_equal(colour_scale$is_discrete(), FALSE) 21 | expect_error(scale_colour_pretty_c(palette = "Green")) 22 | expect_error(scale_colour_pretty_c(palette = "Greens", direction = 0)) 23 | 24 | colour_scale <- scale_color_pretty_c(palette = "Greens") 25 | expect_equal(colour_scale$is_discrete(), FALSE) 26 | expect_error(scale_color_pretty_c(palette = "Green")) 27 | expect_error(scale_color_pretty_c(palette = "Greens", direction = 0)) 28 | 29 | colour_scale <- scale_colour_pretty_div(palette = "PinkGreens") 30 | expect_equal(colour_scale$is_discrete(), FALSE) 31 | expect_error(scale_colour_pretty_div(palette = "Teals")) 32 | expect_error(scale_colour_pretty_div(palette = "PinkGreens", direction = 0)) 33 | 34 | color_scale <- scale_color_pretty_div(palette = "PinkGreens") 35 | expect_equal(color_scale$is_discrete(), FALSE) 36 | expect_error(scale_color_pretty_div(palette = "Teals")) 37 | expect_error(scale_color_pretty_div(palette = "PinkGreens", direction = 0)) 38 | 39 | colour_scale <- scale_colour_pretty_d(palette = "Relax") 40 | expect_equal(colour_scale$is_discrete(), TRUE) 41 | colour_scale <- scale_colour_pretty_d(palette = "Relax", direction = -1) 42 | expect_equal(colour_scale$is_discrete(), TRUE) 43 | expect_error(scale_colour_pretty_d(palette = "Relaxing")) 44 | expect_error(scale_colour_pretty_d(palette = "Relax", direction = 0)) 45 | 46 | colour_scale <- scale_color_pretty_d(palette = "Relax") 47 | expect_equal(colour_scale$is_discrete(), TRUE) 48 | colour_scale <- scale_color_pretty_d(palette = "Relax", direction = -1) 49 | expect_equal(colour_scale$is_discrete(), TRUE) 50 | expect_error(scale_color_pretty_d(palette = "Relaxing")) 51 | expect_error(scale_color_pretty_d(palette = "Relax", direction = 0)) 52 | }) 53 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/available-palettes.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Available Palettes" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Available Palettes} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | Install from CRAN using: 18 | ``` {r, eval = FALSE} 19 | install.packages("PrettyCols") 20 | ``` 21 | 22 | Or install the development version using: 23 | ``` {r, eval = FALSE} 24 | remotes::install_github("nrennie/PrettyCols") 25 | ``` 26 | 27 | Then load into R: 28 | ```{r} 29 | library(PrettyCols) 30 | ``` 31 | 32 | ## Sequential Palettes 33 | 34 | ```{r, out.width = "100%", fig.align="center"} 35 | view_all_palettes(type = "seq") 36 | ``` 37 | 38 | ## Diverging Palettes 39 | 40 | ```{r, out.width = "100%", fig.align="center"} 41 | view_all_palettes(type = "div") 42 | ``` 43 | 44 | ## Qualitative Palettes 45 | 46 | ```{r, out.width = "100%", fig.asp=2, fig.align="center"} 47 | view_all_palettes(type = "qual") 48 | ``` 49 | -------------------------------------------------------------------------------- /vignettes/colourblind-friendly-palettes.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Colourblind Friendly Palettes" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Colourblind Friendly Palettes} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | Install from CRAN using: 18 | ``` {r, eval = FALSE} 19 | install.packages("PrettyCols") 20 | ``` 21 | 22 | Or install the development version using: 23 | ``` {r, eval = FALSE} 24 | remotes::install_github("nrennie/PrettyCols") 25 | ``` 26 | 27 | Then load into R: 28 | ```{r} 29 | library(PrettyCols) 30 | ``` 31 | 32 | To return a data frame of which colour palettes are colourblind friendly, use: 33 | 34 | ```{r, eval = F} 35 | colourblind_friendly() 36 | ``` 37 | 38 | Note that the `colorblind_friendly()` is the same function. 39 | 40 | To view the palettes that are colourblind friendly, set the `colourblind_friendly` argument in `view_all_palettes()` to `TRUE`. To view all colourblind friendly palettes: 41 | 42 | ```{r, out.width = "60%", fig.align="center"} 43 | view_all_palettes(colourblind_friendly = TRUE) 44 | ``` 45 | 46 | This can be combined with a palette type. For example, to view all diverging colour palettes that are colourblind friendly: 47 | ```{r, out.width = "60%", fig.align="center"} 48 | view_all_palettes(type = "div", colourblind_friendly = TRUE) 49 | ``` 50 | 51 | Colourblind friendliness was checked using the {colorblindcheck} R package. 52 | 53 | -------------------------------------------------------------------------------- /vignettes/using-with-ggplot2.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Using with {ggplot2}" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Using with {ggplot2}} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | Install from CRAN using: 18 | ``` {r, eval = FALSE} 19 | install.packages("PrettyCols") 20 | ``` 21 | 22 | Or install the development version using: 23 | ``` {r, eval = FALSE} 24 | remotes::install_github("nrennie/PrettyCols") 25 | ``` 26 | 27 | Then load into R: 28 | ```{r} 29 | library(PrettyCols) 30 | ``` 31 | 32 | Set up a simple data frame to use for an example plot: 33 | ```{r} 34 | library(ggplot2) 35 | df <- data.frame( 36 | type = c("A", "B", "C"), 37 | value = c(1, 2, 3) 38 | ) 39 | ``` 40 | 41 | To change the fill or colour for discrete variables: 42 | ```{r, fig.show="hold", out.width = "47%"} 43 | ggplot( 44 | data = df, 45 | mapping = aes(x = type, y = value, fill = type) 46 | ) + 47 | geom_col() + 48 | scale_fill_pretty_d(palette = "Blues") 49 | 50 | ggplot( 51 | data = df, 52 | mapping = aes(x = type, y = value, colour = type) 53 | ) + 54 | geom_col(linewidth = 2, fill = "white") + 55 | scale_colour_pretty_d(palette = "Blues") 56 | ``` 57 | 58 | To change the fill or colour for continuous variables: 59 | ```{r, fig.show="hold", out.width = "47%"} 60 | ggplot( 61 | data = df, 62 | mapping = aes(x = type, y = value, fill = value) 63 | ) + 64 | geom_col() + 65 | scale_fill_pretty_c(palette = "Purples") 66 | 67 | ggplot( 68 | data = df, 69 | mapping = aes(x = type, y = value, colour = value) 70 | ) + 71 | geom_col(linewidth = 2, fill = "white") + 72 | scale_colour_pretty_c(palette = "Purples", direction = -1) 73 | ``` 74 | 75 | To change the fill or colour for continuous (diverging) variables (using diverging palettes only): 76 | ```{r, fig.show="hold", out.width = "47%"} 77 | ggplot( 78 | data = df, 79 | mapping = aes(x = type, y = value, fill = value) 80 | ) + 81 | geom_col() + 82 | scale_fill_pretty_div(palette = "PurpleYellows", midpoint = 2) 83 | 84 | ggplot( 85 | data = df, 86 | mapping = aes(x = type, y = value, colour = value) 87 | ) + 88 | geom_col(linewidth = 2, fill = "white") + 89 | scale_colour_pretty_div(palette = "PurpleYellows", midpoint = 2) 90 | ``` 91 | 92 | To change the legend title: 93 | ```{r, fig.show="hold", out.width = "47%", fig.align='center'} 94 | ggplot( 95 | data = df, 96 | mapping = aes(x = type, y = value, fill = value) 97 | ) + 98 | geom_col() + 99 | scale_fill_pretty_c(palette = "Purples", name = "My New Title") + 100 | theme(legend.title = element_text(colour = "blue")) 101 | ``` 102 | 103 | 104 | -------------------------------------------------------------------------------- /vignettes/viewing-palettes.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Viewing Palettes" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{Viewing Palettes} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | ```{r, include = FALSE} 11 | knitr::opts_chunk$set( 12 | collapse = TRUE, 13 | comment = "#>" 14 | ) 15 | ``` 16 | 17 | Install from CRAN using: 18 | ``` {r, eval = FALSE} 19 | install.packages("PrettyCols") 20 | ``` 21 | 22 | Or install the development version using: 23 | ``` {r, eval = FALSE} 24 | remotes::install_github("nrennie/PrettyCols") 25 | ``` 26 | 27 | Then load into R: 28 | ```{r} 29 | library(PrettyCols) 30 | ``` 31 | 32 | To see the names of all available palettes, run: 33 | ```{r} 34 | names(PrettyColsPalettes) 35 | ``` 36 | 37 | To see the colours in a specific palette, use the `prettycols()` function: 38 | ```{r, out.width = "100%", fig.align="center"} 39 | prettycols("Tangerines") 40 | ``` 41 | 42 | By default a discrete palette showing all colours is displayed. Setting `type = "continuous"` displays a continuous palette, changing `n` changes the number of colours, and switching `direction = -1` reverses the order of colours. For example: 43 | ```{r, out.width = "100%", fig.align="center"} 44 | prettycols("Tangerines", n = 50, type = "continuous", direction = -1) 45 | ``` 46 | 47 | To see all available palettes, run: 48 | ```{r, out.width = "100%", fig.align="center"} 49 | view_all_palettes() 50 | ``` 51 | 52 | or, 53 | 54 | ```{r, eval = FALSE} 55 | view_all_palettes(type == "all") 56 | ``` 57 | 58 | Palettes are categorised into three types: 59 | 60 | * Sequential (`seq`), 61 | * Diverging (`div`), 62 | * Qualitative (`qual`). 63 | 64 | Palettes can be viewed by type. For example, to see all sequential colour palettes, run: 65 | 66 | ```{r, out.width = "100%", fig.align="center"} 67 | view_all_palettes(type = "seq") 68 | ``` 69 | 70 | --------------------------------------------------------------------------------