Skip to content

Commit

Permalink
Merge pull request #36 from nanxstats/bmj
Browse files Browse the repository at this point in the history
Improve BMJ color palette documentation
  • Loading branch information
nanxstats authored May 20, 2024
2 parents 1df1f09 + 95a11be commit 7e30687
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 16 deletions.
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(pal_aaas)
export(pal_bmj)
export(pal_cosmic)
export(pal_d3)
export(pal_flatui)
Expand All @@ -24,6 +25,7 @@ export(pal_ucscgb)
export(rgb_gsea)
export(rgb_material)
export(scale_color_aaas)
export(scale_color_bmj)
export(scale_color_cosmic)
export(scale_color_d3)
export(scale_color_flatui)
Expand All @@ -45,6 +47,7 @@ export(scale_color_tron)
export(scale_color_uchicago)
export(scale_color_ucscgb)
export(scale_colour_aaas)
export(scale_colour_bmj)
export(scale_colour_cosmic)
export(scale_colour_d3)
export(scale_colour_flatui)
Expand All @@ -66,6 +69,7 @@ export(scale_colour_tron)
export(scale_colour_uchicago)
export(scale_colour_ucscgb)
export(scale_fill_aaas)
export(scale_fill_bmj)
export(scale_fill_cosmic)
export(scale_fill_d3)
export(scale_fill_flatui)
Expand Down
17 changes: 7 additions & 10 deletions R/discrete-bmj.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#' The BMJ Color Palettes
#' BMJ Color Palettes
#'
#' Color palette inspired by plots in
#' \emph{The BMJ}.
#' Color palette from the BMJ living style guide.
#'
#' @param palette Palette type.
#' Currently there is one available option: \code{"default"}
#' (7-color palette).
#' (9-color palette).
#' @param alpha Transparency level, a real number in (0, 1].
#' See \code{alpha} in \code{\link[grDevices]{rgb}} for details.
#'
Expand All @@ -15,12 +14,11 @@
#' @importFrom scales manual_pal
#'
#' @author Hui Chen <\email{huichen@@zju.edu.cn}>
#' Modified from Nan Xiao's code on JAMA pallett
#'
#' @examples
#' library("scales")
#' show_col(pal_bmj("default")(7))
#' show_col(pal_bmj("default", alpha = 0.6)(7))
#' show_col(pal_bmj("default")(9))
#' show_col(pal_bmj("default", alpha = 0.6)(9))
pal_bmj <- function(palette = c("default"), alpha = 1) {
palette <- match.arg(palette)

Expand All @@ -37,7 +35,7 @@ pal_bmj <- function(palette = c("default"), alpha = 1) {
manual_pal(unname(alpha_cols))
}

#' Journal of the American Medical Association Color Scales
#' BMJ Color Scales
#'
#' See \code{\link{pal_bmj}} for details.
#'
Expand All @@ -48,8 +46,7 @@ pal_bmj <- function(palette = c("default"), alpha = 1) {
#'
#' @importFrom ggplot2 discrete_scale
#'
#' @author Nan Xiao <\email{me@@nanx.me}> |
#' <\href{https://nanx.me}{https://nanx.me}>
#' @author Hui Chen <\email{huichen@@zju.edu.cn}>
#'
#' @rdname scale_bmj
#'
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
8 changes: 8 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ p2_jama <- p2 + scale_fill_jama()
grid.arrange(p1_jama, p2_jama, ncol = 2)
```

### BMJ

```{r, ggsci-bmj}
p1_bmj <- p1 + scale_color_bmj()
p2_bmj <- p2 + scale_fill_bmj()
grid.arrange(p1_bmj, p2_bmj, ncol = 2)
```

### JCO

```{r, ggsci-jco}
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ open with `vignette("ggsci")` in R) for a quick-start guide.

<img src="man/figures/README-ggsci-jama-1.png" width="100%" style="display: block; margin: auto;" />

### BMJ

<img src="man/figures/README-ggsci-bmj-1.png" width="100%" style="display: block; margin: auto;" />

### JCO

<img src="man/figures/README-ggsci-jco-1.png" width="100%" style="display: block; margin: auto;" />
Expand Down
6 changes: 6 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ reference:
- scale_color_jama
- scale_colour_jama
- scale_fill_jama
- title: "BMJ"
contents:
- pal_bmj
- scale_color_bmj
- scale_colour_bmj
- scale_fill_bmj
- title: "JCO"
contents:
- pal_jco
Expand Down
15 changes: 9 additions & 6 deletions data-raw/data-generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ ggsci_db$"jama"$"default" <- c(
"Makara" = "#80796B"
)

# Color palette inspired by plots in BMJ (http://technology.bmj.com/living-style-guide/colour.html)
# Color palette from BMJ living style guide
# https://technology.bmj.com/living-style-guide/colour.html
ggsci_db$"bmj"$"default" <- c(
"Blue" = "#2A6EBB",
"Yellow" = "#F0AB00",
"Blue" = "#2A6EBB",
"Yellow" = "#F0AB00",
"Pink" = "#C50084",
"Purple" = "#7D5CC6",
"Purple" = "#7D5CC6",
"Orange" = "#E37222",
"Green" = "#69BE28",
"Aqua" = "#00B2A9",
"Red" = "#CD202C",
"Red" = "#CD202C",
"Grey" = "#747678"
)

Expand Down Expand Up @@ -521,7 +522,9 @@ test_barplot("futurama", "planetexpress")
test_barplot("rickandmorty", "schwifty")
test_barplot("simpsons", "springfield")
test_barplot("gsea", "default")
test_barplot("flatuiau", "intense")
test_barplot("flatui", "default")
test_barplot("flatui", "flattastic")
test_barplot("flatui", "aussie")
test_barplot("material", "red")
test_barplot("material", "pink")
test_barplot("material", "purple")
Expand Down
Binary file added man/figures/README-ggsci-bmj-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions man/pal_bmj.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions man/scale_bmj.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions vignettes/ggsci.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ summarized in the table below.
| JAMA | `scale_color_jama()` | `"default"` | `pal_jama()` |
| | `scale_fill_jama()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| BMJ | `scale_color_bmj()` | `"default"` | `pal_bmj()` |
| | `scale_fill_bmj()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
| JCO | `scale_color_jco()` | `"default"` | `pal_jco()` |
| | `scale_fill_jco()` | | |
+-----------------+------------------------------+--------------------------------+----------------------+
Expand Down Expand Up @@ -215,6 +218,17 @@ p2_jama <- p2 + scale_fill_jama()
grid.arrange(p1_jama, p2_jama, ncol = 2)
```

### BMJ

The BMJ palette is from the
[BMJ living style guide](https://technology.bmj.com/living-style-guide/colour.html):

```{r}
p1_bmj <- p1 + scale_color_bmj()
p2_bmj <- p2 + scale_fill_bmj()
grid.arrange(p1_bmj, p2_bmj, ncol = 2)
```

### JCO

The JCO palette is inspired by the the plots in
Expand Down

0 comments on commit 7e30687

Please sign in to comment.