### Install phsstyles Locally Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Install the phsstyles package locally by providing the file path to the zipped repository. This is an alternative if GitHub installation fails due to network security settings. ```r remotes::install_local("/phsstyles-master.zip", upgrade = "never" ) ``` -------------------------------- ### Install phsstyles from GitHub Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Install the phsstyles package from GitHub using the remotes package. Ensure 'upgrade' is set to 'never' to avoid potential issues with package updates. ```r remotes::install_github("Public-Health-Scotland/phsstyles", upgrade = "never" ) ``` -------------------------------- ### Create bar chart with PHS discrete fill scale Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Creates a bar chart and applies a discrete fill scale using the PHS main-blues palette. The legend is hidden in this example. ```r # Create a bar chart filled with colours from PHS main-blues palette library(ggplot2) ggplot(mtcars, aes(x = as.factor(cyl), fill = as.factor(cyl))) + geom_bar() + scale_fill_discrete_phs(palette = "main-blues") + theme(legend.position = "none") ``` -------------------------------- ### Get PHS Color Hex Codes Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Generate hex codes for specific PHS named colors using the phs_colours() function. This is useful for custom color applications in plots. ```r # Generate hex code for those colours phs_colours(c("phs-blue", "phs-purple")) #> [1] "#0078D4" "#3F3685" ``` -------------------------------- ### Access Function Help Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Access the help file for any function within the phsstyles package by prefixing the function name with a question mark (?) in the RStudio console. ```r ?phs_colours ``` -------------------------------- ### Load phsstyles Package Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Load the phsstyles package into your R session using the library() function to access its functionalities. ```r library(phsstyles) ``` -------------------------------- ### Create a ggplot bar chart with PHS colors Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Demonstrates how to create a ggplot bar chart and apply a manual color scale using `phs_colours()` with specified PHS color names. The legend is hidden for a cleaner look. ```r library(ggplot2) phs_bar_chart <- ggplot(mtcars, aes(x = as.factor(cyl), fill = as.factor(cyl))) + geom_bar() + scale_fill_manual(values = phs_colours(c("phs-purple", "phs-magenta", "phs-blue"))) + theme(legend.position = "none") phs_bar_chart ``` -------------------------------- ### Create PHS Styled Bar Chart with ggplot2 Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.html Demonstrates how to create a ggplot bar chart using PHS color palettes via `scale_fill_manual` and `phs_colours()`. ```R library(ggplot2) phs_bar_chart <- ggplot(mtcars, aes(x = as.factor(cyl), fill = as.factor(cyl))) + geom_bar() + scale_fill_manual(values = phs_colours(c("phs-purple", "phs-magenta", "phs-blue"))) + theme(legend.position = "none") phs_bar_chart ``` -------------------------------- ### Create Raster Chart with Reversed PHS Main Purples Palette Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Demonstrates how to create a raster chart using ggplot2 and apply a reversed continuous color scale from the PHS main-purples palette. Ensure the ggplot2 library is loaded. ```r library(ggplot2) ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) + scale_fill_continuous_phs(palette = "main-purples", direction = -1) ``` -------------------------------- ### Create scatter plot with PHS discrete color scale Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Generates a scatter plot using `qplot` and applies a discrete color scale from the PHS main palette. Ensure the grouping variable is a factor. ```r # Create a scatter plot using PHS main colour palette library(ggplot2) df <- mtcars df[, "cyl"] <- as.factor(df[, "cyl"]) qplot(mpg, wt, data = df, colour = cyl) + scale_colour_discrete_phs(palette = "main") ``` -------------------------------- ### Customize Plot Theme with theme_phs Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.html Demonstrates how to override default theme elements, such as removing vertical gridlines and adding horizontal ones, using theme_phs. ```R qplot(mpg, wt, data = mtcars) + theme_phs() + theme(panel.grid.major.x = element_blank(), panel.grid.major.y = element_line(colour = grDevices::rgb(190 / 255, 190 / 255, 190 / 255))) ``` -------------------------------- ### Create scatter plot with PHS continuous color scale Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Generates a scatter plot and applies a continuous color scale using the PHS main-purples palette, combined with the PHS theme. ```r # Create a scatter plot using continuous colours from PHS main-purples palette library(ggplot2) qplot(mpg, wt, data = mtcars, colour = cyl) + scale_colour_continuous_phs(palette = "main-purples") + theme_phs() ``` -------------------------------- ### Apply PHS Theme to ggplot2 Chart Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.html Load the ggplot2 library and apply the custom theme_phs() to a basic plot. This snippet demonstrates the primary way to style charts with PHS aesthetics. ```r library(ggplot2) # Apply PHS theme to a chart qplot(mpg, wt, data = mtcars) + theme_phs() #> Warning: `qplot()` was deprecated in ggplot2 3.4.0. #> This warning is displayed once per session. #> #> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was #> #> generated. ``` -------------------------------- ### Create Raster Chart with PHS Continuous Fill Scale Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.html Use this function to create a raster chart filled with reversed continuous colors from a specified PHS palette. Requires the `ggplot2` library. ```R library(ggplot2) ggplot(faithfuld, aes(waiting, eruptions)) + geom_raster(aes(fill = density)) + scale_fill_continuous_phs(palette = "main-purples", direction = -1) ``` -------------------------------- ### List all available PHS colors Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Use `phs_colours()` to retrieve a named vector of all available PHS color hex codes. This function can also be used to subset specific colors by name. ```r phs_colours() ``` -------------------------------- ### Create Scatter Plot with PHS Main Palette Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.html Use `scale_colour_discrete_phs` to apply the PHS main color palette to a ggplot2 scatter plot. Ensure the `ggplot2` library is loaded and the `cyl` variable is a factor. ```R # Create a scatter plot using PHS main colour palette library(ggplot2) df <- mtcars df[,'cyl'] <- as.factor(df[,'cyl']) qplot(mpg, wt, data = df, colour = cyl) + scale_colour_discrete_phs(palette = "main") ``` -------------------------------- ### Continuous Color Scale with PHS Palette Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.html Use this function to create a scatter plot with continuous colors from the PHS main-purples palette. Requires the ggplot2 library. ```R library(ggplot2) qplot(mpg, wt, data = mtcars, colour = cyl) + scale_colour_continuous_phs(palette = "main-purples") + theme_phs() ``` -------------------------------- ### PHS Discrete Fill Scale Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.html Use this scale to fill bars with colors from the PHS main-blues palette. Ensure the ggplot2 library is loaded. ```R library(ggplot2) ggplot(mtcars, aes(x = as.factor(cyl), fill = as.factor(cyl))) + geom_bar() + scale_fill_discrete_phs(palette = "main-blues") + theme(legend.position = "none") ``` -------------------------------- ### Customize PHS theme in ggplot Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Shows how to further customize the PHS theme by overriding specific elements, such as removing vertical grid lines and adding custom horizontal grid lines. ```r # Overwirte a feature (e.g. remove vertical gridlines and add horizontal ones) qplot(mpg, wt, data = mtcars) + theme_phs() + theme( panel.grid.major.x = element_blank(), panel.grid.major.y = element_line( colour = grDevices::rgb( 190 / 255, 190 / 255, 190 / 255 ) ) ) ``` -------------------------------- ### Apply PHS theme to a ggplot chart Source: https://github.com/public-health-scotland/phsstyles/blob/master/README.md Applies the default PHS theme to a ggplot chart. This function modifies various theme elements to align with PHS branding. ```r library(ggplot2) # Apply PHS theme to a chart qplot(mpg, wt, data = mtcars) + theme_phs() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.