Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branding Updates - 2024 Revamp #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions R/colour_modify.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# Color and Palette Management Functions

#' Add or Modify Colors
#'
#' This function adds new colors or modifies existing ones in the color palette.
#'
#' @param new_colors A data frame containing new color information.
#' @return Updated color data frame.
#' @export
add_or_modify_colors <- function(new_colors) {
# Ensure new_colors has the correct structure
required_cols <- c("colourName", "R", "G", "B", "hex")
if (!all(required_cols %in% names(new_colors))) {
stop("new_colors must contain at least these columns: ", paste(required_cols, collapse = ", "))
}

# Add or update colors
for (i in 1:nrow(new_colors)) {
color_name <- new_colors$colourName[i]
existing_index <- which(sydneyunicolours$colourName == color_name)

if (length(existing_index) > 0) {
# Update existing color
sydneyunicolours[existing_index, names(new_colors)] <- new_colors[i, ]
} else {
# Add new color
new_row <- data.frame(X = max(sydneyunicolours$X) + 1)
new_row[names(new_colors)] <- new_colors[i, ]
sydneyunicolours <- rbind(sydneyunicolours, new_row)
}
}

sydneyunicolours
}

#' Remove Colors
#'
#' This function removes specified colors from the color palette.
#'
#' @param color_names A vector of color names to be removed.
#' @return Updated color data frame.
#' @export
remove_colors <- function(color_names) {
sydneyunicolours <- sydneyunicolours[!sydneyunicolours$colourName %in% color_names, ]
sydneyunicolours
}

#' Add or Modify Palettes
#'
#' This function adds new palette entries or modifies existing ones.
#'
#' @param new_palette_entries A data frame containing new palette information.
#' @return Updated palette data frame.
#' @export
add_or_modify_palettes <- function(new_palette_entries) {
# Ensure new_palette_entries has the correct structure
required_cols <- c("Palette", "Colour", "Role")
if (!all(required_cols %in% names(new_palette_entries))) {
stop("new_palette_entries must contain at least these columns: ", paste(required_cols, collapse = ", "))
}

# Add or update palette entries
for (i in 1:nrow(new_palette_entries)) {
palette_name <- new_palette_entries$Palette[i]
color_name <- new_palette_entries$Colour[i]

existing_index <- which(sydneyunipalettes$Palette == palette_name &
sydneyunipalettes$Colour == color_name)

if (length(existing_index) > 0) {
# Update existing entry
sydneyunipalettes[existing_index, names(new_palette_entries)] <- new_palette_entries[i, ]
} else {
# Add new entry
sydneyunipalettes <- rbind(sydneyunipalettes, new_palette_entries[i, ])
}
}

sydneyunipalettes
}

#' Remove Palette Entries
#'
#' This function removes entire palettes or specific colors from a palette.
#'
#' @param palette_name The name of the palette to modify.
#' @param color_names Optional vector of color names to remove from the palette.
#' @return Updated palette data frame.
#' @export
remove_palette_entries <- function(palette_name, color_names = NULL) {
if (is.null(color_names)) {
# Remove entire palette
sydneyunipalettes <- sydneyunipalettes[sydneyunipalettes$Palette != palette_name, ]
} else {
# Remove specific colors from the palette
sydneyunipalettes <- sydneyunipalettes[!(sydneyunipalettes$Palette == palette_name &
sydneyunipalettes$Colour %in% color_names), ]
}
sydneyunipalettes
}

#' Add or Modify Color (Simple)
#'
#' This function provides a simple way to add or modify a color using just name and hex code.
#'
#' @param color_name The name of the color to add or modify.
#' @param hex_code The hex code of the color (format: "#RRGGBB").
#' @return Updated color data frame.
#' @export
add_or_modify_color_simple <- function(color_name, hex_code) {
# Validate hex code
if (!grepl("^#[0-9A-Fa-f]{6}$", hex_code)) {
stop("Invalid hex code. It should be in the format '#RRGGBB'.")
}

# Convert hex to RGB
rgb_values <- grDevices::col2rgb(hex_code)

# Create new color data
new_color <- data.frame(
colourName = color_name,
R = rgb_values[1],
G = rgb_values[2],
B = rgb_values[3],
hex = hex_code,
stringsAsFactors = FALSE
)

# Add other necessary columns with NA or default values
extra_cols <- setdiff(names(sydneyunicolours), names(new_color))
for (col in extra_cols) {
new_color[[col]] <- NA
}

# Add or update the color
sydneyunicolours <- add_or_modify_colors(new_color)

# Return the updated color data frame
sydneyunicolours
}

