Skip to content

Commit

Permalink
version 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
katelyndiaz authored and cran-robot committed Sep 15, 2023
0 parents commit a3abb9a
Show file tree
Hide file tree
Showing 29 changed files with 1,481 additions and 0 deletions.
32 changes: 32 additions & 0 deletions DESCRIPTION
@@ -0,0 +1,32 @@
Package: ggRtsy
Type: Package
Title: Add Some Van Gogh Colors and Overlay Colors on Your 'ggplot()'
Version: 0.1.0
Authors@R: c(
person("Katelyn", "Diaz", email = "katndiaz@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-6108-1682")),
person("Silas", "Weden", email = "sweden@smith.edu", role = "aut"),
person("Tess", "Goldmann", email = "tgoldmann@smith.edu", role = "aut"),
person("Aushanae", "Haller", email = "aushanaenhaller@gmail.com", role = "edt", comment = c(ORCID = "0000-0002-2090-1952")),
person("Kathleen", "Hablutzel", email = "krhablutzel@gmail.com", role = "edt", comment = c(ORCID = "0000-0002-7802-6353"))
)
Maintainer: Katelyn Diaz <katndiaz@gmail.com>
Description: Works with 'ggplot2' to add a Van Gogh color palette to the user’s repertoire.
It also has a function that work alongside 'ggplot2' to create more interesting data visualizations and add contextual information to the user’s plots.
License: CC0
Encoding: UTF-8
LazyData: true
Depends: R (>= 2.10)
RoxygenNote: 7.2.3
Imports: purrr, stringr, ggplot2, tibble, magrittr, grDevices, dplyr
Suggests: rmarkdown, knitr, testthat (>= 3.0.0)
Config/testthat/edition: 3
VignetteBuilder: knitr
NeedsCompilation: no
Packaged: 2023-09-14 16:34:54 UTC; katelyndiaz
Author: Katelyn Diaz [aut, cre] (<https://orcid.org/0000-0001-6108-1682>),
Silas Weden [aut],
Tess Goldmann [aut],
Aushanae Haller [edt] (<https://orcid.org/0000-0002-2090-1952>),
Kathleen Hablutzel [edt] (<https://orcid.org/0000-0002-7802-6353>)
Repository: CRAN
Date/Publication: 2023-09-15 19:12:05 UTC
28 changes: 28 additions & 0 deletions MD5
@@ -0,0 +1,28 @@
43e55d33fd5b14f8c7571f85a2b87384 *DESCRIPTION
9e6c728f00d5df743b513fa3e556d689 *NAMESPACE
0a554a8b27e997224e134cb2b265faa5 *R/PaletteColors.R
977b0562eb54e7a0383fa166e582181c *R/RGBToHex.R
1fef69a38273e8a5c71c24cd380c2fad *R/RectangleFiller.R
1454b092ea5b6b0df6154917d76436a2 *R/datasets.R
5b8432e5451ec44388b7ed493ffaa305 *README.md
9001dec7820ff2ae32944d560388c430 *build/vignette.rds
fa03005ef49fcc60ec64a08d6a4d342f *data/goghColors.rda
ddd6069aaeda9801fcafdb7413fcdec2 *data/goghPaintingSets.rda
5eae0d6df2d952d7e5708ca1d6e4b08c *inst/doc/Vignette.R
92bb6b2aa554e69b22a93d7f62d64a84 *inst/doc/Vignette.Rmd
210b227c6ceb2f016babbe1d9d97dd86 *inst/doc/Vignette.html
085578bc8c85e1532da71012ea11f3a4 *man/RectangleFiller.Rd
35ed96d80c717bf2b1c1d7dc06188f76 *man/figures/logo.png
7b9f7df107adf8238675994fe966f7e6 *man/goghColors.Rd
6f74cff4c76eac845754593f02867838 *man/goghPaintingSets.Rd
ab70d4b158c99313af12bdbe24b3900b *man/gogh_interpolate.Rd
9a1d9fafd2bf105312aa3c143e0641ef *man/gogh_palettes_pop.Rd
8e0ea8c49e31eeb32fcbca5afe6d733b *man/rgbToHex.Rd
d9c0e096e80f31b25abd24a1bf292e1d *man/scale_color_gogh.Rd
b8162fa614085f125429816645d9e6da *man/scale_fill_gogh.Rd
1c3cc3d94e302d2ada65f47bd1d66850 *tests/testthat.R
4553c3e0e6797dcc56c0184b6d7ca55d *tests/testthat/test-PaletteColors.R
a145ea48f29c1d983bc1d94ab7d7936c *tests/testthat/test-RGBToHex.R
4a8ed5574bbfb4106ff6e24678426a5b *tests/testthat/test-RectangleFiller.R
b3babc31376ce2f910be8e4e5f664690 *tests/testthat/test-goghColors.R
92bb6b2aa554e69b22a93d7f62d64a84 *vignettes/Vignette.Rmd
10 changes: 10 additions & 0 deletions NAMESPACE
@@ -0,0 +1,10 @@
# Generated by roxygen2: do not edit by hand

export(RectangleFiller)
export(gogh_interpolate)
export(gogh_palettes_pop)
export(rgbToHex)
export(scale_color_gogh)
export(scale_fill_gogh)
import(dplyr)
importFrom(magrittr,"%>%")
76 changes: 76 additions & 0 deletions R/PaletteColors.R
@@ -0,0 +1,76 @@
#' Different color palettes created from Van Gogh paintings
#' @export
#'

gogh_palettes_pop <- list(
`starryNight` = c("#23338C", "#30478C", "#5377A6", "#BDBF7E", "#BFA72C"), # https://uploads4.wikiart.org/00142/images/vincent-van-gogh/the-starry-night.jpg!Large.jpg
`sunflowers` = c("#74A629", "#F2EB80", "#F2E085", "#BF9821", "#A6681C"), # https://uploads7.wikiart.org/images/vincent-van-gogh/still-life-vase-with-fifteen-sunflowers-1888-1.jpg!Large.jpg
`selfPortrait` = c("#021F59", "#63A5BF", "#8C701C", "#BF9B6F", "#730202"), # https://uploads8.wikiart.org/images/vincent-van-gogh/self-portrait-1889-1.jpg!Large.jpg
`wheatField` = c("#73A9D9", "#477332", "#D9B13B", "#D98E32", "#A66329"), # https://uploads4.wikiart.org/images/vincent-van-gogh/wheat-field-with-cypresses-at-the-haude-galline-near-eygalieres-1889-2.jpg!Large.jpg
`cafeTerrace` = c("#2A6BBF", "#3F6CA6", "#F2C84B", "#D99036", "#BF6734"), # https://uploads2.wikiart.org/images/vincent-van-gogh/cafe-terrace-place-du-forum-arles-1888(1).jpg!Large.jpg
`rhoneStarry` = c("#073359", "#27668C", "#5A98BF", "#60734D", "#A3A658"), # https://uploads0.wikiart.org/00175/images/vincent-van-gogh/starry-night-over-the-rhone.jpg!Large.jpg
`irises` = c("#415AA6", "#6382BF", "#65A67C", "#8CA653", "#A66D58"), # https://uploads0.wikiart.org/00213/images/vincent-van-gogh/antique-3840759.jpg!Large.jpg
`almondBlossoms` = c("#236E8C", "#20788C", "#49B3BF", "#41BFBF", "#BDBF75") # https://uploads6.wikiart.org/images/vincent-van-gogh/branches-with-almond-blossom-1890(1).jpg!Large.jpg
)

#' Interpolate the color palette
#' @param palette the ggRtsy painting color palette of choice
#' @param reverse Boolean, will be TRUE if the user wants the palette reversed
#' @param ... further arguments passed to [ggRtsy::gogh_interpolate()]
#' @export
#' @return A color interpolation function.
#' If `reverse` is TRUE, it returns a reversed color interpolation function.
gogh_interpolate <- function(palette = "starryNight", reverse = FALSE, ...) {
pal <- gogh_palettes_pop[[palette]]
if (reverse == TRUE) {
pal <- rev(pal)
}
grDevices::colorRampPalette(pal, ...)
}

#' Creating the color scale for Van Gogh Colors
#' @param palette the ggRtsy painting color palette of choice
#' @param reverse Boolean, will be TRUE if the user wants the palette reversed
#' @param discrete Boolean if color aesthetic is discrete
#' @param ... further arguments passed to [ggRtsy::scale_color_gogh()]
#' @examples
#' if (require(ggplot2)) {
#' data <- data.frame(c = LETTERS[1:3],x = c(1,5,7),y = c(5,9,13))
#' ggplot(data, aes(x,y,color = c))+geom_point()+scale_color_gogh()
#' }
#' @export
#' @return A ggplot2 color scale.
#' If `discrete` is TRUE, it returns a discrete color scale; otherwise, a continuous color scale.
scale_color_gogh <- function(palette = "starryNight",
discrete = TRUE, reverse = FALSE, ...) {
pal <- gogh_interpolate(palette, reverse)

if (discrete == TRUE) {
ggplot2::discrete_scale("colour", paste0("gogh_", palette), palette = pal, ...)
} else {
ggplot2::scale_colour_gradientn(colours = pal(256), ...) # gradient is the default for continuous
}
}

#' Creating the color fill scale for Van Gogh Colors
#' @param palette Character name of palette in gogh_palettes_pop
#' @param discrete Boolean if color aesthetic is discrete
#' @param reverse Boolean if the palette should be reversed
#' @param ... Additional arguments used to discrete_scale() or scale_fill_gradientn()
#' to automatically interpolate between colors.
#' @examples
#' if (require(ggplot2)) {
#' data <- data.frame(c = LETTERS[1:3],x = c(1,5,7),y = c(5,9,13))
#' ggplot(data, aes(x,fill=c))+geom_bar()+scale_fill_gogh()
#' }
#' @export
#' @return No return value. Called for side effects.
scale_fill_gogh <- function(palette = "sunflowers", discrete = TRUE, reverse = FALSE, ...) {
pal <- gogh_interpolate(palette = palette, reverse = reverse)
if (discrete) {
ggplot2::discrete_scale("fill", paste0("gogh_", palette), palette = pal, ...)
} else {
ggplot2::scale_fill_gradientn(colours = pal(256), ...)
}
}

40 changes: 40 additions & 0 deletions R/RGBToHex.R
@@ -0,0 +1,40 @@
#' Converts RGB colors to Hex code colors
#' @details Taking input of a vector of RGB values in the format
#' "(0, 72, 186)", etc, and returns the corresponding
#' hex value in the format "#0048ba"
#'
#' @param rgbVec a vector of strings in the format "(0, 72, 186)"
#'
#' @return vector of hex code strings in the format "#0048ba"
#'
#' @export
#'
#' @importFrom magrittr %>%

rgbToHex <- function(rgbVec) {
hexdigit <- c(0:9, letters[1:6])
rgbMapFunc <- function(rgb) {
return(paste("#", hexdigit[as.numeric(stringr::str_split(stringr::str_remove_all(
rgb, "[( )]"
), "\\,")[[1]]) %/% 16 + 1][1],
hexdigit[as.numeric(stringr::str_split(stringr::str_remove_all(
rgb, "[( )]"
), "\\,")[[1]]) %% 16 + 1][1],
hexdigit[as.numeric(stringr::str_split(stringr::str_remove_all(
rgb, "[( )]"
), "\\,")[[1]]) %/% 16 + 1][2],
hexdigit[as.numeric(stringr::str_split(stringr::str_remove_all(
rgb, "[( )]"
), "\\,")[[1]]) %% 16 + 1][2],
hexdigit[as.numeric(stringr::str_split(stringr::str_remove_all(
rgb, "[( )]"
), "\\,")[[1]]) %/% 16 + 1][3],
hexdigit[as.numeric(stringr::str_split(stringr::str_remove_all(
rgb, "[( )]"
), "\\,")[[1]]) %% 16 + 1][3],
sep = ""
))
}

return(purrr::map_chr(rgbVec, rgbMapFunc))
}
37 changes: 37 additions & 0 deletions R/RectangleFiller.R
@@ -0,0 +1,37 @@
#' Adds transparent coloring horizontally across a ggplot
#'
#' Adds up to 5 colors of choice horizontally across a ggplot
#' graph for data emphasis or decoration.
#'
#' @param plot1 a ggplot with a continuous x-axis
#' @param hex_codes series of wanted colors
#'
#' @return ggplot item with colors
#'
#' @export
#'
#' @import dplyr
#' @importFrom magrittr %>%

RectangleFiller <- function(plot1,
hex_codes = c("red", "blue", "green", "orange", "purple")) {
rect_height <- fill <- NULL

data <- plot1$data[unlist(plot1$labels)] %>%
purrr::map_dfr(range, na.rm = TRUE)
x_min <- data[[1, 1]]
x_max <- data[[2, 1]]
width <- (x_max - x_min) / length(hex_codes)

coords <- tibble::tibble(
x_center = seq(from = x_min + width / 2, to = x_max, by = width),
y_center = mean(data[[2]]),
rect_height = Inf,
fill = letters[1:length(hex_codes)]
)
names(coords)[1:2] <- unlist(plot1$labels[1:2])

plot1 +
ggplot2::geom_tile(data = coords, ggplot2::aes(height = rect_height, fill = fill), alpha = .2) +
ggplot2::scale_fill_manual(values = hex_codes, guide = FALSE)
}
37 changes: 37 additions & 0 deletions R/datasets.R
@@ -0,0 +1,37 @@
#' Sampling of Colors from Van Gogh Paintings
#'
#' This dataset consists of information on 986 colors across Van Gogh paintings.
#'
#' @format A data frame of 986 rows representing colors selected from
#' Van Gogh's painting. 5 colors were selected from each painting.
#' Consists of 3 variables.
#'
#' \describe{
#' \item{name}{Color name}
#' \item{rgb}{Color RGB value}
#' \item{hex}{Color hex code value}
#' }
#' @source Kaggle Konstantinos Katserelis <https://www.kaggle.com/datasets/pointblanc/colors-of-van-gogh?select=color_space.csv>
#' Note data is released under CC BY-SA 4.0
"goghColors"


#' Van Gogh Paintings Information
#'
#' This dataset consists of information about and colors from all 1931
#' of Van Gogh's paintings.
#'
#' @format A data frame of 1931 rows representing information from
#' Van Gogh's paintings. Consists of 6 variables.
#'
#' \describe{
#' \item{name}{Painting name}
#' \item{colors}{5 colors picked from the painting}
#' \item{year}{Year painting was painted}
#' \item{genre}{Genre of painting}
#' \item{style}{Style of painting}
#' \item{link}{Link of image of painting}
#' }
#' @source Kaggle Konstantinos Katserelis <https://www.kaggle.com/datasets/pointblanc/colors-of-van-gogh?select=color_space.csv>
#' Note data is released under CC BY-SA 4.0
"goghPaintingSets"

0 comments on commit a3abb9a

Please sign in to comment.