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

fix issues associated with apply_theme() function #411

Merged
merged 10 commits into from
Jun 21, 2022
Merged

Conversation

SHAESEN2
Copy link
Collaborator

@SHAESEN2 SHAESEN2 commented Jun 16, 2022

What changes are proposed in this pull request?
Ensure that only the strata present in the theme are displayed.
Other strata are greyed out and legend title is aligned with theme.

Which files are involved in this pull request and what changes were made?

Did you include unit tests for the proposed change/bug fix (https://testthat.r-lib.org/)?
Pending

If there is an GitHub issue associated with this pull request, please provide link.
#388

Checklist for PR reviewer

  • PR branch has pulled the most recent updates from main branch. Ensure the pull request branch and your local version match and both have the latest updates from the main branch.
  • If a new function was added, function should be included in _pkgdown.yml
  • If a bug was fixed, a unit test was added for the bug check
  • Run pkgdown::build_site(). Check the R console for errors, and review the rendered website.
  • Code coverage is suitable for any new functions/features. Review coverage with withr::with_envvar(new = c("NOT_CRAN" = "true"), covr::report()). Before you run, begin a fresh R session without any packages loaded.
  • R CMD Check runs without errors, warnings, and notes
  • usethis::use_spell_check() runs with no spelling errors in documentation
  • Has NEWS.md been updated with the changes from this pull request under the heading indicating the latest version. If there is an issue associated with the pull request, reference it in parentheses at the end update (see NEWS.md for examples).
  • Has the version number been incremented using usethis::use_version(which = "dev")
  • Has the README been knitted before merging to ensure each PR has the most up-to-date readme?
  • Approve Pull Request
  • Merge the PR. Please use "Squash and merge".

@ddsjoberg
Copy link
Collaborator

@SHAESEN2 i think i can review later tonight. in the meantime, the R CMD Checks are not passing. Do you want to take a look before it's reviewed?

@bailliem
Copy link
Collaborator

There is an error being thrown in the Styling_KM_Plots.Rmd vignette running the chunk on line 135

lung_suvival_object %>%
  visR::visr() %>%
  apply_theme()

Error in apply_theme(.) : object 'skipcolor' not found
2. apply_theme(.)

  1. lung_suvival_object %>% visR::visr() %>% apply_theme()

R/apply_theme.R Outdated Show resolved Hide resolved
@bailliem
Copy link
Collaborator

bailliem commented Jun 16, 2022

There is an error being thrown in the Styling_KM_Plots.Rmd vignette running the chunk on line 135

lung_suvival_object %>%
  visR::visr() %>%
  apply_theme()

Error in apply_theme(.) : object 'skipcolor' not found 2. apply_theme(.)

  1. lung_suvival_object %>% visR::visr() %>% apply_theme()

Ok. If I understand the example its apply an empty theme expecting to revert to the default theme. I'm not sure the example makes a lot of sense. Why would you apply_theme() that is null. Maybe the "fix" here is a warning if no user supplied theme is provided as an arguement.

@SHAESEN2
Copy link
Collaborator Author

There is an error being thrown in the Styling_KM_Plots.Rmd vignette running the chunk on line 135

lung_suvival_object %>%
  visR::visr() %>%
  apply_theme()

Error in apply_theme(.) : object 'skipcolor' not found 2. apply_theme(.)

  1. lung_suvival_object %>% visR::visr() %>% apply_theme()

Ok. If I understand the example its apply an empty theme expecting to revert to the default theme. I'm not sure the example makes a lot of sense. Why would you apply_theme() that is null. Maybe the "fix" here is a warning if no user supplied theme is provided as an arguement.

It is to be able to apply sensible defaults as per good visualization practices. However I feel that we should implement them directly rather than making this complex function.

@SHAESEN2
Copy link
Collaborator Author

I think we should add experimental to the function + documentation is still pending

@bailliem
Copy link
Collaborator

I think we should add experimental to the function + documentation is still pending

Agree. This seems like a nice to have for now.

@timtreis timtreis changed the title fix issues associated with this function fix issues associated with apply_theme() function Jun 17, 2022
@timtreis
Copy link
Collaborator

timtreis commented Jun 17, 2022

I added a test that covers the behaviour when not enough colours are given and "grey50" is substituted. I'll let Codecov tell me if there's more untested behaviour, but other than that it looks good!

Edit: Now testing for two more use-cases you covered:

a) Use visR palette when theme has no info on strata used in plot (-> had to set skipcolordef to FALSE)
b) Use ggplot palette when strata has more levels than the visR palette elements

@timtreis
Copy link
Collaborator

timtreis commented Jun 17, 2022

image

I think this warning can never be triggered because the required situation (more colours than in the visR palette) is caught here and the else if (!skipcolordef) is never entered.

image

Hey Tim,

I had one situation for which I needed to write that code:

## strata not present but there are too many compared to colors defined
survobj<-
survival::lung %>%
  dplyr::mutate(sex = as.factor(ifelse(sex == 1, "Male", "Female")))  %>%
  dplyr::mutate(status = status - 1) %>%
  dplyr::rename(Age = "age", Sex = "sex", Status = "status", Days = "time")  %>%
  visR::estimate_KM(strata = c("Age", "pat.karno"), CNSR = "Status", AVAL = "Days")

(gg<-survobj%>%
  visR::visr()) %>%
 apply_theme(theme)

@SHAESEN2
Copy link
Collaborator Author

I added a test that covers the behaviour when not enough colours are given and "grey50" is substituted. I'll let Codecov tell me if there's more untested behaviour, but other than that it looks good!

Edit: Now testing for two more use-cases you covered:

a) Use visR palette when theme has no info on strata used in plot (-> had to set skipcolordef to FALSE) b) Use ggplot palette when strata has more levels than the visR palette elements

Thanks for taking the time!!! I'll go through the testing and let you review it once again.

@SHAESEN2
Copy link
Collaborator Author

PR should be finalized. Can someone review?

Copy link
Collaborator

@bailliem bailliem left a comment

Choose a reason for hiding this comment

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

Looks good - I'll push a couple of minor changes to the document strings then merge the PR

R/apply_theme.R Outdated Show resolved Hide resolved
R/define_theme.R Outdated Show resolved Hide resolved
Move lifecycle badges to under description
Add questioning badge to tabelone
@bailliem bailliem merged commit a5bc3da into develop Jun 21, 2022
@bailliem bailliem deleted the bugfix/apply_theme branch June 21, 2022 14:31
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.

4 participants