├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ ├── R-CMD-check.yaml │ ├── pkgdown.yaml │ └── test-coverage.yaml ├── .gitignore ├── CRAN-SUBMISSION ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── api.R ├── color.R ├── palette.R ├── scale_colorhex.R ├── scale_palettehex.R └── utils.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── cran-comments.md ├── inst └── WORDLIST ├── man ├── figures │ ├── README-example-1.png │ ├── README-latest-1.png │ ├── README-pop-cols-1.png │ ├── README-popular-1.png │ ├── README-popular-palettes-1.png │ ├── README-unnamed-chunk-2-1.png │ ├── README-unnamed-chunk-2-2.png │ ├── README-unnamed-chunk-2-3.png │ ├── README-unnamed-chunk-2-4.png │ ├── README-unnamed-chunk-3-1.png │ ├── README-unnamed-chunk-3-2.png │ ├── README-unnamed-chunk-3-3.png │ ├── README-unnamed-chunk-3-4.png │ └── README-unnamed-chunk-3-5.png ├── get_color.Rd ├── get_latest_palettes.Rd ├── get_palette.Rd ├── get_popular_colors.Rd ├── get_popular_palettes.Rd ├── get_random_color.Rd ├── is_hex.Rd ├── scale-colorhex.Rd └── scale-palettehex.Rd └── tests └── spelling.R /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^\.github$ 6 | ^cran-comments\.md$ 7 | ^CRAN-RELEASE$ 8 | ^CRAN-SUBMISSION$ 9 | ^colorhex\.Rproj$ 10 | ^_pkgdown\.yml$ 11 | ^docs$ 12 | ^pkgdown$ 13 | -------------------------------------------------------------------------------- /.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 | schedule: 9 | - cron: '00 1 * * 1' 10 | 11 | name: R-CMD-check 12 | 13 | jobs: 14 | R-CMD-check: 15 | runs-on: ubuntu-latest 16 | env: 17 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 18 | R_KEEP_PKG_SOURCE: yes 19 | steps: 20 | - uses: actions/checkout@v3 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::rcmdcheck 29 | needs: check 30 | 31 | - uses: r-lib/actions/check-r-package@v2 32 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.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 | release: 7 | types: [published] 8 | workflow_dispatch: 9 | 10 | name: pkgdown 11 | 12 | jobs: 13 | pkgdown: 14 | runs-on: ubuntu-latest 15 | # Only restrict concurrency for non-PR jobs 16 | concurrency: 17 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 18 | env: 19 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 20 | permissions: 21 | contents: write 22 | steps: 23 | - uses: actions/checkout@v3 24 | 25 | - uses: r-lib/actions/setup-pandoc@v2 26 | 27 | - uses: r-lib/actions/setup-r@v2 28 | with: 29 | use-public-rspm: true 30 | 31 | - uses: r-lib/actions/setup-r-dependencies@v2 32 | with: 33 | extra-packages: any::pkgdown, local::. 34 | needs: website 35 | 36 | - name: Build site 37 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 38 | shell: Rscript {0} 39 | 40 | - name: Deploy to GitHub pages 🚀 41 | if: github.event_name != 'pull_request' 42 | uses: JamesIves/github-pages-deploy-action@v4.4.1 43 | with: 44 | clean: false 45 | branch: gh-pages 46 | folder: docs 47 | -------------------------------------------------------------------------------- /.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@v3 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: | 31 | covr::codecov( 32 | quiet = FALSE, 33 | clean = FALSE, 34 | install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package") 35 | ) 36 | shell: Rscript {0} 37 | 38 | - name: Show testthat output 39 | if: always() 40 | run: | 41 | ## -------------------------------------------------------------------- 42 | find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true 43 | shell: bash 44 | 45 | - name: Upload test results 46 | if: failure() 47 | uses: actions/upload-artifact@v3 48 | with: 49 | name: coverage-test-failures 50 | path: ${{ runner.temp }}/package 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | .Ruserdata 5 | *.Rproj 6 | **.DS_Store 7 | docs 8 | -------------------------------------------------------------------------------- /CRAN-SUBMISSION: -------------------------------------------------------------------------------- 1 | Version: 0.1.4 2 | Date: 2023-09-07 19:55:56 UTC 3 | SHA: 4 | d0cf9e1372771e89b74a37c0ea69e75934b91d26 5 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: colorhex 2 | Type: Package 3 | Title: Colors and Palettes from Color-Hex 4 | Version: 0.1.4 5 | Authors@R: c( 6 | person("Athanasia Mo", "Mowinckel", 7 | email = "a.m.mowinckel@psykologi.uio.no", 8 | role = c("aut", "cre"), 9 | comment = c(ORCID = "0000-0002-5756-0223")), 10 | person("Julia", "Romanowska", 11 | email = "Julia.Romanowska@uib.no", 12 | role = "ctb", 13 | comment = c(ORCID = "0000-0001-6733-1953")) 14 | ) 15 | Description: The website is a great resource of hex colour 16 | codes and palettes. This package allows you to retrieve palettes 17 | and colour information from the website directly from R. There are 18 | also custom scale-functions for 'ggplot2'. 19 | License: MIT + file LICENSE 20 | Encoding: UTF-8 21 | Imports: 22 | cli, 23 | curl, 24 | ggplot2, 25 | graphics, 26 | grDevices, 27 | httr2, 28 | rvest 29 | RoxygenNote: 7.2.3 30 | URL: https://drmowinckels.github.io/colorhex/, https://github.com/drmowinckels/colorhex 31 | BugReports: https://github.com/drmowinckels/colorhex/issues 32 | Suggests: 33 | spelling, 34 | scales 35 | Language: en-US 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2021 2 | COPYRIGHT HOLDER: Athanasia M. Mowinckel 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2021 Athanasia M. Mowinckel 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(format,colorhex) 4 | S3method(plot,colorhex) 5 | S3method(plot,palettehex) 6 | S3method(print,colorhex) 7 | export(get_color) 8 | export(get_latest_palettes) 9 | export(get_palette) 10 | export(get_popular_colors) 11 | export(get_popular_palettes) 12 | export(get_random_color) 13 | export(is_hex) 14 | export(scale_color_colorhex_c) 15 | export(scale_color_colorhex_d) 16 | export(scale_color_palettehex_c) 17 | export(scale_color_palettehex_d) 18 | export(scale_colour_colorhex_c) 19 | export(scale_colour_colorhex_d) 20 | export(scale_colour_palettehex_c) 21 | export(scale_colour_palettehex_d) 22 | export(scale_fill_colorhex_c) 23 | export(scale_fill_colorhex_d) 24 | export(scale_fill_palettehex_c) 25 | export(scale_fill_palettehex_d) 26 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | 2 | # colorhex 0.1.4 3 | - fixes failure of build if server is unresponsive 4 | 5 | # colorhex 0.1.1 6 | - cran submission 7 | 8 | # colorhex 0.1.01 9 | 10 | * With ggplot2 scales. 11 | 12 | # colorhex 0.1.0 13 | 14 | * Added a `NEWS.md` file to track changes to the package. 15 | * First release 16 | -------------------------------------------------------------------------------- /R/api.R: -------------------------------------------------------------------------------- 1 | query_colorhex <- function(){ 2 | if(!curl::has_internet()){ 3 | cli::cli_alert_warning("Not connected to internet.") 4 | return(invisible(NULL)) 5 | } 6 | req <- httr2::request(colour_url()) 7 | req <- httr2::req_retry(req, 8 | backoff = ~ 10, 9 | is_transient = ~ httr2::resp_status(.x) > 400) 10 | req <- httr2::req_error(req, 11 | is_error = function(resp) FALSE, 12 | body = error_body) 13 | req 14 | } 15 | 16 | colour_url <- function(full = TRUE){ 17 | url <- "www.color-hex.com" 18 | if(!full) 19 | return(url) 20 | paste0("https://", url, "/") 21 | } 22 | 23 | error_body <- function(resp) { 24 | httr2::resp_body_json(resp)$error 25 | } 26 | 27 | status_ok <- function(req){ 28 | test <- httr2::req_perform(req) 29 | if(httr2::resp_status(test) > 400 ){ 30 | cli::cli_alert_warning("Cannot connect to service.") 31 | cli::cli_inform(httr2::resp_status_desc(test)) 32 | return(FALSE) 33 | } 34 | TRUE 35 | } 36 | -------------------------------------------------------------------------------- /R/color.R: -------------------------------------------------------------------------------- 1 | #' Get popular colour 2 | #' 3 | #' www.color-hex.com has a list of colours 4 | #' that have been liked by the most users. 5 | #' This function will retrieve all of these. 6 | #' 7 | #' @return character vector of hex colours 8 | #' @export 9 | #' 10 | #' @examples 11 | #' if(curl::has_internet()){ 12 | #' get_popular_colors() 13 | #' } 14 | get_popular_colors <- function(){ 15 | req <- httr2::request(colour_url()) 16 | if(is.null(req)) 17 | return(invisible(NULL)) 18 | req <- httr2::req_url_path_append( 19 | req, 20 | "popular-colors.php") 21 | if(!status_ok(req)) 22 | return(invisible(NULL)) 23 | 24 | resp <- httr2::req_perform(req) 25 | resp <- httr2::resp_body_html(resp) 26 | cols <- rvest::html_nodes( 27 | resp, 28 | xpath = '//*[@class="colordva"]') 29 | cols <- as.character(cols) 30 | get_bkg_color(cols) 31 | } 32 | 33 | #' Generate random HEX colour 34 | #' 35 | #' @return character hex value 36 | #' @export 37 | #' 38 | #' @examples 39 | #' get_random_color() 40 | get_random_color <- function(){ 41 | grDevices::rgb(randcol(), 42 | randcol(), 43 | randcol(), 44 | maxColorValue = 255) 45 | } 46 | 47 | #' Get color information 48 | #' 49 | #' Get color information from www.color-hex.com 50 | #' of a hex-color. 51 | #' 52 | #' @param hex character string that is a hexidecimal color 53 | #' 54 | #' @return list of class 'colorhex' 55 | #' @export 56 | #' 57 | #' @examples 58 | #' if(curl::has_internet()){ 59 | #' get_color("#470f0f") 60 | #' } 61 | get_color <- function(hex){ 62 | hex <- fix_hex(hex) 63 | req <- query_colorhex() 64 | if(is.null(req)) 65 | return(invisible(NULL)) 66 | 67 | req <- httr2::req_url_path_append( 68 | req, 69 | "color", 70 | gsub("^#", "", hex)) 71 | 72 | if(!status_ok(req)) 73 | return(invisible(NULL)) 74 | 75 | resp <- httr2::req_perform(req) 76 | resp <- httr2::resp_body_html(resp) 77 | tables <- rvest::html_nodes(resp, "table") 78 | tables <- lapply(tables, rvest::html_table, fill = TRUE) 79 | prim <- as.data.frame(t(tables[[1]])) 80 | names(prim) <- as.character(unlist(prim[1,])) 81 | row.names(prim) <- NULL 82 | prim <- prim[-1,] 83 | 84 | rows <- rvest::html_nodes(resp, 85 | xpath = '//*[@class="colordvconline"]') 86 | rows <- rvest::html_text(rows) 87 | rows <- gsub(" \n", "", rows) 88 | rows <- sapply(rows, fix_hex) 89 | 90 | ret <- list( 91 | hex = hex, 92 | space = prim, 93 | base = tables[[2]], 94 | triadic = NA_character_, 95 | analogous = NA_character_, 96 | complementary = NA_character_, 97 | shades = rows[1:11], 98 | tints = rows[12:22], 99 | related = rows[22:length(rows)], 100 | palettes = get_pals(resp, "palettecontainerlist narrow") 101 | ) 102 | 103 | if(length(tables) > 2){ 104 | ex <- lapply(3:5, function(x){ 105 | j <- unique(unlist(tables[[x]])) 106 | sapply(j[j!=""], fix_hex) 107 | }) 108 | ret$triadic = ex[[1]] 109 | ret$analogous = ex[[2]] 110 | ret$complementary = ex[[3]] 111 | } 112 | 113 | colorhex(ret) 114 | } 115 | 116 | colorhex <- function(x){ 117 | stopifnot(names(x) %in% c("hex", 118 | "space", "base", 119 | "complementary", "analogous", 120 | "triadic", "shades", "tints", 121 | "related", "palettes")) 122 | 123 | structure( 124 | x, 125 | class = "colorhex" 126 | ) 127 | } 128 | 129 | #' @export 130 | format.colorhex <- function(x, ...){ 131 | c( 132 | sprintf("# Color-hex: %s", x$hex), 133 | sprintf("RGB: %s", paste0(x$space[, "RGB"], collapse=", ")), 134 | sprintf("HSL: %s", paste0(x$space[, "HSL"], collapse=", ")), 135 | sprintf("CMYK: %s", paste0(x$space[, "CMYK"], collapse=", ")), 136 | sprintf("triadic: %s", paste0(x$triadic, collapse = ", ")), 137 | sprintf("complementary: %s", x$complementary), 138 | sprintf("used in %s palettes", nrow(x$palettes)) 139 | ) 140 | } 141 | 142 | #' @export 143 | print.colorhex <- function(x, ...){ 144 | cat(format(x), sep="\n") 145 | invisible(x) 146 | } 147 | 148 | #' @export 149 | plot.colorhex <- function(x, 150 | type = c("complementary", "triadic", 151 | "analogous", "shades", "tints", 152 | "related"), 153 | labels = TRUE, ...){ 154 | 155 | type <- match.arg(type, 156 | c("complementary", "triadic", 157 | "analogous", "shades", "tints", "related"), 158 | several.ok = TRUE) 159 | 160 | x <- lapply(type, function(y) if(y != "hex") c(x$hex, x[[y]]) else x[[y]]) 161 | names(x) <- type 162 | 163 | ncols <- length(type) 164 | nrows <- max(sapply(x, length))+.5 165 | 166 | oldpar <- graphics::par(no.readonly = TRUE) 167 | on.exit(graphics::par(oldpar)) 168 | graphics::par(mar = c(0, 0, 0, 0)) 169 | graphics::plot.new() 170 | graphics::plot(c(-.1, nrows+.3), c(.5, ncols+.5), 171 | type = "n", xlab = "", ylab = "", 172 | axes = FALSE 173 | ) 174 | 175 | for(i in 1:length(type)){ 176 | tmp <- x[[type[i]]] 177 | graphics::text(1, i, type[i], cex = 1, pos = 2) 178 | for(j in 1:length(tmp)){ 179 | graphics::rect(j, i-.4, j+1, i+.4, col=tmp[j], border = NA) 180 | if(labels){ 181 | graphics::rect(j+.2, i-.1, j+.8, i+.1, col="white", border = NA) 182 | graphics::text(j+.5, i, tmp[j], cex = .7) 183 | } 184 | } 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /R/palette.R: -------------------------------------------------------------------------------- 1 | #' Get latest palettes 2 | #' 3 | #' Retrieve the most recently made palettes 4 | #' from www.color-hex.com 5 | #' 6 | #' @return data.frame with name, id and colours 7 | #' @export 8 | #' 9 | #' @examples 10 | #' if(curl::has_internet()){ 11 | #' get_latest_palettes() 12 | #' } 13 | get_latest_palettes <- function(){ 14 | req <- query_colorhex() 15 | if(is.null(req)) 16 | return(invisible(NULL)) 17 | req <- httr2::req_url_path_append( 18 | req, "color-palettes") 19 | if(!status_ok(req)) 20 | return(invisible(NULL)) 21 | resp <- httr2::req_perform(req) 22 | resp <- httr2::resp_body_html(resp) 23 | get_pals(resp) 24 | } 25 | 26 | #' Get most popular palettes 27 | #' 28 | #' Retrieve the palettes most users have 29 | #' checked as favorites from www.color-hex.com 30 | #' 31 | #' @return data.frame with name, id and colours 32 | #' @export 33 | #' 34 | #' @examples 35 | #' if(curl::has_internet()){ 36 | #' get_popular_palettes() 37 | #' } 38 | get_popular_palettes <- function(){ 39 | req <- query_colorhex() 40 | if(is.null(req)) 41 | return(invisible(NULL)) 42 | req <- httr2::req_url_path_append( 43 | req, 44 | "color-palettes", 45 | "popular.php") 46 | if(!status_ok(req)) 47 | return(invisible(NULL)) 48 | resp <- httr2::req_perform(req) 49 | resp <- httr2::resp_body_html(resp) 50 | get_pals(resp) 51 | } 52 | 53 | #' Get palettes from id 54 | #' 55 | #' Get palette information from www.color-hex.com 56 | #' based on the palette id (can be found in the url) 57 | #' 58 | #' @param id numeric id of a palette 59 | #' 60 | #' @return data.frame with palette information 61 | #' @export 62 | #' 63 | #' @examples 64 | #' if(curl::has_internet()){ 65 | #' get_palette(103107) 66 | #' 67 | #' # Lookup multiple palettes 68 | #' id <- c(103161, 103107) 69 | #' get_palette(id) 70 | #' } 71 | get_palette <- function(id){ 72 | x <- lapply(id, get_pal) 73 | do.call(rbind, x) 74 | } 75 | 76 | #' @export 77 | plot.palettehex <- function(x, ...){ 78 | colr <- apply(x, 1, unnest_pal) 79 | 80 | nrows <- max(sapply(colr, nrow))+1 81 | ncols <- length(colr) 82 | 83 | oldpar <- graphics::par(no.readonly = TRUE) 84 | on.exit(graphics::par(oldpar)) 85 | graphics::par(mar = c(0, 0, 0, 0)) 86 | graphics::plot.new() 87 | graphics::plot(c(-2, nrows-.2), c(.6, ncols+.3), 88 | type = "n", xlab = "", ylab = "", 89 | axes = FALSE 90 | ) 91 | for(i in 1:length(colr)){ 92 | tmp <- colr[[i]] 93 | graphics::text(1, i+.1, 94 | sprintf("%s (%s)", tolower(tmp$name[[1]]), tmp$id[[1]]), 95 | cex = .7, pos = 2) 96 | for(j in 1:nrow(tmp)){ 97 | graphics::rect(j, i-.3, j+1, i+.3, col=tmp$hex[[j]], border = NA) 98 | } 99 | } 100 | 101 | } 102 | 103 | # helpers ---- 104 | 105 | get_pal <- function(id){ 106 | req <- query_colorhex() 107 | if(is.null(req)) 108 | return(invisible(NULL)) 109 | req <- httr2::req_url_path_append( 110 | req, 111 | "color-palette", 112 | id) 113 | if(!status_ok(req)) 114 | return(invisible(NULL)) 115 | resp <- httr2::req_perform(req) 116 | resp <- httr2::resp_body_html(resp) 117 | 118 | tables <- rvest::html_nodes(resp, "table") 119 | tables <- rvest::html_table(tables[1], fill = TRUE)[[1]] 120 | 121 | palettehex( 122 | gsub(" Color Palette", "", 123 | rvest::html_text(rvest::html_nodes(resp, "h1"))), 124 | id, 125 | list(tables[,2]) 126 | ) 127 | } 128 | 129 | get_pals <- function(resp, class = "palettecontainerlist"){ 130 | path <- paste0('//*[@class="',class, '"]') 131 | pal <- rvest::html_nodes(resp, xpath = path) 132 | pal2 <- as.character(pal) 133 | pal2 <- strsplit(pal2, "\n") 134 | 135 | title <- sapply(pal2, function(x) strip_html(x[length(x)-1])) 136 | number <- unlist(sapply(pal2, function(x) get_nums(x[2])[[1]])) 137 | 138 | palettehex( 139 | title, 140 | number, 141 | lapply(pal2, get_pal_color) 142 | ) 143 | } 144 | 145 | palettehex <- function(name, id, palette){ 146 | ret <- data.frame( 147 | name = name, 148 | id = id, 149 | stringsAsFactors = FALSE 150 | ) 151 | ret$palette <- palette 152 | 153 | structure( 154 | ret, 155 | class = c("palettehex", "data.frame")) 156 | } 157 | 158 | unnest_pal <- function(x){ 159 | k <- cbind(x[1], x[2], unname(unlist(x[3]))) 160 | k <- as.data.frame(k, stringsAsFactors = FALSE) 161 | names(k) <- c("name", "id", "hex") 162 | row.names(k) <- NULL 163 | k$num <- 1:nrow(k) 164 | k 165 | } 166 | 167 | -------------------------------------------------------------------------------- /R/scale_colorhex.R: -------------------------------------------------------------------------------- 1 | #' Colour scales for ggplot2 2 | #' 3 | #' Colour and fill scales for ggplot2 4 | #' plots, using object of class \code{colorhex} 5 | #' as basis for colour choices. 6 | #' 7 | #' The \code{colorhex} class is a list where there 8 | #' is a variety of extra information on the hex 9 | #' colour selected. This information can be used 10 | #' to create colour scales to be used in ggplot2. 11 | #' 12 | #' @param x object of class \code{colorhex} 13 | #' @param type character. Type of colours to use. 14 | #' One of c("complementary", "triadic" (default), "shades", "tints", "related") 15 | #' @param reverse logical. If scale should b reversed (default: FALSE) 16 | #' @param ... arguments to be passed to \code{\link[ggplot2]{discrete_scale}} 17 | #' 18 | #' @name scale-colorhex 19 | #' @return a ggplot2-proto 20 | #' @examples 21 | #' if(curl::has_internet()){ 22 | #' library(ggplot2) 23 | #' 24 | #' x <- get_color("#008080") 25 | #' 26 | #' ggplot(mtcars, aes(mpg)) + 27 | #' geom_density(aes(fill = disp, group = disp)) + 28 | #' scale_fill_colorhex_c(x) 29 | #' 30 | #' ggplot(mtcars, aes(mpg)) + 31 | #' geom_density(aes(fill = disp, group = disp)) + 32 | #' scale_fill_colorhex_c(x, "tints") 33 | #' 34 | #' ggplot(mtcars, aes(mpg)) + 35 | #' geom_density(aes(fill = disp, group = disp)) + 36 | #' scale_fill_colorhex_c(x, "shades") 37 | #' 38 | #' ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 39 | #' geom_point() + 40 | #' scale_color_colorhex_d(x, "triadic") 41 | #' 42 | #' ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 43 | #' geom_point() + 44 | #' scale_color_colorhex_d(x, "shades") 45 | #' } 46 | NULL 47 | #> NULL 48 | 49 | #' @describeIn scale-colorhex Discrete colour scale 50 | #' @export 51 | scale_colour_colorhex_d <- function(x, 52 | type = "triadic", 53 | reverse = FALSE, 54 | ...) { 55 | ggplot2::discrete_scale( 56 | "colour", "colorhex_d", 57 | colorhex_pal(x, type, reverse), 58 | ... 59 | ) 60 | } 61 | 62 | #' @describeIn scale-colorhex Discrete colour scale 63 | #' @export 64 | scale_color_colorhex_d <- scale_colour_colorhex_d 65 | 66 | #' @describeIn scale-colorhex Discrete fill scale 67 | #' @export 68 | scale_fill_colorhex_d <- function(x, 69 | type = "triadic", 70 | reverse = FALSE, 71 | ...) { 72 | ggplot2::discrete_scale( 73 | "fill", "colorhex_d", 74 | colorhex_pal(x, type, reverse), 75 | ... 76 | ) 77 | } 78 | 79 | #' @describeIn scale-colorhex Continuous colour scale 80 | #' @export 81 | scale_colour_colorhex_c <- function(x, 82 | type = "complementary", 83 | reverse = FALSE, 84 | ...) { 85 | type <- match.arg(type, c("complementary", "triadic", 86 | "shades", "tints", "related")) 87 | n <- length(c(x$hex, x[[type]])) 88 | cols <- colorhex_pal(x, type, reverse)(n) 89 | 90 | ggplot2::scale_colour_gradientn(colours = cols, 91 | ...) 92 | } 93 | 94 | #' @describeIn scale-colorhex Continuous colour scale 95 | #' @export 96 | scale_color_colorhex_c <- scale_colour_colorhex_c 97 | 98 | #' @describeIn scale-colorhex Continuous fill scale 99 | #' @export 100 | scale_fill_colorhex_c <- function(x, 101 | type = "complementary", 102 | reverse = FALSE, 103 | ...) { 104 | type <- match.arg(type, c("complementary", "triadic", 105 | "shades", "tints", "related")) 106 | n <- length(c(x$hex, x[[type]])) 107 | cols <- colorhex_pal(x, type, reverse)(n) 108 | 109 | ggplot2::scale_fill_gradientn(colours = cols, 110 | ...) 111 | } 112 | 113 | # pal-maker ---- 114 | colorhex_pal <- function(x, 115 | type = "complementary", 116 | reverse = FALSE) { 117 | 118 | type <- match.arg(type, c("complementary", "triadic", 119 | "shades", "tints", "related")) 120 | 121 | function(n) { 122 | cols <- c(x$hex, x[[type]]) 123 | 124 | if (n > length(cols)) 125 | warning(sprintf("colorhex only has %s colors.", length(cols))) 126 | 127 | cols <- cols[1:n] 128 | cols <- cols[!is.na(cols)] 129 | 130 | if (!reverse) cols else rev(cols) 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /R/scale_palettehex.R: -------------------------------------------------------------------------------- 1 | #' Colour scales for ggplot2 2 | #' 3 | #' Colour and fill scales for ggplot2 4 | #' plots, using object of class \code{palettehex}. 5 | #' 6 | #' The \code{palettehex} class is a data.frame of 7 | #' many palettes. This function takes such a data.frame 8 | #' and a choice of palette by name, id or numeric index 9 | #' can be made for the scale. 10 | #' 11 | #' @param x object of class \code{palettehex} 12 | #' @param which selection of which palette of a set to choose. Either by name, 13 | #' id or numeric index. 14 | #' @param reverse logical. If scale should b reversed (default: FALSE) 15 | #' @param ... arguments to be passed to \code{\link[ggplot2]{discrete_scale}} 16 | #' 17 | #' @name scale-palettehex 18 | #' @return ggplot2-proto 19 | #' @examples 20 | #' if(curl::has_internet()){ 21 | #' library(ggplot2) 22 | #' 23 | #' x <- get_popular_palettes() 24 | #' 25 | #' ggplot(mtcars, aes(mpg)) + 26 | #' geom_density(aes(fill = disp, group = disp)) + 27 | #' scale_fill_palettehex_c(x) 28 | #' 29 | #' ggplot(mtcars, aes(mpg)) + 30 | #' geom_density(aes(fill = disp, group = disp)) + 31 | #' scale_fill_palettehex_c(x, 3) 32 | #' 33 | #' ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 34 | #' geom_point() + 35 | #' scale_color_palettehex_d(x) 36 | #' 37 | #' ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 38 | #' geom_point() + 39 | #' scale_color_palettehex_d(x, 1872) 40 | #' } 41 | NULL 42 | #> NULL 43 | 44 | #' @describeIn scale-palettehex Discrete colour scale 45 | #' @export 46 | scale_colour_palettehex_d <- function(x, 47 | which = 1, 48 | reverse = FALSE, 49 | ...) { 50 | ggplot2::discrete_scale( 51 | "colour", "palettehex_d", 52 | palettehex_pal(x, which, reverse), 53 | ... 54 | ) 55 | } 56 | 57 | #' @describeIn scale-palettehex Discrete colour scale 58 | #' @export 59 | scale_color_palettehex_d <- scale_colour_palettehex_d 60 | 61 | #' @describeIn scale-palettehex Discrete fill scale 62 | #' @export 63 | scale_fill_palettehex_d <- function(x, 64 | which = 1, 65 | reverse = FALSE, 66 | ...) { 67 | ggplot2::discrete_scale( 68 | "fill", "palettehex_d", 69 | palettehex_pal(x, which, reverse), 70 | ... 71 | ) 72 | } 73 | 74 | #' @describeIn scale-palettehex Continuous colour scale 75 | #' @export 76 | scale_colour_palettehex_c <- function(x, 77 | which = 1, 78 | reverse = FALSE, 79 | ...) { 80 | n <- length(find_pal(x, which)) 81 | cols <- palettehex_pal(x, which, reverse)(n) 82 | 83 | ggplot2::scale_colour_gradientn(colours = cols, 84 | ...) 85 | } 86 | 87 | #' @describeIn scale-palettehex Continuous colour scale 88 | #' @export 89 | scale_color_palettehex_c <- scale_colour_palettehex_c 90 | 91 | #' @describeIn scale-palettehex Continuous fill scale 92 | #' @export 93 | scale_fill_palettehex_c <- function(x, 94 | which = 1, 95 | reverse = FALSE, 96 | ...) { 97 | n <- length(find_pal(x, which)) 98 | cols <- palettehex_pal(x, which, reverse)(n) 99 | 100 | ggplot2::scale_fill_gradientn(colours = cols, 101 | ...) 102 | } 103 | 104 | # pal-maker ---- 105 | palettehex_pal <- function(x, 106 | which = 1, 107 | reverse = FALSE) { 108 | cols <- find_pal(x, which) 109 | 110 | function(n) { 111 | if (n > length(cols)) 112 | warning(sprintf("palettehex only has %s colors.", length(cols))) 113 | 114 | cols <- cols[1:n] 115 | cols <- cols[!is.na(cols)] 116 | 117 | if (!reverse) cols else rev(cols) 118 | } 119 | } 120 | 121 | 122 | find_pal <- function(x, which){ 123 | 124 | idx <- match(which, x$name) 125 | if(!is.na(idx)) return(x$palette[[idx]]) 126 | 127 | idx <- match(which, x$id) 128 | if(!is.na(idx)) return(x$palette[[idx]]) 129 | 130 | x$palette[[which]] 131 | 132 | } 133 | -------------------------------------------------------------------------------- /R/utils.R: -------------------------------------------------------------------------------- 1 | 2 | #' Validate Hex 3 | #' 4 | #' validate if string is hexidecimal 5 | #' color code 6 | #' 7 | #' @param x hexidecimal character 8 | #' @return logical. TRUE if object is a hexidecimal code 9 | #' 10 | #' @export 11 | is_hex <- function(x){ 12 | grepl("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$", x) 13 | } 14 | 15 | 16 | chartable <- function(table){ 17 | x <- rvest::html_table(table)[[1]] 18 | as.character(x[-1, ])[-1] 19 | } 20 | 21 | strip_html <- function(x){ 22 | rvest::html_text( 23 | rvest::read_html(x) 24 | ) 25 | } 26 | 27 | get_nums <- function(x){ 28 | as.numeric(strsplit(x, "\\D+")[[1]][-1]) 29 | } 30 | 31 | get_pal_color <- function(x){ 32 | x <- x[grepl("style", x)] 33 | get_bkg_color(x) 34 | } 35 | 36 | get_bkg_color <- function(x){ 37 | x <- strsplit(x, "background-color:") 38 | x <- sapply(x, function(x) x[2]) 39 | 40 | x <- gsub(';|\\\">|| ', '', x) 41 | sapply(x, fix_hex) 42 | } 43 | 44 | fix_hex <- function(x){ 45 | if(!is_hex(x)){ 46 | cli::cli_abort("'{x}' is not a valid hexidecimal colour.") 47 | } 48 | indx <- ifelse(nchar(x) == 4, TRUE, FALSE) 49 | 50 | x[indx] <- paste0(x[indx], gsub("#", "", x[indx])) 51 | x 52 | } 53 | 54 | nchar <- function(x){ 55 | j <- strsplit(x, "") 56 | j <- lapply(j, length) 57 | unlist(j) 58 | } 59 | 60 | randcol <- function(){ 61 | sample(1:255, 1) 62 | } 63 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%", 13 | fig.retina = 3 14 | ) 15 | ``` 16 | 17 | # colorhex 18 | 19 | 20 | [![CRAN status](https://www.r-pkg.org/badges/version/colorhex)](https://CRAN.R-project.org/package=colorhex) 21 | [![R-CMD-check](https://github.com/drmowinckels/colorhex/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/drmowinckels/colorhex/actions/workflows/R-CMD-check.yaml) 22 | 23 | 24 | 25 | The goal of colorhex is to create an interface to [color-hex.com](https://www.color-hex.com/), a website with hexidecimal colors and information about them. 26 | 27 | It also has lots of user-made palettes that can be used and browsed. 28 | 29 | ## Installation 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | You can install the development version from [GitHub](https://github.com/) with: 38 | 39 | ``` r 40 | # install.packages("remotes") 41 | remotes::install_github("drmowinckels/colorhex", ref = "main") 42 | ``` 43 | ## Example 44 | 45 | ### Single colors 46 | 47 | ```{r example, fig.width = 12} 48 | library(colorhex) 49 | 50 | x <- get_color("#470f0f") 51 | x 52 | plot(x) 53 | ``` 54 | 55 | ```{r "pop-cols", , fig.width = 12, fig.height=12} 56 | x <- get_popular_colors() 57 | x 58 | scales::show_col(x) 59 | ``` 60 | 61 | ### Palettes 62 | 63 | ```{r "latest", fig.height=10} 64 | latest <- get_latest_palettes() 65 | plot(latest) 66 | ``` 67 | 68 | ```{r "popular-palettes", fig.height=12} 69 | popular <- get_popular_palettes() 70 | plot(popular) 71 | ``` 72 | 73 | ### ggplot2 scales 74 | ```{r warning=FALSE} 75 | library(ggplot2) 76 | 77 | ggplot(mtcars, aes(mpg)) + 78 | geom_density(aes(fill = disp, group = disp)) + 79 | scale_fill_palettehex_c(popular) 80 | 81 | ggplot(mtcars, aes(mpg)) + 82 | geom_density(aes(fill = disp, group = disp)) + 83 | scale_fill_palettehex_c(popular, 3) 84 | 85 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 86 | geom_point() + 87 | scale_color_palettehex_d(popular) 88 | 89 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 90 | geom_point() + 91 | scale_color_palettehex_d(popular, 1872) 92 | ``` 93 | 94 | ```{r warning=FALSE} 95 | x <- get_color("#008080") 96 | 97 | ggplot(mtcars, aes(mpg)) + 98 | geom_density(aes(fill = disp, group = disp)) + 99 | scale_fill_colorhex_c(x) 100 | 101 | ggplot(mtcars, aes(mpg)) + 102 | geom_density(aes(fill = disp, group = disp)) + 103 | scale_fill_colorhex_c(x, "tints") 104 | 105 | ggplot(mtcars, aes(mpg)) + 106 | geom_density(aes(fill = disp, group = disp)) + 107 | scale_fill_colorhex_c(x, "shades") 108 | 109 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 110 | geom_point() + 111 | scale_color_colorhex_d(x, "triadic") 112 | 113 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 114 | geom_point() + 115 | scale_color_colorhex_d(x, "shades") 116 | ``` 117 | 118 | 119 | 120 | 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # colorhex 5 | 6 | 7 | 8 | [![CRAN 9 | status](https://www.r-pkg.org/badges/version/colorhex)](https://CRAN.R-project.org/package=colorhex) 10 | [![R-CMD-check](https://github.com/drmowinckels/colorhex/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/drmowinckels/colorhex/actions/workflows/R-CMD-check.yaml) 11 | 12 | 13 | The goal of colorhex is to create an interface to 14 | [color-hex.com](https://www.color-hex.com/), a website with hexidecimal 15 | colors and information about them. 16 | 17 | It also has lots of user-made palettes that can be used and browsed. 18 | 19 | ## Installation 20 | 21 | 22 | 23 | 24 | 25 | 26 | You can install the development version from 27 | [GitHub](https://github.com/) with: 28 | 29 | ``` r 30 | # install.packages("remotes") 31 | remotes::install_github("drmowinckels/colorhex", ref = "main") 32 | ``` 33 | 34 | ## Example 35 | 36 | ### Single colors 37 | 38 | ``` r 39 | library(colorhex) 40 | 41 | x <- get_color("#470f0f") 42 | x 43 | #> # Color-hex: #470f0f 44 | #> RGB: 71, 15, 15 45 | #> HSL: 0.00, 0.65, 0.17 46 | #> CMYK: 0.00, 0.79, 0.79   0.72 47 | #> triadic: #0f470f, #0f0f47 48 | #> complementary: #0f4747 49 | #> used in 2 palettes 50 | plot(x) 51 | ``` 52 | 53 | 54 | 55 | ``` r 56 | x <- get_popular_colors() 57 | x 58 | #> [1] "#ff80ed" "#065535" "#000000" "#133337" "#ffc0cb" "#ffffff" "#ffe4e1" 59 | #> [8] "#008080" "#ff0000" "#e6e6fa" "#ffd700" "#00ffff" "#ffa500" "#0000ff" 60 | #> [15] "#ff7373" "#c6e2ff" "#40e0d0" "#b0e0e6" "#d3ffce" "#f0f8ff" "#666666" 61 | #> [22] "#faebd7" "#bada55" "#fa8072" "#003366" "#ffb6c1" "#c0c0c0" "#ffff00" 62 | #> [29] "#800000" "#800080" "#c39797" "#00ff00" "#7fffd4" "#fff68f" "#eeeeee" 63 | #> [36] "#cccccc" "#f08080" "#20b2aa" "#ffc3a0" "#333333" "#66cdaa" "#c0d6e4" 64 | #> [43] "#ff6666" "#ff00ff" "#cbbeb5" "#ffdab9" "#468499" "#ff7f50" "#afeeee" 65 | #> [50] "#b4eeb4" "#00ced1" "#008000" "#660066" "#f6546a" "#0e2f44" "#b6fcd5" 66 | #> [57] "#990000" "#696969" "#f5f5f5" "#daa520" "#000080" "#6897bb" "#808080" 67 | #> [64] "#f5f5dc" "#088da5" "#8b0000" "#8a2be2" "#81d8d0" "#ccff00" "#ffff66" 68 | #> [71] "#ff4040" "#dddddd" "#2acaea" "#101010" "#0a75ad" "#ff1493" "#420420" 69 | #> [78] "#66cccc" "#a0db8e" "#999999" "#794044" "#3399ff" "#cc0000" "#00ff7f" 70 | scales::show_col(x) 71 | ``` 72 | 73 | 74 | 75 | ### Palettes 76 | 77 | ``` r 78 | latest <- get_latest_palettes() 79 | plot(latest) 80 | ``` 81 | 82 | 83 | 84 | ``` r 85 | popular <- get_popular_palettes() 86 | plot(popular) 87 | ``` 88 | 89 | 90 | 91 | ### ggplot2 scales 92 | 93 | ``` r 94 | library(ggplot2) 95 | 96 | ggplot(mtcars, aes(mpg)) + 97 | geom_density(aes(fill = disp, group = disp)) + 98 | scale_fill_palettehex_c(popular) 99 | ``` 100 | 101 | 102 | 103 | ``` r 104 | 105 | ggplot(mtcars, aes(mpg)) + 106 | geom_density(aes(fill = disp, group = disp)) + 107 | scale_fill_palettehex_c(popular, 3) 108 | ``` 109 | 110 | 111 | 112 | ``` r 113 | 114 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 115 | geom_point() + 116 | scale_color_palettehex_d(popular) 117 | ``` 118 | 119 | 120 | 121 | ``` r 122 | 123 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 124 | geom_point() + 125 | scale_color_palettehex_d(popular, 1872) 126 | ``` 127 | 128 | 129 | 130 | ``` r 131 | x <- get_color("#008080") 132 | 133 | ggplot(mtcars, aes(mpg)) + 134 | geom_density(aes(fill = disp, group = disp)) + 135 | scale_fill_colorhex_c(x) 136 | ``` 137 | 138 | 139 | 140 | ``` r 141 | 142 | ggplot(mtcars, aes(mpg)) + 143 | geom_density(aes(fill = disp, group = disp)) + 144 | scale_fill_colorhex_c(x, "tints") 145 | ``` 146 | 147 | 148 | 149 | ``` r 150 | 151 | ggplot(mtcars, aes(mpg)) + 152 | geom_density(aes(fill = disp, group = disp)) + 153 | scale_fill_colorhex_c(x, "shades") 154 | ``` 155 | 156 | 157 | 158 | ``` r 159 | 160 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 161 | geom_point() + 162 | scale_color_colorhex_d(x, "triadic") 163 | ``` 164 | 165 | 166 | 167 | ``` r 168 | 169 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 170 | geom_point() + 171 | scale_color_colorhex_d(x, "shades") 172 | ``` 173 | 174 | 175 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: ~ 2 | template: 3 | bootstrap: 5 4 | 5 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | ## R CMD check results 2 | 3 | 0 errors | 0 warnings | 0 note 4 | 5 | * This is a new release. 6 | * Fixes example failures when server is unreachable 7 | -------------------------------------------------------------------------------- /inst/WORDLIST: -------------------------------------------------------------------------------- 1 | Colour 2 | WGet 3 | colour 4 | colours 5 | favourited 6 | ggplot 7 | hexidecimal 8 | proto 9 | triadic 10 | www 11 | cran 12 | CMD 13 | -------------------------------------------------------------------------------- /man/figures/README-example-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-example-1.png -------------------------------------------------------------------------------- /man/figures/README-latest-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-latest-1.png -------------------------------------------------------------------------------- /man/figures/README-pop-cols-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-pop-cols-1.png -------------------------------------------------------------------------------- /man/figures/README-popular-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-popular-1.png -------------------------------------------------------------------------------- /man/figures/README-popular-palettes-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-popular-palettes-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-2-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-2-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-2-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-2-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-2-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-2-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-2-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-2-4.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-3-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-3-3.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-3-4.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drmowinckels/colorhex/19a0d5893feb4bafa2eb008983d696dd942e2612/man/figures/README-unnamed-chunk-3-5.png -------------------------------------------------------------------------------- /man/get_color.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color.R 3 | \name{get_color} 4 | \alias{get_color} 5 | \title{Get color information} 6 | \usage{ 7 | get_color(hex) 8 | } 9 | \arguments{ 10 | \item{hex}{character string that is a hexidecimal color} 11 | } 12 | \value{ 13 | list of class 'colorhex' 14 | } 15 | \description{ 16 | Get color information from www.color-hex.com 17 | of a hex-color. 18 | } 19 | \examples{ 20 | if(curl::has_internet()){ 21 | get_color("#470f0f") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /man/get_latest_palettes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/palette.R 3 | \name{get_latest_palettes} 4 | \alias{get_latest_palettes} 5 | \title{Get latest palettes} 6 | \usage{ 7 | get_latest_palettes() 8 | } 9 | \value{ 10 | data.frame with name, id and colours 11 | } 12 | \description{ 13 | Retrieve the most recently made palettes 14 | from www.color-hex.com 15 | } 16 | \examples{ 17 | if(curl::has_internet()){ 18 | get_latest_palettes() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /man/get_palette.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/palette.R 3 | \name{get_palette} 4 | \alias{get_palette} 5 | \title{Get palettes from id} 6 | \usage{ 7 | get_palette(id) 8 | } 9 | \arguments{ 10 | \item{id}{numeric id of a palette} 11 | } 12 | \value{ 13 | data.frame with palette information 14 | } 15 | \description{ 16 | Get palette information from www.color-hex.com 17 | based on the palette id (can be found in the url) 18 | } 19 | \examples{ 20 | if(curl::has_internet()){ 21 | get_palette(103107) 22 | 23 | # Lookup multiple palettes 24 | id <- c(103161, 103107) 25 | get_palette(id) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /man/get_popular_colors.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color.R 3 | \name{get_popular_colors} 4 | \alias{get_popular_colors} 5 | \title{Get popular colour} 6 | \usage{ 7 | get_popular_colors() 8 | } 9 | \value{ 10 | character vector of hex colours 11 | } 12 | \description{ 13 | www.color-hex.com has a list of colours 14 | that have been liked by the most users. 15 | This function will retrieve all of these. 16 | } 17 | \examples{ 18 | if(curl::has_internet()){ 19 | get_popular_colors() 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /man/get_popular_palettes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/palette.R 3 | \name{get_popular_palettes} 4 | \alias{get_popular_palettes} 5 | \title{Get most popular palettes} 6 | \usage{ 7 | get_popular_palettes() 8 | } 9 | \value{ 10 | data.frame with name, id and colours 11 | } 12 | \description{ 13 | Retrieve the palettes most users have 14 | checked as favorites from www.color-hex.com 15 | } 16 | \examples{ 17 | if(curl::has_internet()){ 18 | get_popular_palettes() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /man/get_random_color.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/color.R 3 | \name{get_random_color} 4 | \alias{get_random_color} 5 | \title{Generate random HEX colour} 6 | \usage{ 7 | get_random_color() 8 | } 9 | \value{ 10 | character hex value 11 | } 12 | \description{ 13 | Generate random HEX colour 14 | } 15 | \examples{ 16 | get_random_color() 17 | } 18 | -------------------------------------------------------------------------------- /man/is_hex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils.R 3 | \name{is_hex} 4 | \alias{is_hex} 5 | \title{Validate Hex} 6 | \usage{ 7 | is_hex(x) 8 | } 9 | \arguments{ 10 | \item{x}{hexidecimal character} 11 | } 12 | \value{ 13 | logical. TRUE if object is a hexidecimal code 14 | } 15 | \description{ 16 | validate if string is hexidecimal 17 | color code 18 | } 19 | -------------------------------------------------------------------------------- /man/scale-colorhex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_colorhex.R 3 | \name{scale-colorhex} 4 | \alias{scale-colorhex} 5 | \alias{scale_colour_colorhex_d} 6 | \alias{scale_color_colorhex_d} 7 | \alias{scale_fill_colorhex_d} 8 | \alias{scale_colour_colorhex_c} 9 | \alias{scale_color_colorhex_c} 10 | \alias{scale_fill_colorhex_c} 11 | \title{Colour scales for ggplot2} 12 | \usage{ 13 | scale_colour_colorhex_d(x, type = "triadic", reverse = FALSE, ...) 14 | 15 | scale_color_colorhex_d(x, type = "triadic", reverse = FALSE, ...) 16 | 17 | scale_fill_colorhex_d(x, type = "triadic", reverse = FALSE, ...) 18 | 19 | scale_colour_colorhex_c(x, type = "complementary", reverse = FALSE, ...) 20 | 21 | scale_color_colorhex_c(x, type = "complementary", reverse = FALSE, ...) 22 | 23 | scale_fill_colorhex_c(x, type = "complementary", reverse = FALSE, ...) 24 | } 25 | \arguments{ 26 | \item{x}{object of class \code{colorhex}} 27 | 28 | \item{type}{character. Type of colours to use. 29 | One of c("complementary", "triadic" (default), "shades", "tints", "related")} 30 | 31 | \item{reverse}{logical. If scale should b reversed (default: FALSE)} 32 | 33 | \item{...}{arguments to be passed to \code{\link[ggplot2]{discrete_scale}}} 34 | } 35 | \value{ 36 | a ggplot2-proto 37 | } 38 | \description{ 39 | Colour and fill scales for ggplot2 40 | plots, using object of class \code{colorhex} 41 | as basis for colour choices. 42 | } 43 | \details{ 44 | The \code{colorhex} class is a list where there 45 | is a variety of extra information on the hex 46 | colour selected. This information can be used 47 | to create colour scales to be used in ggplot2. 48 | } 49 | \section{Functions}{ 50 | \itemize{ 51 | \item \code{scale_colour_colorhex_d()}: Discrete colour scale 52 | 53 | \item \code{scale_color_colorhex_d()}: Discrete colour scale 54 | 55 | \item \code{scale_fill_colorhex_d()}: Discrete fill scale 56 | 57 | \item \code{scale_colour_colorhex_c()}: Continuous colour scale 58 | 59 | \item \code{scale_color_colorhex_c()}: Continuous colour scale 60 | 61 | \item \code{scale_fill_colorhex_c()}: Continuous fill scale 62 | 63 | }} 64 | \examples{ 65 | if(curl::has_internet()){ 66 | library(ggplot2) 67 | 68 | x <- get_color("#008080") 69 | 70 | ggplot(mtcars, aes(mpg)) + 71 | geom_density(aes(fill = disp, group = disp)) + 72 | scale_fill_colorhex_c(x) 73 | 74 | ggplot(mtcars, aes(mpg)) + 75 | geom_density(aes(fill = disp, group = disp)) + 76 | scale_fill_colorhex_c(x, "tints") 77 | 78 | ggplot(mtcars, aes(mpg)) + 79 | geom_density(aes(fill = disp, group = disp)) + 80 | scale_fill_colorhex_c(x, "shades") 81 | 82 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 83 | geom_point() + 84 | scale_color_colorhex_d(x, "triadic") 85 | 86 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 87 | geom_point() + 88 | scale_color_colorhex_d(x, "shades") 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /man/scale-palettehex.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/scale_palettehex.R 3 | \name{scale-palettehex} 4 | \alias{scale-palettehex} 5 | \alias{scale_colour_palettehex_d} 6 | \alias{scale_color_palettehex_d} 7 | \alias{scale_fill_palettehex_d} 8 | \alias{scale_colour_palettehex_c} 9 | \alias{scale_color_palettehex_c} 10 | \alias{scale_fill_palettehex_c} 11 | \title{Colour scales for ggplot2} 12 | \usage{ 13 | scale_colour_palettehex_d(x, which = 1, reverse = FALSE, ...) 14 | 15 | scale_color_palettehex_d(x, which = 1, reverse = FALSE, ...) 16 | 17 | scale_fill_palettehex_d(x, which = 1, reverse = FALSE, ...) 18 | 19 | scale_colour_palettehex_c(x, which = 1, reverse = FALSE, ...) 20 | 21 | scale_color_palettehex_c(x, which = 1, reverse = FALSE, ...) 22 | 23 | scale_fill_palettehex_c(x, which = 1, reverse = FALSE, ...) 24 | } 25 | \arguments{ 26 | \item{x}{object of class \code{palettehex}} 27 | 28 | \item{which}{selection of which palette of a set to choose. Either by name, 29 | id or numeric index.} 30 | 31 | \item{reverse}{logical. If scale should b reversed (default: FALSE)} 32 | 33 | \item{...}{arguments to be passed to \code{\link[ggplot2]{discrete_scale}}} 34 | } 35 | \value{ 36 | ggplot2-proto 37 | } 38 | \description{ 39 | Colour and fill scales for ggplot2 40 | plots, using object of class \code{palettehex}. 41 | } 42 | \details{ 43 | The \code{palettehex} class is a data.frame of 44 | many palettes. This function takes such a data.frame 45 | and a choice of palette by name, id or numeric index 46 | can be made for the scale. 47 | } 48 | \section{Functions}{ 49 | \itemize{ 50 | \item \code{scale_colour_palettehex_d()}: Discrete colour scale 51 | 52 | \item \code{scale_color_palettehex_d()}: Discrete colour scale 53 | 54 | \item \code{scale_fill_palettehex_d()}: Discrete fill scale 55 | 56 | \item \code{scale_colour_palettehex_c()}: Continuous colour scale 57 | 58 | \item \code{scale_color_palettehex_c()}: Continuous colour scale 59 | 60 | \item \code{scale_fill_palettehex_c()}: Continuous fill scale 61 | 62 | }} 63 | \examples{ 64 | if(curl::has_internet()){ 65 | library(ggplot2) 66 | 67 | x <- get_popular_palettes() 68 | 69 | ggplot(mtcars, aes(mpg)) + 70 | geom_density(aes(fill = disp, group = disp)) + 71 | scale_fill_palettehex_c(x) 72 | 73 | ggplot(mtcars, aes(mpg)) + 74 | geom_density(aes(fill = disp, group = disp)) + 75 | scale_fill_palettehex_c(x, 3) 76 | 77 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 78 | geom_point() + 79 | scale_color_palettehex_d(x) 80 | 81 | ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + 82 | geom_point() + 83 | scale_color_palettehex_d(x, 1872) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if(requireNamespace('spelling', quietly = TRUE)) 2 | spelling::spell_check_test(vignettes = TRUE, error = FALSE, 3 | skip_on_cran = TRUE) 4 | --------------------------------------------------------------------------------