Skip to content

Commit

Permalink
fixes #208
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinsimpson committed Feb 21, 2023
1 parent d43495a commit dddb5a3
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 69 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
@@ -1,6 +1,6 @@
Package: gratia
Version: 0.8.1.7
Date: 2023-02-17
Version: 0.8.1.8
Date: 2023-02-21
Title: Graceful 'ggplot'-Based Graphics and Other Functions for GAMs Fitted Using 'mgcv'
Authors@R: c(person(given = "Gavin L.", family = "Simpson",
email = "ucfagls@gmail.com",
Expand Down Expand Up @@ -32,7 +32,8 @@ Imports:
lifecycle,
pillar,
cli,
nlme
nlme,
ggokabeito
Suggests:
gamm4,
lme4,
Expand Down
6 changes: 4 additions & 2 deletions NAMESPACE
Expand Up @@ -364,6 +364,8 @@ importFrom(dplyr,starts_with)
importFrom(dplyr,summarise)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(ggokabeito,scale_colour_okabe_ito)
importFrom(ggokabeito,scale_fill_okabe_ito)
importFrom(ggplot2,aes)
importFrom(ggplot2,coord_equal)
importFrom(ggplot2,coord_map)
Expand Down Expand Up @@ -393,11 +395,11 @@ importFrom(ggplot2,layer_scales)
importFrom(ggplot2,lims)
importFrom(ggplot2,scale_colour_continuous)
importFrom(ggplot2,scale_colour_discrete)
importFrom(ggplot2,scale_colour_viridis_d)
importFrom(ggplot2,scale_colour_hue)
importFrom(ggplot2,scale_fill_distiller)
importFrom(ggplot2,scale_fill_gradient2)
importFrom(ggplot2,scale_fill_hue)
importFrom(ggplot2,scale_fill_viridis_c)
importFrom(ggplot2,scale_fill_viridis_d)
importFrom(ggplot2,theme)
importFrom(ggplot2,vars)
importFrom(grDevices,nclass.FD)
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
@@ -1,4 +1,4 @@
# gratia 0.8.1.7
# gratia 0.8.1.8

## User visible changes

Expand Down Expand Up @@ -57,6 +57,10 @@
before conversion to a tibble. This makes more sense as it results in more
typical behaviour as the columns of the printed object are doubles.

* Constrained factor smooths (`bs = "sz"`) where the factor is not the first
variable mentioned in the smooth (i.e. `s(x, f, bs = "sz")` for continuous
`x` and factor `f`) are not plottable with `draw()`. #208

# gratia 0.8.1

## User visible changes
Expand Down
28 changes: 22 additions & 6 deletions R/smooth-estimates.R
Expand Up @@ -1529,7 +1529,8 @@

#' @importFrom rlang .data
#' @importFrom ggplot2 ggplot geom_point geom_line expand_limits theme aes
#' labs scale_colour_viridis_d scale_fill_viridis_d
#' labs scale_fill_hue scale_colour_hue
#' @importFrom ggokabeito scale_colour_okabe_ito scale_fill_okabe_ito
#' @keywords internal
#' @noRd
`plot_smooth.sz_factor_smooth` <- function(object,
Expand Down Expand Up @@ -1575,17 +1576,32 @@
return(NULL)
}
} else {
x_var <- variables[2]
fac_var <- variables[1]
fac_var_lab <- variables[1]
# which is the factor?
if (fs[1L]) {
x_var <- variables[2]
fac_var <- fac_var_lab <- variables[1]
} else {
x_var <- variables[1]
fac_var <- fac_var_lab <- variables[2]
}
}

# how many levels? can't have more than 9 for okabeito
n_levs <- nlevels(object[[fac_var]])
if (is.null(discrete_colour)) {
discrete_colour <- scale_colour_viridis_d()
discrete_colour <- if (n_levs > 9L) {
scale_colour_hue()
} else {
scale_colour_okabe_ito()
}
}

if (is.null(discrete_fill)) {
discrete_fill <- scale_fill_viridis_d()
discrete_fill <- if (n_levs > 9L) {
scale_fill_hue()
} else {
scale_fill_okabe_ito()
}
}

## If constant supplied apply it to `est`
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion tests/testthat/test-draw-smooth-estimates.R
Expand Up @@ -124,7 +124,6 @@ test_that("draw.smooth_estimates works for sz factor smooth", {
expect_doppelganger("draw.smooth_estimates sz factor smooth", plt)
})


test_that("draw.smooth_estimates works for sz two factor smooth", {
skip_on_os(os = "win")
skip_on_os(os = "mac")
Expand Down

0 comments on commit dddb5a3

Please sign in to comment.