# Internal helper function to save data
save_color_data <- function() {
save(sydneyunicolours, sydneyunipalettes, file = "R/sysdata.rda")
}
3 changes: 3 additions & 0 deletions R/define_palettes.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ usyd_cols <- function(...) {
#'
#' @export
usyd_palettes <- list(
`modern` = usyd_cols("Ochre","White","Black","LightGrey","Charcoal"),
`modern_extended` = usyd_cols("Ochre","White","Black","LightGrey","Charcoal","Sandstone","HeritageRose","Navy","Eucalypt","Jacaranda"),
`modern_tertiary` = usyd_cols("Ochre","Charcoal","Sandstone","HeritageRose","Navy","Eucalypt","Jacaranda"),
`primary` = usyd_cols("MasterbrandCharcoal", "MasterbrandOchre", "AccentBlue", "AccentYellow", "AccentGrey"),
`modern_diverging` =usyd_cols("DarkEucalypt","Eucalypt","NeutralGrey","LightOchre","UpdatedOchre"),
`extended` = usyd_cols("MasterbrandCharcoal", "MasterbrandOchre", "AccentBlue", "AccentYellow", "SecondaryDarkGreen",
Expand Down
Binary file modified R/sysdata.rda
Binary file not shown.
15 changes: 12 additions & 3 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ names(usyd_palettes)

```{r palettes_qualitative, echo=TRUE, warnings=FALSE, message=FALSE, fig.align='center', fig.width=5, fig.height=3}

# Modern
util_visualise_pal(usyd_palettes[["modern"]])

# Modern Extended
util_visualise_pal(usyd_palettes[["modern_extended"]])

# Modern Tertiary
util_visualise_pal(usyd_palettes[["modern_tertiary"]])

# Primary
util_visualise_pal(usyd_palettes[["primary"]])

Expand Down Expand Up @@ -124,13 +133,13 @@ Below are some examples of `usydColours` in action.

```{r usage_categorical, echo=TRUE, message=FALSE, warning=FALSE, fig.height=3, fig.align='center'}

# Bar graph with the primary palette
# Bar graph with the tertiary palette
diamonds %>%
filter(price < 1000) %>%
ggplot(aes(price, fill = cut)) +
geom_histogram(colour = "black", position = "dodge", binwidth = 250) +
theme_bw() +
scale_fill_manual(values = usyd_palette("primary"))
scale_fill_manual(values = usyd_palette("modern_tertiary"))

# Density graph with the muted palette
iris %>%
Expand Down Expand Up @@ -204,7 +213,7 @@ ggplot(choropleth, aes(long, lat, group = group)) +
ggtitle("US unemployment rate by county") +
theme(axis.line = element_blank(), axis.text = element_blank(),
axis.ticks = element_blank(), axis.title = element_blank()) +
scale_fill_gradientn(colours = usyd_palette("muted", 100, type = "continuous"))
scale_fill_gradientn(colours = usyd_palette("modern_tertiary", 100, type = "continuous"))

```

Expand Down
68 changes: 52 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
usydColours
================
Jazmin Ozsvar
v2.0.0 Henry Lydecker (Latest)
Q3 2024
v1.2.0 Henry Lydecker
01/05/2022
v1.0.0 Jazmin Ozsvar
04/06/2020

## The University of Sydney colour palettes
Expand Down Expand Up @@ -33,50 +37,72 @@ install_github("Sydney-Informatics-Hub/usydColours")

Below is a list of the currently available palettes.

## [1] "primary" "modern_diverging" "extended"
## [4] "secondary" "pastel" "complementary_ReGr"
## [7] "complementary_ReBl" "bright" "muted"
## [10] "trafficlight" "heatmap" "flametree"
## [13] "jacaranda" "harbour" "sandstone"
## [16] "ochre" "greyscale" "BlGrYe"
## [19] "BlOr" "diverging_blue_red" "diverging_blue_orange"
## [1] "modern" "modern_extended" "modern_tertiary"
Copy link

@edenz93 edenz93 Aug 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like how the new ones are called modern, I also did not realise how much the branding has changed!!

## [4] "primary" "modern_diverging" "extended"
## [7] "secondary" "pastel" "complementary_ReGr"
## [10] "complementary_ReBl" "bright" "muted"
## [13] "trafficlight" "heatmap" "flametree"
## [16] "jacaranda" "harbour" "sandstone"
## [19] "ochre" "greyscale" "BlGrYe"
## [22] "BlOr" "diverging_blue_red" "diverging_blue_orange"

### Qualitative palettes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just being nit picky but maybe centre align all the plots?


``` r
# Modern
util_visualise_pal(usyd_palettes[["modern"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-1.png" style="display: block; margin: auto;" />

``` r
# Modern Extended
util_visualise_pal(usyd_palettes[["modern_extended"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-2.png" style="display: block; margin: auto;" />

``` r
# Modern Tertiary
util_visualise_pal(usyd_palettes[["modern_tertiary"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-3.png" style="display: block; margin: auto;" />

``` r
# Primary
util_visualise_pal(usyd_palettes[["primary"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-1.png" style="display: block; margin: auto;" />
<img src="README_files/figure-gfm/palettes_qualitative-4.png" style="display: block; margin: auto;" />

``` r
# Extended
util_visualise_pal(usyd_palettes[["extended"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-2.png" style="display: block; margin: auto;" />
<img src="README_files/figure-gfm/palettes_qualitative-5.png" style="display: block; margin: auto;" />

``` r
# Secondary
util_visualise_pal(usyd_palettes[["secondary"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-3.png" style="display: block; margin: auto;" />
<img src="README_files/figure-gfm/palettes_qualitative-6.png" style="display: block; margin: auto;" />

``` r
# Pastel
util_visualise_pal(usyd_palettes[["pastel"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-4.png" style="display: block; margin: auto;" />
<img src="README_files/figure-gfm/palettes_qualitative-7.png" style="display: block; margin: auto;" />

``` r
# Bright
util_visualise_pal(usyd_palettes[["bright"]])
```

<img src="README_files/figure-gfm/palettes_qualitative-5.png" style="display: block; margin: auto;" />
<img src="README_files/figure-gfm/palettes_qualitative-8.png" style="display: block; margin: auto;" />

### Sequential palettes

Expand Down Expand Up @@ -180,13 +206,13 @@ Below are some examples of `usydColours` in action.
#### Categorical data

``` r
# Bar graph with the primary palette
# Bar graph with the tertiary palette
diamonds %>%
filter(price < 1000) %>%
ggplot(aes(price, fill = cut)) +
geom_histogram(colour = "black", position = "dodge", binwidth = 250) +
theme_bw() +
scale_fill_manual(values = usyd_palette("primary"))
scale_fill_manual(values = usyd_palette("modern_tertiary"))
```

<img src="README_files/figure-gfm/usage_categorical-1.png" style="display: block; margin: auto;" />
Expand Down Expand Up @@ -272,7 +298,7 @@ ggplot(choropleth, aes(long, lat, group = group)) +
ggtitle("US unemployment rate by county") +
theme(axis.line = element_blank(), axis.text = element_blank(),
axis.ticks = element_blank(), axis.title = element_blank()) +
scale_fill_gradientn(colours = usyd_palette("muted", 100, type = "continuous"))
scale_fill_gradientn(colours = usyd_palette("modern_tertiary", 100, type = "continuous"))
```

<img src="README_files/figure-gfm/usage_continuous2-1.png" style="display: block; margin: auto;" />
Expand Down Expand Up @@ -344,3 +370,13 @@ like to apply them in Photoshop or any other code.
| NeutralGrey | 224 | 224 | 224 | \#E0E0E0 |
| LightOchre | 255 | 173 | 140 | \#FFAD8C |
| UpdatedOchre | 231 | 71 | 38 | \#E74726 |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are UpdatedOchre and Ochre same same but different?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would It be worth consolidating the duplicate colors into one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Yes, consolidating would be a worthy goal.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's like going to the nail salon

Screenshot 2024-08-28 at 9 37 40 AM

| Ochre | 231 | 71 | 38 | \#E74726 |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe have the RGB values and hex code as a text overlay on the swatch plot rather than a separate table down the bottom?

swatchplot-1

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or I quite like how this site has it down below each palette in the main body:

Screenshot 2024-08-28 at 8 53 48 AM

| White | 255 | 255 | 255 | \#FFFFFF |
| Black | 0 | 0 | 0 | \#000000 |
| LightGrey | 230 | 231 | 233 | \#E6E7E9 |
| Charcoal | 66 | 65 | 67 | \#424143 |
| Sandstone | 251 | 238 | 226 | \#FBEEE2 |
| HeritageRose | 218 | 168 | 162 | \#DAA8A2 |
| Navy | 27 | 53 | 94 | \#1B355E |
| Eucalypt | 113 | 164 | 153 | \#71A499 |
| Jacaranda | 143 | 158 | 200 | \#8F9EC8 |
Binary file modified README_files/figure-gfm/palettes_qualitative-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/palettes_qualitative-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/palettes_qualitative-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/palettes_qualitative-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/palettes_qualitative-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/swatchplot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/usage_categorical-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/usage_categorical-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified README_files/figure-gfm/usage_continuous2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Rplots.pdf
Binary file not shown.