Skip to content

Commit

Permalink
Adding ggplot2 functionality to ggeffects plot() fails when not setti…
Browse files Browse the repository at this point in the history
…ng "terms" (#357)

* Adding ggplot2 functionality to ggeffects plot() fails when not setting "terms"
Fixes #355

* fix
  • Loading branch information
strengejacke authored Jul 31, 2023
1 parent 748e5bf commit a328f60
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: ggeffects
Type: Package
Encoding: UTF-8
Title: Create Tidy Data Frames of Marginal Effects for 'ggplot' from Model Outputs
Version: 1.2.3.8
Version: 1.2.3.9
Authors@R: c(
person("Daniel", "Lüdecke", role = c("aut", "cre"), email = "d.luedecke@uke.de", comment = c(ORCID = "0000-0002-8895-3206")),
person("Frederik", "Aust", role = "ctb", comment = c(ORCID = "0000-0003-4900-788X")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
not work when there were missing data in weight variables (i.e. when the
regression model used weights).

* Fixes issue in `plot()` when no term was specified in the call to `ggpredict()`.

# ggeffects 1.2.3

## General
Expand Down
65 changes: 60 additions & 5 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -963,12 +963,17 @@ plot.ggalleffects <- function(x,
ci.style = c("ribbon", "errorbar", "dash", "dot"),
facets,
add.data = FALSE,
colors = "Set1",
label.data = FALSE,
limit.range = FALSE,
residuals = FALSE,
residuals.line = FALSE,
collapse.group = FALSE,
colors = NULL,
alpha = 0.15,
dodge = 0.25,
use.theme = TRUE,
dot.alpha = 0.5,
jitter = 0.2,
jitter = NULL,
log.y = FALSE,
case = NULL,
show.legend = TRUE,
Expand All @@ -981,15 +986,50 @@ plot.ggalleffects <- function(x,
grid,
one.plot = TRUE,
rawdata,
verbose = TRUE,
...) {

if (!missing(grid)) facets <- grid
if (missing(facets)) facets <- NULL

ci.style <- match.arg(ci.style)

# check alias
if (missing(rawdata)) rawdata <- add.data

if (isTRUE(facets)) {
if (length(x) == 1) {
x <- x[[1]]
graphics::plot(
x,
ci = ci,
ci.style = ci.style,
facets = FALSE,
add.data = rawdata,
label.data = label.data,
limit.range = limit.range,
residuals = residuals,
residuals.line = residuals.line,
collapse.group = collapse.group,
colors = colors,
alpha = alpha,
dodge = dodge,
use.theme = use.theme,
dot.alpha = dot.alpha,
jitter = jitter,
log.y = log.y,
case = case,
show.legend = show.legend,
show.title = show.title,
show.x.title = show.x.title,
show.y.title = show.y.title,
dot.size = dot.size,
line.size = line.size,
connect.lines = connect.lines,
one.plot = one.plot,
verbose = verbose,
...
)
} else if (isTRUE(facets)) {
# merge all effect-data frames into one
dat <- get_complete_df(x)

Expand Down Expand Up @@ -1017,6 +1057,7 @@ plot.ggalleffects <- function(x,
ci.style = ci.style,
facets = TRUE,
add.data = rawdata,
label.data = label.data,
colors = colors,
alpha = alpha,
dodge = dodge,
Expand All @@ -1032,15 +1073,21 @@ plot.ggalleffects <- function(x,
dot.size = dot.size,
line.size = line.size,
connect.lines = connect.lines,
limit.range = limit.range,
residuals = residuals,
residuals.line = residuals.line,
collapse.group = collapse.group,
verbose = verbose,
...
)
} else {
lapply(x, function(.x) {
graphics::plot(
x = .x,
ci = ci,
ci.style = ci.style,
facets = facets,
rawdata = rawdata,
add.data = rawdata,
colors = colors,
alpha = alpha,
dodge = dodge,
Expand All @@ -1054,7 +1101,15 @@ plot.ggalleffects <- function(x,
show.x.title = show.x.title,
show.y.title = show.y.title,
dot.size = dot.size,
line.size = line.size
line.size = line.size,
label.data = label.data,
limit.range = limit.range,
residuals = residuals,
residuals.line = residuals.line,
collapse.group = collapse.group,
connect.lines = connect.lines,
one.plot = one.plot,
verbose = verbose
)
})
}
Expand Down

0 comments on commit a328f60

Please sign in to comment.