-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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") | ||
} |
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 | ||
|
@@ -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" | ||
## [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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
@@ -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;" /> | ||
|
@@ -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;" /> | ||
|
@@ -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 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are UpdatedOchre and Ochre same same but different? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would It be worth consolidating the duplicate colors into one? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| Ochre | 231 | 71 | 38 | \#E74726 | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 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 | |
There was a problem hiding this comment.
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!!