Skip to content

Commit

Permalink
Add color schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
jbengler committed Feb 29, 2024
1 parent ee6be9e commit 000507e
Show file tree
Hide file tree
Showing 33 changed files with 848 additions and 191 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tidyplots
Title: Tidy Plots Using the Pipe
Version: 0.0.2
Version: 0.0.2.9000
Authors@R:
person("Jan Broder", "Engler", , "[email protected]", role = c("aut", "cre", "cph"),
comment = c(ORCID = "0000-0002-3169-2076"))
Expand All @@ -11,7 +11,6 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
cli,
colorspace,
dplyr,
forcats,
ggbeeswarm,
Expand All @@ -21,14 +20,14 @@ Imports:
ggrepel,
glue,
Hmisc,
htmltools,
patchwork,
purrr,
ragg,
rlang,
scales,
stringr,
svglite,
tibble,
tidyr
Depends:
R (>= 2.10)
Expand Down
20 changes: 18 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Generated by roxygen2: do not edit by hand

S3method("[",tidycolor)
S3method("[[",tidycolor)
S3method(c,tidycolor)
S3method(print,tidycolor)
export("%>%")
export(add)
export(add_area)
Expand Down Expand Up @@ -68,13 +72,25 @@ export(adjust_rotate_plot)
export(adjust_x_axis)
export(adjust_y_axis)
export(all_rows)
export(colors_continuous_blue_pink_yellow)
export(colors_continuous_inferno)
export(colors_continuous_magma)
export(colors_continuous_turbo)
export(colors_continuous_viridis)
export(colors_discrete_circle)
export(colors_discrete_metro_ui)
export(colors_diverging_RdBu)
export(colors_diverging_RdYlBu)
export(colors_diverging_blue2brown)
export(colors_diverging_blue2red)
export(filter_rows)
export(first_rows)
export(format_number)
export(format_p_value)
export(last_rows)
export(max_rows)
export(min_rows)
export(new_color_scheme)
export(remove_legend)
export(remove_legend_title)
export(remove_padding)
Expand All @@ -97,9 +113,8 @@ export(reorder_y_axis_labels)
export(reverse_color_labels)
export(reverse_x_axis_labels)
export(reverse_y_axis_labels)
export(sample_rows)
export(save_plot)
export(show_color_palettes)
export(show_plot)
export(sort_color_labels)
export(sort_x_axis_labels)
export(sort_y_axis_labels)
Expand All @@ -110,3 +125,4 @@ export(theme_minimal_xy)
export(theme_minimal_y)
export(theme_tidyplot)
export(tidyplot)
export(view_plot)
10 changes: 8 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# tidyplots (development version)

* New S3 class `tidycolor` for color schemes. The print method of `tidycolor` sends a html preview of the color scheme to the RStudio viewer panel.
* New `new_color_scheme()` to create custom color schemes.
* New build-in color schemes using the prefix `colors_discrete_`, `colors_continuous_` and `colors_diverging_`.
* `adjust_colors()` now also works with too few or too many provided colors.
* New function factory behind `adjust_x_axis()` and `adjust_y_axis()`

# tidyplots 0.0.2

* Renaming functions to improve consistency.

* The package is still in early development. Expect user-facing and breaking changes.

# tidyplots 0.0.1

* Initial release. tidyplots streamlines the creation of publication-ready plots for scientific papers, making it incredibly easy to add and refine plot elements. It allows precise control over composition, style, and absolute sizes, while its utilization of the pipe `%>%` simplifies the construction of advanced plotting pipelines.

