Skip to content

Commit

Permalink
Allow user-specified point shapes in plot_coefs
Browse files Browse the repository at this point in the history
Relates to #71
  • Loading branch information
jacob-long committed Apr 8, 2022
1 parent f5a8738 commit 812ce0a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ incorrectly in previous versions of `jtools`. This has been corrected. Thanks
to Rebecca Andridge for noticing this. (#89)
* `wtd.sd()` now gives correct results when data is missing in `x` but not in
the weights. Thanks to Klaus Langohr for reporting the issue.
* Users may now choose their own points in `plot_coefs()` and `plot_summs()`
by passing a vector of shapes to the `point.shape` argument. (#71)

# jtools 2.1.4

Expand Down
19 changes: 15 additions & 4 deletions R/plot_coefs.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
#' also moved to 1 instead of 0.
#' @param point.shape When using multiple models, should each model's point
#' estimates use a different point shape to visually differentiate each
#' model from the others? Default is TRUE.
#' model from the others? Default is TRUE. You may also pass a vector of
#' shapes to specify shapes yourself.
#' @param point.size Change the size of the points. Default is 3.
#' @param legend.title What should the title for the legend be? Default is
#' "Model", but you can specify it here since it is rather difficult to
Expand Down Expand Up @@ -141,7 +142,7 @@ plot_summs <- function(..., ci_level = .95, model.names = NULL, coefs = NULL,
inner_ci_level = inner_ci_level, colors = list(colors),
plot.distributions = plot.distributions,
rescale.distributions = rescale.distributions, exp = exp,
point.shape = point.shape, point.size = point.size,
point.shape = list(point.shape), point.size = point.size,
legend.title = legend.title,
groups = groups, facet.rows = facet.rows,
facet.cols = facet.cols, facet.label.pos = facet.label.pos,
Expand Down Expand Up @@ -352,11 +353,21 @@ plot_coefs <- function(..., ci_level = .95, inner_ci_level = NULL,

# To set the shape aesthetic, I prefer the points that can be filled. But
# there are only 6 such shapes, so I need to check how many models there are.
if (point.shape == TRUE) {
if (length(point.shape) == 1 && point.shape == TRUE) {
oshapes <- c(21:25, 15:18, 3, 4, 8)
shapes <- oshapes[seq_len(n_models)]
} else if (point.shape == FALSE) {
} else if (length(point.shape) == 1 && is.logical(point.shape[1]) &
point.shape[1] == FALSE) {
shapes <- rep(21, times = n_models)
} else {
if (length(point.shape) != n_models & length(point.shape) != 1) {
stop_wrap("You must provide the same number of point shapes as the
number of models.")
} else if (length(point.shape) == 1) {
shapes <- rep(point.shape, times = n_models)
} else {
shapes <- point.shape
}
}

p <- p +
Expand Down
3 changes: 2 additions & 1 deletion man/plot_summs.Rd

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

0 comments on commit 812ce0a

Please sign in to comment.