From ae825f93d479c15ea2eb687bdcbd08ce9751df03 Mon Sep 17 00:00:00 2001 From: James Azam Date: Tue, 24 Sep 2024 14:07:43 +0100 Subject: [PATCH] Plot distributions with colour instead of line types (#788) * Plot distributions with color instead of line types * Add NEWS item * Use Dark2 palette Co-authored-by: Sebastian Funk * Add reviewer Co-authored-by: Sebastian Funk * Move news item to package section --------- Co-authored-by: Sebastian Funk --- NAMESPACE | 1 + NEWS.md | 1 + R/dist_spec.R | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 0e9622605..f2d0c3cb2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -191,6 +191,7 @@ importFrom(ggplot2,ggsave) importFrom(ggplot2,guide_legend) importFrom(ggplot2,guides) importFrom(ggplot2,labs) +importFrom(ggplot2,scale_color_brewer) importFrom(ggplot2,scale_color_manual) importFrom(ggplot2,scale_x_date) importFrom(ggplot2,scale_y_continuous) diff --git a/NEWS.md b/NEWS.md index 1c9450d90..94400f744 100644 --- a/NEWS.md +++ b/NEWS.md @@ -29,6 +29,7 @@ ## Package changes - `fix_dist()` has been renamed to `fix_parameters()` because it removes the uncertainty in a distribution's parameters. By @sbfnk in #733 and reviewed by @jamesmbaazam. +- `plot.dist_spec` now uses color instead of line types to display pmfs vs cmfs. By @jamesmbaazam in #788 and reviewed by @sbfnk. ## Bug fixes diff --git a/R/dist_spec.R b/R/dist_spec.R index c5a493314..5498481df 100644 --- a/R/dist_spec.R +++ b/R/dist_spec.R @@ -617,6 +617,7 @@ print.dist_spec <- function(x, ...) { #' addition to the probability mass function #' @param ... ignored #' @importFrom ggplot2 aes geom_col geom_step facet_wrap vars theme_bw +#' scale_color_brewer #' @importFrom data.table data.table rbindlist #' @importFrom cli cli_abort #' @export @@ -699,11 +700,12 @@ plot.dist_spec <- function(x, samples = 50L, res = 1, cumulative = TRUE, ...) { # Plot PMF and CDF as facets in the same plot plot <- ggplot( - pmf_data, mapping = aes(x = x, y = p, group = sample, linetype = type) + pmf_data, mapping = aes(x = x, y = p, group = sample, color = type) ) + geom_line() + facet_wrap(vars(distribution)) + labs(x = "x", y = "Probability") + + scale_color_brewer(palette = "Dark2") + theme_bw() if (cumulative) { cmf_data <- pmf_data[,