Skip to content

Commit e8b479d

Browse files
committed
(temp) test bugfix to brewer pal
1 parent c9a42cd commit e8b479d

File tree

1 file changed

+42
-33
lines changed

1 file changed

+42
-33
lines changed

R/999_plot_palettes.R

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,54 @@
55
# Applies palettes to <ggplot> objects
66
# TODO add proper documentation.
77
apply_palette <- function(ggplot_object, palette_name) {
8-
ggplot_object <- switch(palette_name,
9-
"npg" =
10-
ggplot_object + ggsci::scale_color_npg() + ggsci::scale_fill_npg(),
11-
"aaas" =
12-
ggplot_object + ggsci::scale_color_aaas() + ggsci::scale_fill_aaas(),
13-
"nejm" =
14-
ggplot_object + ggsci::scale_color_nejm() + ggsci::scale_fill_nejm(),
15-
"lancet" =
16-
ggplot_object + ggsci::scale_color_lancet() + ggsci::scale_fill_lancet(),
17-
"jama" =
18-
ggplot_object + ggsci::scale_color_jama() + ggsci::scale_fill_jama(),
19-
"jco" =
20-
ggplot_object + ggsci::scale_color_jco() + ggsci::scale_fill_jco(),
21-
"ucscgb" =
22-
ggplot_object + ggsci::scale_color_ucscgb() + ggsci::scale_fill_ucscgb(),
23-
"d3" =
24-
ggplot_object + ggsci::scale_color_d3() + ggsci::scale_fill_d3(),
25-
"locuszoom" =
26-
ggplot_object + ggsci::scale_color_locuszoom() + ggsci::scale_fill_locuszoom(),
27-
"igv" =
28-
ggplot_object + ggsci::scale_color_igv() + ggsci::scale_fill_igv(),
29-
"cosmic" =
30-
ggplot_object + ggsci::scale_color_cosmic() + ggsci::scale_fill_cosmic(),
31-
"uchicago" =
32-
ggplot_object + ggsci::scale_color_uchicago() + ggsci::scale_fill_uchicago(),
33-
"brewer" =
34-
ggplot_object + ggplot2::scale_color_brewer() + ggplot2::scale_fill_brewer(),
35-
"ordinal" =
36-
ggplot_object + ggplot2::scale_color_ordinal() + ggplot2::scale_fill_ordinal(),
37-
"viridis_d" =
38-
ggplot_object + ggplot2::scale_color_viridis_d() + ggplot2::scale_fill_viridis_d()
8+
ggplot_object <- switch(
9+
palette_name,
10+
"npg" = ggplot_object + ggsci::scale_color_npg() + ggsci::scale_fill_npg(),
11+
"aaas" = ggplot_object +
12+
ggsci::scale_color_aaas() +
13+
ggsci::scale_fill_aaas(),
14+
"nejm" = ggplot_object +
15+
ggsci::scale_color_nejm() +
16+
ggsci::scale_fill_nejm(),
17+
"lancet" = ggplot_object +
18+
ggsci::scale_color_lancet() +
19+
ggsci::scale_fill_lancet(),
20+
"jama" = ggplot_object +
21+
ggsci::scale_color_jama() +
22+
ggsci::scale_fill_jama(),
23+
"jco" = ggplot_object + ggsci::scale_color_jco() + ggsci::scale_fill_jco(),
24+
"ucscgb" = ggplot_object +
25+
ggsci::scale_color_ucscgb() +
26+
ggsci::scale_fill_ucscgb(),
27+
"d3" = ggplot_object + ggsci::scale_color_d3() + ggsci::scale_fill_d3(),
28+
"locuszoom" = ggplot_object +
29+
ggsci::scale_color_locuszoom() +
30+
ggsci::scale_fill_locuszoom(),
31+
"igv" = ggplot_object + ggsci::scale_color_igv() + ggsci::scale_fill_igv(),
32+
"cosmic" = ggplot_object +
33+
ggsci::scale_color_cosmic() +
34+
ggsci::scale_fill_cosmic(),
35+
"uchicago" = ggplot_object +
36+
ggsci::scale_color_uchicago() +
37+
ggsci::scale_fill_uchicago(),
38+
"brewerDark2" = ggplot_object +
39+
ggplot2::scale_color_brewer(palette = "Dark2") +
40+
ggplot2::scale_fill_brewer(palette = "Dark2"),
41+
"ordinal" = ggplot_object +
42+
ggplot2::scale_color_ordinal() +
43+
ggplot2::scale_fill_ordinal(),
44+
"viridis_d" = ggplot_object +
45+
ggplot2::scale_color_viridis_d() +
46+
ggplot2::scale_fill_viridis_d()
3947
)
4048

4149
return(ggplot_object)
4250
}
4351

4452
get_palette_colours <- function(palette_name, num_colours) {
4553
# palette function by name
46-
colours <- switch(palette_name,
54+
colours <- switch(
55+
palette_name,
4756
"npg" = ggsci::pal_npg()(num_colours),
4857
"aaas" = ggsci::pal_aaas()(num_colours),
4958
"nejm" = ggsci::pal_nejm()(num_colours),
@@ -56,7 +65,7 @@ get_palette_colours <- function(palette_name, num_colours) {
5665
"igv" = ggsci::pal_igv()(num_colours),
5766
"cosmic" = ggsci::pal_cosmic()(num_colours),
5867
"uchicago" = ggsci::pal_uchicago()(num_colours),
59-
"brewer" = RColorBrewer::brewer.pal()(num_colours),
68+
"brewerDark2" = RColorBrewer::brewer.pal(name = "Dark2", n = num_colours),
6069
"ordinal" = viridisLite::viridis(n = num_colours, option = "viridis"),
6170
"viridis_d" = viridisLite::viridis(n = num_colours, option = "viridis")
6271
)

0 commit comments

Comments
 (0)