* The package is still in early development. Expect user-facing and breaking changes.
59 changes: 59 additions & 0 deletions R/aaa.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
color_palettes <- list(
black_blue_pink_yellow = c(
"#161523","#171943","#2C2E68","#2E3D88","#3F519D","#48569F","#5F569F",
"#7D5099","#8B5197","#A14F96","#C85296","#DB5999","#E06A7F","#E27F6D",
"#E68F63","#ECA562","#F3BD66","#F9D966","#FAF06F","#EEE969"),

blue_pink_yellow = c(
"#00034D","#000F9F","#001CEF","#241EF5","#5823F6","#A033E0","#E85AB1",
"#F1907C","#F4AF63","#FCE552","#FFFB6D"),

blue2brown = c(
"#1961A5","#2671B5","#2D80BF","#268CC9","#119DD8","#00B2EB","#66C5EF",
"#C4E5F8","#FEFCF6","#FDEEB8","#FCDD67","#F6C445","#E78B43","#DD5642",
"#DB3E34","#CA3632","#B3322E"),

bunq = c(
"#248746","#2D9B47","#62B64F","#88CC53","#3CB7AA","#3296D7","#2772BA",
"#1D5D83","#973431","#E23133","#F18823","#F5C836"),

color_circle_vivid = c(
"#939393","#644296","#F08533","#D1352C","#559E3F","#3B78B0"),

ggsci_d3 = c(
"#1F77B4","#FF7F0E","#2CA02C","#D62728","#9467BD","#8C564B","#E377C2",
"#7F7F7F","#BCBD22","#17BECF"),

ggsci_jco = c(
"#0073C2","#EFC000","#868686","#CD534C","#7AA6DC","#003C67","#8F7700",
"#3B3B3B","#A73030","#4A6990"),

ggsci_locuszoom = c(
"#D43F3A","#EEA236","#5CB85C","#46B8DA","#357EBD","#9632B8","#B8B8B8"),

ggsci_npg = c(
"#E64B35","#4DBBD5","#00A087","#3C5488","#F39B7F","#8491B4","#91D1C2",
"#DC0000","#7E6148","#B09C85"),

metro_ui = c(
"#4DACD6","#4FAE62","#F6C54D","#E37D46","#C02D45"),

multiqc_align = c(
"#437BB1","#7CB5EC","#F7A35C","#B1084C","#7F0000"),

multiqc_count = c(
"#7CB5EC","#434348","#90ED7D","#F7A35C"),

multiqc_fastq_screen = c(
"#87B5E7","#434348","#A6E98A","#ECA669","#8087E2","#E06681","#E2D269",
"#F7A35C","#B1084C","#4A8E8E","#E36561","#77150C","#CCCCCC"),

white_ocre_brown = c(
"#FDFCF4","#F9F0CC","#F9E59F","#F4DA7A","#F1CB62","#EDBF55","#DF9350",
"#D87D4A","#CF5C45","#BC403D","#AD3C39","#9F3736","#983534","#842E2E"),

white_turquise_blue = c(
"#FCFBDF","#F7F7D1","#EDF0BD","#E3EBB6","#CFE1B5","#C4DDB6","#9FCEB4",
"#83C5B3","#5DBAB7","#1FB1BA","#00AFBF","#049FBF","#0493BF","#037DB5",
"#036DAC","#16579E","#224B95","#2B3D8B","#2B3977","#232959","#1F2451")
)
2 changes: 1 addition & 1 deletion R/add.R
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ add_heatmap <- function(gg, scale = c("none", "row", "column"), rotate_labels =
ggplot2::coord_cartesian(expand = FALSE)

if (scale %in% c("row", "column"))
gg <- gg %>% adjust_colors(c("blue", "white", "red"), as_palette = TRUE)
gg <- gg %>% adjust_colors(c("blue", "white", "red"))

add_geom(gg, ggplot2::geom_raster(mapping = mapping, ...),
rasterize = rasterize, rasterize_dpi = rasterize_dpi)
Expand Down
39 changes: 0 additions & 39 deletions R/adjust.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,45 +130,6 @@ adjust_x_axis <- ff_adjust_axis("x")
adjust_y_axis <- ff_adjust_axis("y")


#' Adjust colors
#' @param gg bla
#' @param new_colors bla
#' @param saturation bla
#' @param as_palette bla
#' @param labels bla
#' @param ... bla
#' @export
adjust_colors <- function(gg, new_colors = NULL, saturation = 1, as_palette = FALSE,
labels = tidyplot_parse_labels(), ...) {
out <- gg
# as individual colors
if (!is.null(new_colors) && as_palette == FALSE) {
out$tidyplot$new_colors <- new_colors
suppressMessages(
out <-
out +
ggplot2::scale_fill_manual(values = apply_saturation(new_colors, saturation = saturation), drop = FALSE, labels = labels, ...) +
ggplot2::scale_color_manual(values = new_colors, drop = FALSE, labels = labels, ...)
)
cli::cli_alert_success("adjust_colors: applied {.pkg new_colors}")
} else {
# as color palette
suppressMessages({
if (is_discrete(gg, "colour"))
out <- out + my_scale_color_d(palette = new_colors, drop = FALSE, labels = labels, ...)
if (is_discrete(gg, "fill"))
out <- out + my_scale_fill_d(palette = new_colors, saturation = saturation, drop = FALSE, labels = labels, ...)
if (is_continuous(gg, "colour"))
out <- out + my_scale_color_c(palette = new_colors, labels = labels, ...)
if (is_continuous(gg, "fill"))
out <- out + my_scale_fill_c(palette = new_colors, saturation = saturation, labels = labels, ...)
})
cli::cli_alert_success("adjust_colors: applied {.pkg new color palette}")
}
out
}


#' Adjust plot size
#' @param gg bla
#' @param width bla
Expand Down
Loading

0 comments on commit 000507e

Please sign in to comment.