From 2b151e3f85e3a819058b6d982d30c416bfe55aad Mon Sep 17 00:00:00 2001 From: Josh Cook Date: Thu, 21 Feb 2019 13:19:18 -0500 Subject: [PATCH 1/7] feat: use COSMIC colors for hallmarks of cancer and mutational signatures --- NAMESPACE | 4 ++ R/discrete-cosmic.R | 106 ++++++++++++++++++++++++++++++++++++++ R/sysdata.rda | Bin 5049 -> 5429 bytes data-raw/data-generator.R | 24 +++++++++ man/pal_cosmic.Rd | 32 ++++++++++++ man/scale_cosmic.Rd | 63 ++++++++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 R/discrete-cosmic.R create mode 100644 man/pal_cosmic.Rd create mode 100644 man/scale_cosmic.Rd diff --git a/NAMESPACE b/NAMESPACE index 182bc9f..62d8498 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(pal_aaas) +export(pal_cosmic) export(pal_d3) export(pal_futurama) export(pal_gsea) @@ -21,6 +22,7 @@ export(pal_ucscgb) export(rgb_gsea) export(rgb_material) export(scale_color_aaas) +export(scale_color_cosmic) export(scale_color_d3) export(scale_color_futurama) export(scale_color_gsea) @@ -39,6 +41,7 @@ export(scale_color_tron) export(scale_color_uchicago) export(scale_color_ucscgb) export(scale_colour_aaas) +export(scale_colour_cosmic) export(scale_colour_d3) export(scale_colour_futurama) export(scale_colour_gsea) @@ -57,6 +60,7 @@ export(scale_colour_tron) export(scale_colour_uchicago) export(scale_colour_ucscgb) export(scale_fill_aaas) +export(scale_fill_comis) export(scale_fill_d3) export(scale_fill_futurama) export(scale_fill_gsea) diff --git a/R/discrete-cosmic.R b/R/discrete-cosmic.R new file mode 100644 index 0000000..7e3fad9 --- /dev/null +++ b/R/discrete-cosmic.R @@ -0,0 +1,106 @@ +#' COSMIC Color Palettes +#' +#' Color palettes inspired by the colors used projects from the +#' \href{https://cancer.sanger.ac.uk/cosmic}{Catalogue Of +#' Somatic Mutations in Cancers (COSMIC)} +#' +#' @param palette Palette type. +#' Currently there is two available options: \code{"signature_substitutions"} +#' (6-color palette) and \code{"hallmarks"} (10-color palette). +#' @param alpha Transparency level, a real number in (0, 1]. +#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details. +#' +#' @export pal_cosmic +#' +#' @importFrom grDevices col2rgb rgb +#' @importFrom scales manual_pal +#' +#' @author Nan Xiao <\email{me@@nanx.me}> | +#' <\href{https://nanx.me}{https://nanx.me}> +#' @author Joshua H. Cook <\email{joshuacook0023@@gmail.com}> | +#' <\href{https://github.com/jhrcook}{GitHub/jhrcook}> +#' +#' @examples +#' library("scales") +#' show_col(pal_cosmic("hallmark")(10)) +#' show_col(pal_cosmic("hallmark", alpha = 0.6)(10)) +#' show_col(pal_cosmic("signature_substitutions")(6)) +#' show_col(pal_cosmic("signature_substitutions", alpha = 0.6)(6)) +pal_cosmic <- function(palette = c("hallmarks"), alpha = 1) { + palette <- match.arg(palette) + + if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]") + + raw_cols <- ggsci_db$"cosmic"[[palette]] + raw_cols_rgb <- col2rgb(raw_cols) + alpha_cols <- rgb( + raw_cols_rgb[1L, ], raw_cols_rgb[2L, ], raw_cols_rgb[3L, ], + alpha = alpha * 255L, names = names(raw_cols), + maxColorValue = 255L + ) + + manual_pal(unname(alpha_cols)) +} + +#' COSMIC Color Scales +#' +#' See \code{\link{pal_cosmic}} for details. +#' +#' @inheritParams pal_cosmic +#' @param ... additional parameters for \code{\link[ggplot2]{discrete_scale}} +#' +#' @export scale_color_cosmic +#' +#' @importFrom ggplot2 discrete_scale +#' +#' @author Nan Xiao <\email{me@@nanx.me}> | +#' <\href{https://nanx.me}{https://nanx.me}> +#' @author Joshua H. Cook <\email{joshuacook0023@@gmail.com}> | +#' <\href{https://github.com/jhrcook}{GitHub/jhrcook}> +#' +#' @rdname scale_cosmic +#' +#' @examples +#' +#' # TODO: change to useing this palette +#' +#' library("ggplot2") +#' data("diamonds") +#' +#' ggplot( +#' subset(diamonds, carat >= 2.2), +#' aes(x = table, y = price, colour = cut) +#' ) + +#' geom_point(alpha = 0.7) + +#' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + +#' theme_dark() + theme( +#' panel.background = element_rect(fill = "#2D2D2D"), +#' legend.key = element_rect(fill = "#2D2D2D") +#' ) + +#' scale_color_cosmic() +#' +#' ggplot( +#' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), +#' aes(x = depth, fill = cut) +#' ) + +#' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + +#' theme_dark() + theme( +#' panel.background = element_rect(fill = "#2D2D2D") +#' ) + +#' scale_fill_cosmic() +scale_color_cosmic <- function(palette = c("hallmarks"), alpha = 1, ...) { + palette <- match.arg(palette) + discrete_scale("colour", "cosmic", pal_cosmic(palette, alpha), ...) +} + +#' @export scale_colour_cosmic +#' @rdname scale_cosmic +scale_colour_cosmic <- scale_color_cosmic + +#' @export scale_fill_cosmic +#' @importFrom ggplot2 discrete_scale +#' @rdname scale_cosmic +scale_fill_cosmic <- function(palette = c("hallmarks"), alpha = 1, ...) { + palette <- match.arg(palette) + discrete_scale("fill", "cosmic", pal_cosmic(palette, alpha), ...) +} diff --git a/R/sysdata.rda b/R/sysdata.rda index 6631603f98e6c8fc46482dd7cc7d9c9df445637a..b977dff01a9d0ad379eb6a51d1a795c2bfedf5e9 100644 GIT binary patch literal 5429 zcmZWrRa_H*!$bv@kcNTOL}DOalaTIELO@`2N-EtgT@qt-3IdXo+URa1M#x}vk8T9M zc>Dg}J>Ap&?(TOF#}xY<=YR2J6oPR>_kD*d#H{kNmbq3zJUqO9luL-?jkvTF69{$; zH1x=`b0*}ZQ#KLun1|pHBHu(_uepKeSotu)NY#CI3TSloqY)urUtfgZOaJr$rT6XP z0VnH&Q|!;iCH+p$I&v5#JsxiN2Uk)kE^obSKaG{Qk5;3(^ThvMcOQ3)cQj*Je z55_#O68~_nDX~+&m`UY9GVSgR?bpABCMFX!YguL-!&S0-BjWf3zu(dpj3|uw>xikw zt)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8C;eHNYCC58sd9K8^j90nBG!L=F7F(9;GR_)KnSUMbsBPsCl;?}c-?lmze6 zLSQQcSkxcP*73)n=}P*q^S@8oerW57Rw3q~EX#y*tbBjx!UJ6!shex#DYYad>9-)! zL_Xv8e(6Yt;b_4aU50oO&lHVS|3tqZc$A" = "#5ABCEB", + "C>G" = "#050708", + "C>T" = "#D33C32", + "T>A" = "#CBCACB", + "T>C" = "#ABCD72", + "T>G" = "#E7C9C6" +) + # Color palette inspired by The Simpsons ggsci_db$"simpsons"$"springfield" <- c( "HomerYellow" = "#FED439", "HomerBlue" = "#709AE1", diff --git a/man/pal_cosmic.Rd b/man/pal_cosmic.Rd new file mode 100644 index 0000000..01a9291 --- /dev/null +++ b/man/pal_cosmic.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/discrete-cosmic.R +\name{pal_cosmic} +\alias{pal_cosmic} +\title{COSMIC Color Palettes} +\usage{ +pal_cosmic(palette = c("hallmarks"), alpha = 1) +} +\arguments{ +\item{palette}{Palette type. +Currently there is two available options: \code{"signature_substitutions"} +(6-color palette) and \code{"hallmarks"} (10-color palette).} + +\item{alpha}{Transparency level, a real number in (0, 1]. +See \code{alpha} in \code{\link[grDevices]{rgb}} for details.} +} +\description{ +Color palettes inspired by the colors used projects from the +\href{https://cancer.sanger.ac.uk/cosmic}{Catalogue Of +Somatic Mutations in Cancers (COSMIC)} +} +\examples{ +library("scales") +show_col(pal_cosmic("hallmark")(10)) +show_col(pal_cosmic("hallmark", alpha = 0.6)(10)) +show_col(pal_cosmic("signature_substitutions")(6)) +show_col(pal_cosmic("signature_substitutions", alpha = 0.6)(6)) +} +\author{ +Nan Xiao <\email{me@nanx.me}> | +<\href{https://nanx.me}{https://nanx.me}> +} diff --git a/man/scale_cosmic.Rd b/man/scale_cosmic.Rd new file mode 100644 index 0000000..cdffb87 --- /dev/null +++ b/man/scale_cosmic.Rd @@ -0,0 +1,63 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/discrete-cosmic.R +\name{scale_color_cosmic} +\alias{scale_color_cosmic} +\alias{scale_colour_cosmic} +\alias{scale_fill_cosmic} +\title{COSMIC Color Scales} +\usage{ +scale_color_cosmic(palette = c("hallmarks"), alpha = 1, ...) + +scale_colour_cosmic(palette = c("hallmarks"), alpha = 1, ...) + +scale_fill_cosmic(palette = c("hallmarks"), alpha = 1, ...) +} +\arguments{ +\item{palette}{Palette type. +Currently there is two available options: \code{"signature_substitutions"} +(6-color palette) and \code{"hallmarks"} (10-color palette).} + +\item{alpha}{Transparency level, a real number in (0, 1]. +See \code{alpha} in \code{\link[grDevices]{rgb}} for details.} + +\item{...}{additional parameters for \code{\link[ggplot2]{discrete_scale}}} +} +\description{ +See \code{\link{pal_cosmic}} for details. +} +\examples{ + +# TODO: change to useing this palette + +library("ggplot2") +data("diamonds") + +ggplot( + subset(diamonds, carat >= 2.2), + aes(x = table, y = price, colour = cut) +) + + geom_point(alpha = 0.7) + + geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + + theme_dark() + theme( + panel.background = element_rect(fill = "#2D2D2D"), + legend.key = element_rect(fill = "#2D2D2D") + ) + + scale_color_cosmic() + +ggplot( + subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), + aes(x = depth, fill = cut) +) + + geom_histogram(colour = "black", binwidth = 1, position = "dodge") + + theme_dark() + theme( + panel.background = element_rect(fill = "#2D2D2D") + ) + + scale_fill_cosmic() +} +\author{ +Nan Xiao <\email{me@nanx.me}> | +<\href{https://nanx.me}{https://nanx.me}> + +Joshua H. Cook <\email{joshuacook0023@gmail.com}> | +<\href{https://github.com/jhrcook}{GitHub/jhrcook}> +} From 8cc4f51e541d96014bcb17583196ffbe1c2f5de4 Mon Sep 17 00:00:00 2001 From: Josh Cook Date: Thu, 21 Feb 2019 13:30:10 -0500 Subject: [PATCH 2/7] doc: includes COSMIC example using 'hallmarks' --- vignettes/ggsci.Rmd | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vignettes/ggsci.Rmd b/vignettes/ggsci.Rmd index 586be1c..d4a70f2 100644 --- a/vignettes/ggsci.Rmd +++ b/vignettes/ggsci.Rmd @@ -76,6 +76,9 @@ summarized in the table below. | | `scale_fill_uchicago()` | `"light"`
| | | | | `"dark"` | | +-----------------+------------------------------+--------------------------------+----------------------+ +| COSMIC | `scale_color_cosmic()` | `"hallmarks"` | `pal_cosmic()` | +| | `scale_fill_cosmic()` | `"signature_substitutions"` | | ++-----------------+------------------------------+--------------------------------+----------------------+ | Star Trek | `scale_color_startrek()` | `"uniform"` | `pal_startrek()` | | | `scale_fill_startrek()` | | | +-----------------+------------------------------+--------------------------------+----------------------+ @@ -263,6 +266,17 @@ p2_uchicago <- p2 + scale_fill_uchicago() grid.arrange(p1_uchicago, p2_uchicago, ncol = 2) ``` +## COSMIC + +# Color palette inspired by [COSMIC](https://cancer.sanger.ac.uk/cosmic) Hallmarks of Cancer (`"hallmarks"`) and the mutational signature substitution (`"signature_substitutions"`) colors. + +```{r, fig.width = 10.67, fig.height = 4, out.width = 800, out.height = 300, dpi = 150} +p1_cancer_hallmarks <- p1 + scale_color_cosmic() +p2_cancer_hallmarks <- p2 + scale_fill_cosmic() +grid.arrange(p1_cancer_hallmarks, p2_cancer_hallmarks, ncol = 2) +``` + + ## Star Trek This palette is inspired by the (uniform) colors in Star Trek: From ba7fe56fdbac89699652e482e4f274cbf5123b8a Mon Sep 17 00:00:00 2001 From: Josh Cook Date: Thu, 21 Feb 2019 13:30:41 -0500 Subject: [PATCH 3/7] doc: build updated COSMIC palette doc --- NAMESPACE | 2 +- man/pal_cosmic.Rd | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 62d8498..6f461bb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -60,7 +60,7 @@ export(scale_colour_tron) export(scale_colour_uchicago) export(scale_colour_ucscgb) export(scale_fill_aaas) -export(scale_fill_comis) +export(scale_fill_cosmic) export(scale_fill_d3) export(scale_fill_futurama) export(scale_fill_gsea) diff --git a/man/pal_cosmic.Rd b/man/pal_cosmic.Rd index 01a9291..7bfaa2e 100644 --- a/man/pal_cosmic.Rd +++ b/man/pal_cosmic.Rd @@ -29,4 +29,7 @@ show_col(pal_cosmic("signature_substitutions", alpha = 0.6)(6)) \author{ Nan Xiao <\email{me@nanx.me}> | <\href{https://nanx.me}{https://nanx.me}> + +Joshua H. Cook <\email{joshuacook0023@gmail.com}> | +<\href{https://github.com/jhrcook}{GitHub/jhrcook}> } From cf224e152e8c0715532822437d9d596f30f2bc23 Mon Sep 17 00:00:00 2001 From: Josh Cook Date: Thu, 21 Feb 2019 13:33:02 -0500 Subject: [PATCH 4/7] doc: example for using scale_fill/color_cosmic in function doc --- R/discrete-cosmic.R | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/R/discrete-cosmic.R b/R/discrete-cosmic.R index 7e3fad9..276aab4 100644 --- a/R/discrete-cosmic.R +++ b/R/discrete-cosmic.R @@ -61,9 +61,6 @@ pal_cosmic <- function(palette = c("hallmarks"), alpha = 1) { #' @rdname scale_cosmic #' #' @examples -#' -#' # TODO: change to useing this palette -#' #' library("ggplot2") #' data("diamonds") #' @@ -73,21 +70,14 @@ pal_cosmic <- function(palette = c("hallmarks"), alpha = 1) { #' ) + #' geom_point(alpha = 0.7) + #' geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + -#' theme_dark() + theme( -#' panel.background = element_rect(fill = "#2D2D2D"), -#' legend.key = element_rect(fill = "#2D2D2D") -#' ) + -#' scale_color_cosmic() +#' theme_bw() + scale_color_cosmic() #' #' ggplot( #' subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), #' aes(x = depth, fill = cut) #' ) + #' geom_histogram(colour = "black", binwidth = 1, position = "dodge") + -#' theme_dark() + theme( -#' panel.background = element_rect(fill = "#2D2D2D") -#' ) + -#' scale_fill_cosmic() +#' theme_bw() + scale_fill_cosmic() scale_color_cosmic <- function(palette = c("hallmarks"), alpha = 1, ...) { palette <- match.arg(palette) discrete_scale("colour", "cosmic", pal_cosmic(palette, alpha), ...) From 52c70ce2508545b7dc0d1cee922ee910c29c5c3c Mon Sep 17 00:00:00 2001 From: Josh Cook Date: Thu, 21 Feb 2019 13:45:55 -0500 Subject: [PATCH 5/7] doc: typo --- vignettes/ggsci.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vignettes/ggsci.Rmd b/vignettes/ggsci.Rmd index d4a70f2..d06945e 100644 --- a/vignettes/ggsci.Rmd +++ b/vignettes/ggsci.Rmd @@ -76,7 +76,7 @@ summarized in the table below. | | `scale_fill_uchicago()` | `"light"`
| | | | | `"dark"` | | +-----------------+------------------------------+--------------------------------+----------------------+ -| COSMIC | `scale_color_cosmic()` | `"hallmarks"` | `pal_cosmic()` | +| COSMIC | `scale_color_cosmic()` | `"hallmarks"` | `pal_cosmic()` | | | `scale_fill_cosmic()` | `"signature_substitutions"` | | +-----------------+------------------------------+--------------------------------+----------------------+ | Star Trek | `scale_color_startrek()` | `"uniform"` | `pal_startrek()` | From 8dbe6bb6e0497b7f53fc65ef7a7642ba1c2ef38a Mon Sep 17 00:00:00 2001 From: Josh Cook Date: Thu, 21 Feb 2019 13:49:52 -0500 Subject: [PATCH 6/7] fix: can call 'signature_substitutions' --- R/discrete-cosmic.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/discrete-cosmic.R b/R/discrete-cosmic.R index 276aab4..d952da2 100644 --- a/R/discrete-cosmic.R +++ b/R/discrete-cosmic.R @@ -22,11 +22,11 @@ #' #' @examples #' library("scales") -#' show_col(pal_cosmic("hallmark")(10)) -#' show_col(pal_cosmic("hallmark", alpha = 0.6)(10)) +#' show_col(pal_cosmic("hallmarks")(10)) +#' show_col(pal_cosmic("hallmarks", alpha = 0.6)(10)) #' show_col(pal_cosmic("signature_substitutions")(6)) #' show_col(pal_cosmic("signature_substitutions", alpha = 0.6)(6)) -pal_cosmic <- function(palette = c("hallmarks"), alpha = 1) { +pal_cosmic <- function(palette = c("hallmarks", "signature_substitutions"), alpha = 1) { palette <- match.arg(palette) if (alpha > 1L | alpha <= 0L) stop("alpha must be in (0, 1]") From b1683ecf135c5f20003371128484a7cc6cd13b7f Mon Sep 17 00:00:00 2001 From: Josh Cook Date: Thu, 21 Feb 2019 13:52:58 -0500 Subject: [PATCH 7/7] doc: updated for fixing scale_cosmic errors --- man/pal_cosmic.Rd | 7 ++++--- man/scale_cosmic.Rd | 14 ++------------ 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/man/pal_cosmic.Rd b/man/pal_cosmic.Rd index 7bfaa2e..536d193 100644 --- a/man/pal_cosmic.Rd +++ b/man/pal_cosmic.Rd @@ -4,7 +4,8 @@ \alias{pal_cosmic} \title{COSMIC Color Palettes} \usage{ -pal_cosmic(palette = c("hallmarks"), alpha = 1) +pal_cosmic(palette = c("hallmarks", "signature_substitutions"), + alpha = 1) } \arguments{ \item{palette}{Palette type. @@ -21,8 +22,8 @@ Somatic Mutations in Cancers (COSMIC)} } \examples{ library("scales") -show_col(pal_cosmic("hallmark")(10)) -show_col(pal_cosmic("hallmark", alpha = 0.6)(10)) +show_col(pal_cosmic("hallmarks")(10)) +show_col(pal_cosmic("hallmarks", alpha = 0.6)(10)) show_col(pal_cosmic("signature_substitutions")(6)) show_col(pal_cosmic("signature_substitutions", alpha = 0.6)(6)) } diff --git a/man/scale_cosmic.Rd b/man/scale_cosmic.Rd index cdffb87..6cb1ef5 100644 --- a/man/scale_cosmic.Rd +++ b/man/scale_cosmic.Rd @@ -26,9 +26,6 @@ See \code{alpha} in \code{\link[grDevices]{rgb}} for details.} See \code{\link{pal_cosmic}} for details. } \examples{ - -# TODO: change to useing this palette - library("ggplot2") data("diamonds") @@ -38,21 +35,14 @@ ggplot( ) + geom_point(alpha = 0.7) + geom_smooth(method = "loess", alpha = 0.1, size = 1, span = 1) + - theme_dark() + theme( - panel.background = element_rect(fill = "#2D2D2D"), - legend.key = element_rect(fill = "#2D2D2D") - ) + - scale_color_cosmic() + theme_bw() + scale_color_cosmic() ggplot( subset(diamonds, carat > 2.2 & depth > 55 & depth < 70), aes(x = depth, fill = cut) ) + geom_histogram(colour = "black", binwidth = 1, position = "dodge") + - theme_dark() + theme( - panel.background = element_rect(fill = "#2D2D2D") - ) + - scale_fill_cosmic() + theme_bw() + scale_fill_cosmic() } \author{ Nan Xiao <\email{me@nanx.me}> |