Skip to content

Commit

Permalink
Merge branch 'issue-307': closes #307
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinsimpson committed Aug 10, 2024
2 parents 593cb88 + c00ddd9 commit 92be27f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
8 changes: 7 additions & 1 deletion R/draw-gam.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
#' generated for tile centres without respect to the spacing of those tiles.
#' @param wrap logical; wrap plots as a patchwork? If \code{FALSE}, a list of
#' ggplot objects is returned, 1 per term plotted.
#' @param caption logical; show the smooth type in the caption of each plot?
#' @param envir an environment to look up the data within.
#' @param ... additional arguments passed to [patchwork::wrap_plots()].
#'
Expand Down Expand Up @@ -200,12 +201,16 @@
default_crs = NULL,
lims_method = "cross",
wrap = TRUE,
caption = TRUE,
envir = environment(formula(object)),
...
) {
# fixed or free?
# fixed or free scale?
scales <- match.arg(scales)

# adding a caption?
caption <- as.logical(caption)

# fix up default scales
# if (is.null(discrete_colour)) {
# discrete_colour <- scale_colour_discrete()
Expand Down Expand Up @@ -392,6 +397,7 @@
default_crs = default_crs,
lims_method = lims_method,
tensor_term_order = tensor_term_order,
caption = caption,
... # FIXME: temporary fix to allow captions to be suppressed-ish
)
} # end stuff for smooths...
Expand Down
52 changes: 41 additions & 11 deletions R/smooth-estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@
crs = NULL,
default_crs = NULL,
lims_method = "cross",
caption = TRUE,
...) {
# add confidence intervals if they don't already exist
if (!all(c(".lower_ci", ".upper_ci") %in% names(object))) {
Expand Down Expand Up @@ -1081,7 +1082,8 @@
crs = crs,
default_crs = default_crs,
lims_method = lims_method,
tensor_term_order = tensor_term_order, # pass on tensor order info
tensor_term_order = tensor_term_order, # pass on tensor order info,
caption = caption,
...
)

Expand Down Expand Up @@ -1114,6 +1116,7 @@
default_crs = NULL,
lims_method = "cross",
tensor_term_order = NULL,
caption = NULL,
...) {
sm_vars <- tensor_term_order[[unique(object$.smooth)]]
if (is.null(sm_vars)) {
Expand Down Expand Up @@ -1272,6 +1275,7 @@
crs = crs,
default_crs = default_crs,
lims_method = lims_method,
caption = caption,
...
)
}
Expand Down Expand Up @@ -1448,8 +1452,11 @@
as.character(unique(object$.smooth))
)
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Basis:", object[[".type"]])
} else {
caption <- NULL
}
if (all(!is.na(object[[".by"]]))) {
if (grouped_by) {
Expand Down Expand Up @@ -1574,8 +1581,11 @@
if (is.null(title)) {
title <- unique(object[[".smooth"]])
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Basis:", object[[".type"]])
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down Expand Up @@ -1716,8 +1726,11 @@
if (is.null(title)) {
title <- unique(object[[".smooth"]])
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Facets:", variables[3], "; Basis:", object[[".type"]])
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down Expand Up @@ -1872,12 +1885,15 @@
if (is.null(title)) {
title <- unique(object[[".smooth"]])
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste(
"Facet rows:", variables[3],
"; columns:", variables[4],
"; Basis:", object[[".type"]]
)
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down Expand Up @@ -2011,8 +2027,11 @@
if (is.null(title)) {
title <- unique(object$.smooth) # variables
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Basis:", object[[".type"]])
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down Expand Up @@ -2106,8 +2125,11 @@
if (is.null(title)) {
title <- unique(object[[".smooth"]])
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Basis:", object[[".type"]])
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down Expand Up @@ -2332,8 +2354,11 @@
if (is.null(title)) {
title <- unique(object[[".smooth"]])
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Basis:", object[[".type"]])
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down Expand Up @@ -2487,9 +2512,11 @@
if (is.null(title)) {
title <- unique(object[[".smooth"]])
}

if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Basis:", object[[".type"]])
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down Expand Up @@ -2628,8 +2655,11 @@
if (is.null(title)) {
title <- unique(object[[".smooth"]])
}
if (is.null(caption)) {
# add the basis via caption if caption is TRUE or NULL
if ((is.logical(caption) && isTRUE(caption)) || is.null(caption)) {
caption <- paste("Basis:", object[[".type"]])
} else {
caption <- NULL
}

if (all(!is.na(object[[".by"]]))) {
Expand Down
3 changes: 3 additions & 0 deletions man/draw.gam.Rd

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

3 changes: 3 additions & 0 deletions man/draw.smooth_estimates.Rd

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

0 comments on commit 92be27f

Please sign in to comment.