Skip to content

Provides color palettes used by the Swedish Medical Products Agency (MPA)

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

vrognas/MPAcolors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MPAcolors

The goal of MPAcolors is to provide colors used by the Swedish Medical Products Agency (MPA) in their publications and reports.

The package also provides functions to generate color palettes for use in ggplot2 plots.

Installation

You can install the development version of MPAcolors from GitHub with:

# install.packages("devtools")
devtools::install_github("vrognas/MPAcolors")

Using these colors in plots

Let’s look at some examples to see the various ways these functions can be used to customize colors with ggplot2. Below is a very simple bar chart using the palmerpenguins::penguins data set.

library(MPAcolors)
library(ggplot2)
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

The new mpa_color function can be used to specifically define a color. In the plot below, mpa_color(“mpa_blue”) is the fill argument in the geom_bar layer to make all of the bars that specific shade of mpa_blue

palmerpenguins::penguins |>
  count(species) |> 
  ggplot(aes(x = species, y = n)) +
  geom_bar(stat = "identity", fill = mpa_color("mpa_blue")) +
  labs(title = "The count of each species in the palmerpenguins data set") +
  scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
  theme_linedraw() +
  theme(axis.ticks = element_blank(),
        axis.title = element_blank(),
        panel.grid.major.x = element_blank())

We could also add fill = species to the aes layer (meaning that each species will have its own color) and then use scale_fill_mpa(palette = “complementary”) to automatically apply our “complementary” color palette.

palmerpenguins::penguins |>
  count(species) |> 
  ggplot(aes(x = species, y = n, fill = species)) +
  geom_bar(stat = "identity") +
  scale_fill_mpa(palette = "complementary") +
  labs(title = "The count of each species in the palmerpenguins data set") +
  scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
  theme_linedraw() +
  theme(axis.ticks = element_blank(),
        axis.title = element_blank(),
        legend.position = "none",
        panel.grid.major.x = element_blank())

Or if you want to use the custom colors but not a specific palette, add a scale_fill_manual layer and specify the values using the mpa_color function.

palmerpenguins::penguins |>
  count(species) |> 
  ggplot(aes(x = species, y = n, fill = species)) +
  geom_bar(stat = "identity") +
  scale_fill_manual(values = 
                      unname(c(mpa_color("pink_complement_20","yellow_complement","mpa_blue_60")))) +
  labs(title = "The count of each species in the palmerpenguins data set") +
  scale_y_continuous(expand = expansion(mult = c(0, 0.1))) +
  theme_linedraw() +
  theme(axis.ticks = element_blank(),
        axis.title = element_blank(),
        legend.position = "none",
        panel.grid.major.x = element_blank())

Lastly, below is an example of a continuous color scale, with our scale_color_mpa_c function specifying the palette to be used.

palmerpenguins::penguins |>
  filter(!is.na(sex)) |> 
  ggplot(aes(x = sex, y = body_mass_g, color = bill_depth_mm)) +
  geom_jitter(size = 3, width = 0.3) +
  scale_color_mpa_c(palette = "highlight", direction = -1) +
  labs(
    title = "Bill depth and body mass by sex",
    y = "Body mass (g)",
    color = "Bill depth (mm)"
  ) +
  theme_linedraw() +
  theme(
    axis.ticks = element_blank(),
    axis.title.x = element_blank(),
    panel.grid.major.x = element_blank()
  )

Complementary palette

scales::show_col(mpa_palette("complementary"), cex_label = 2)

Highlight palette

scales::show_col(mpa_palette("highlight"), cex_label = 2)

About

Provides color palettes used by the Swedish Medical Products Agency (MPA)

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages