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

Updating default color palettes and adding custom_palette() #114

Merged
merged 14 commits into from
Aug 23, 2024

Conversation

shaziaruybal
Copy link
Collaborator

Pull Request

This PR responds to #20 and updates the default color palette to a hopefully nicer one from ggsci. It also fixes a bug (see 8a2d5bb and 193f172).

Additional changes:

  • A simple utility function custom_palette() was created to hopefully aid users to build their own custom palettes, especially if they want to visualise parameters with "multi-country" labels (eg "Guinea, Liberia, Sierra Leone") since the default palette will only work for single-country labels eg ("Guinea").
  • Tests for custom_palette() have also been added

Example usage of custom_palette():

p <- load_epidata("ebola")[["params"]]

# The default palette will only work for individual country labels, i.e. n=7 countries
forest_plot_incubation_period(p, col_by = "population_country")

# Use the custom_palette() to color all country labels, including 'multi-country' labels. In this example there are n=11 labels. 
labels <- c("DRC", "Guinea, Liberia, Sierra Leone", "Liberia, Nigeria", "Sudan", "DRC, Sudan", "Guinea, Sierra Leone", "Nigeria", "Uganda", "Guinea", "Liberia", "Sierra Leone")
colors <- c("indianred", "cornflowerblue", "forestgreen", "goldenrod", "magenta4", "turquoise4","black", "gold4", "skyblue1", "pink3", "darkgrey")

# Create the custom palette
custom_pal <- custom_palette(labels, colors)

# Plot with the custom_pal
forest_plot_incubation_period(p, col_by = "population_country",
                              col_palette = custom_pal)`

# Alternatively, use the function directly
forest_plot_incubation_period(p, col_by = "population_country",
                              col_palette = custom_palette(labels, colors))

Checklist:

  • [NA] I have added new dependencies in DESCRIPTION
  • [NA] I have bumped the version number in DESCRIPTION (I am now working off of an earlier version so didn't update any version numbers)
  • [NA] I have updated the NEWS.md
  • I have added unit tests using testthat
  • I have checked that the package can install locally using devtools::install_local("<path-to-epireview>")
  • I have added documentation where required
  • My documentation includes examples of how to use the function
  • [NA?] If necessary, I have updated priority-pathogens

@shaziaruybal
Copy link
Collaborator Author

@tristan-myles just took a peek at the conflicts, I think the error message may need to also be updated for custom_palette() to be in line with cli_()

@@ -90,11 +90,11 @@ forest_plot <- function(df, facet_by = NA, shape_by = NA, col_by = NA,
## use the palette if provided, otherwise use the default
## as defined in epireview
## if neither is provided, use the default palette
if (!is.na(shp_palette)) {
if (!is.null(shp_palette)) {
p <- p + scale_shape_manual(values = shp_palette, na.value = 4)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@shaziaruybal Can you check that this na.value param is fine? I've added it based on the merge conflicts, but it wasn't in the initial version of develop that you were working on

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tristan-myles and I have checked and we think the na.value param is fine

if (!is.na(col_palette)) {
p <- p + scale_color_manual(values = col_palette, na.value = "gray")
if (!is.null(col_palette)) {
p <- p + scale_color_manual(values = col_palette, na.value = "gray")
Copy link
Collaborator

Choose a reason for hiding this comment

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

@shaziaruybal Same as my previous comment, can you check that this na.value param is fine?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tristan-myles and I have checked and we think the na.value param is fine

Copy link
Collaborator

@tristan-myles tristan-myles left a comment

Choose a reason for hiding this comment

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

In addition to my two comments on the files changed:

  1. devtools::check is failing because load-filter-view-epidata.Rmd no longer compiles due to the changes in forest_plot.R. Could you check the functions used in this vignette. I think you just need to provide custom palettes?
    Additionally, to confirm, is this the expected behaviour when now custom palette is provided?

  2. I've bumped the version to 1.3.4 based on the anticipated merge of Sangeeta's PR, can you just add a brief description of the changes introduced in this PR in the NEWS.md file. A brief one-liner is fine. :)

- Fixes version conflict in DESCRIPTION
@shaziaruybal
Copy link
Collaborator Author

In addition to my two comments on the files changed:

  1. devtools::check is failing because load-filter-view-epidata.Rmd no longer compiles due to the changes in forest_plot.R. Could you check the functions used in this vignette. I think you just need to provide custom palettes?
    Additionally, to confirm, is this the expected behaviour when now custom palette is provided?
  2. I've bumped the version to 1.3.4 based on the anticipated merge of Sangeeta's PR, can you just add a brief description of the changes introduced in this PR in the NEWS.md file. A brief one-liner is fine. :)

we fixed a minor bug when newest version of develop branch was merged and now builds - have added description to NEWS.md

Copy link
Collaborator

@tristan-myles tristan-myles left a comment

Choose a reason for hiding this comment

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

Passes tests and RCMD check passes

@tristan-myles tristan-myles merged commit ef7105b into develop Aug 23, 2024
5 checks passed
@tristan-myles tristan-myles deleted the feature/forest_plot_colors branch August 23, 2024 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants