Skip to content

Commit

Permalink
added palette manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-navarro committed Apr 7, 2024
1 parent 06eaaa4 commit f163b47
Show file tree
Hide file tree
Showing 35 changed files with 150 additions and 48 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: calmr
Title: Canonical Associative Learning Models and their Representations
Version: 0.6.2
Version: 0.6.3
Authors@R:
person("Victor", "Navarro", , "navarrov@cardiff.ac.uk", role = c("aut", "cre", "cph"))
Description: Implementations of canonical associative learning models,
Expand Down Expand Up @@ -78,6 +78,7 @@ Collate:
'calmr_verbosity.R'
'parallel_helpers.R'
'maps.R'
'set_calmr_palette.R'
'class_model.R'
'class_design.R'
'class_result.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export(plot_tbins)
export(plot_trials)
export(rsa)
export(run_experiment)
export(set_calmr_palette)
export(set_reward_parameters)
export(supported_families)
export(supported_models)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# calmr 0.6.3
* Added `set_calmr_palette()` function to control the colour/fill scales used to plot results ([#1](https://github.com/victor-navarro/calmr/issues/1)).

# calmr 0.6.2
* Aggregation of ANCCR data now ignores time; time entries are averaged.
* Added the Temporal Difference model under the name "TD". The model is in an experimental state.
Expand Down
11 changes: 11 additions & 0 deletions R/assertions.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,14 @@ is_design <- function(object) {
length(experiment@design@mapping$unique_nominal_stimuli) > 1
)
}

.assert_valid_palette <- function(palette) {
if (is.null(palette)) {
return("viridis")
}
stopifnot(
"Palette must be one returned by `set_calmr_palette()`" =
palette %in% set_calmr_palette()
)
palette
}
2 changes: 1 addition & 1 deletion R/maps.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ plots_map <- function() {
"elegibilities" = "Elegibility Trace",
"probabilities" = "Response Probability"
)
ggplot2::labs(y = prettynames[output])
prettynames[output]
}

.get_scale_prettyname <- function(output) {
Expand Down
39 changes: 25 additions & 14 deletions R/plotting_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,29 @@ plot_targetted_complex_trials <- function(data, col) {
#' @return A 'ggplot2' scale for colour or fill.
#' @noRd
.calmr_scales <- function(which, ...) {
switch(which,
"colour_d" = {
ggplot2::scale_colour_viridis_d(begin = .1, end = .9, ...)
},
"fill_d" = {
ggplot2::scale_fill_viridis_d(begin = .1, end = .9, ...)
},
"colour_c" = {
ggplot2::scale_colour_viridis_c(begin = .1, end = .9, ...) # nocov
},
"fill_c" = {
ggplot2::scale_fill_viridis_c(begin = .1, end = .9, ...)
}
)
current_scale <- getOption("calmr_palette", default = "viridis")
if (current_scale == "viridis") {
return(switch(which,
"colour_d" = ggplot2::scale_colour_viridis_d(
begin = .1, end = .9, ...
),
"fill_d" = ggplot2::scale_fill_viridis_d(
begin = .1, end = .9, ...
),
"colour_c" = ggplot2::scale_colour_viridis_c(
begin = .1, end = .9, ...
),
"fill_c" = ggplot2::scale_fill_viridis_c(
begin = .1, end = .9, ...
)
))
}
if (current_scale == "hue") {
return(switch(which,
"colour_d" = ggplot2::scale_colour_discrete(...),
"fill_d" = ggplot2::scale_fill_discrete(...),
"colour_c" = ggplot2::scale_colour_continuous(...), # nocov
"fill_c" = ggplot2::scale_fill_continuous(...)
))
}
}
17 changes: 17 additions & 0 deletions R/set_calmr_palette.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#' Get/set the colour/fill palette for plots
#' @param palette A string specifying the available palettes.
#' If NULL, returns available palettes.
#' @return The old palette (invisibly) if palette is not NULL.
#' Otherwise, a character vector of available palettes.
#' @note Changes here do not affect the palette used in graphs.
#' @export

set_calmr_palette <- function(palette = NULL) {
avail_palettes <- c("viridis", "hue")
if (is.null(palette)) {
return(avail_palettes)
}
palette <- .assert_valid_palette(palette)
old <- options("calmr_palette" = palette)
invisible(old)
}
2 changes: 1 addition & 1 deletion docs/404.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/LICENSE.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/calmr_app.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/calmr_basics.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/calmr_fits.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/heidi_similarity.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/articles/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/authors.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions docs/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion docs/news/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ articles:
RW1972: RW1972.html
SM2007: SM2007.html
using_time_models: using_time_models.html
last_built: 2024-04-04T16:26Z
last_built: 2024-04-07T11:45Z
urls:
reference: https://victornavarro.org/calmr/reference
article: https://victornavarro.org/calmr/articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/CalmrFit-class.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/CalmrRSA-class.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/RSA.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/compare_models.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/fit_model.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion docs/reference/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/parse_design.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/pati.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/reference/run_experiment.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/search.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,9 @@
<url>
<loc>https://victornavarro.org/calmr/reference/RW1972.html</loc>
</url>
<url>
<loc>https://victornavarro.org/calmr/reference/set_calmr_palette.html</loc>
</url>
<url>
<loc>https://victornavarro.org/calmr/reference/set_reward_parameters.html</loc>
</url>
Expand Down
2 changes: 1 addition & 1 deletion man/plotting_functions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions man/set_calmr_palette.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/testthat/test-RSA.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ test_that("rsa method works with one model", {
})

test_that("rsa method stops with models outside x", {
expect_error(rsa(comp, comparisons = list("HDI2020" = c("operator_switches"))))
expect_error(rsa(comp,
comparisons = list("HDI2020" = c("operator_switches"))
))
})

test_that("rsa method stops with bad model outputs", {
Expand Down
Loading

0 comments on commit f163b47

Please sign in to comment.