Skip to content

Commit

Permalink
Plot distributions with colour instead of line types (#788)
Browse files Browse the repository at this point in the history
* Plot distributions with color instead of line types

* Add NEWS item

* Use Dark2 palette

Co-authored-by: Sebastian Funk <[email protected]>

* Add reviewer

Co-authored-by: Sebastian Funk <[email protected]>

* Move news item to package section

---------

Co-authored-by: Sebastian Funk <[email protected]>
  • Loading branch information
jamesmbaazam and sbfnk authored Sep 24, 2024
1 parent bea563a commit ae825f9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion R/dist_spec.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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[,
Expand Down

0 comments on commit ae825f9

Please sign in to comment.