Skip to content

Commit e8b62f6

Browse files
authored
Facets drop 'ordered' class (#5704)
* facets always use unordered factors * add news bullet
1 parent ac19272 commit e8b62f6

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
# ggplot2 (development version)
33

4+
* When facets coerce the faceting variables to factors, the 'ordered' class
5+
is dropped (@teunbrand, #5666).
46
* `update_geom_defaults()` and `update_stat_defaults()` have a reset mechanism
57
when using `new = NULL` and invisible return the previous defaults (#4993).
68
* `coord_map()` and `coord_polar()` throw informative warnings when used

R/facet-grid-.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,9 @@ FacetGrid <- ggproto("FacetGrid", Facet,
325325
# Special case of no faceting
326326
data$PANEL <- NO_PANEL
327327
} else {
328-
facet_vals[] <- lapply(facet_vals[], as.factor)
328+
facet_vals[] <- lapply(facet_vals[], as_unordered_factor)
329329
facet_vals[] <- lapply(facet_vals[], addNA, ifany = TRUE)
330-
layout[] <- lapply(layout[], as.factor)
330+
layout[] <- lapply(layout[], as_unordered_factor)
331331

332332
keys <- join_keys(facet_vals, layout, by = vars)
333333

R/facet-wrap.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ FacetWrap <- ggproto("FacetWrap", Facet,
228228
}
229229

230230
facet_vals <- eval_facets(vars, data, params$.possible_columns)
231-
facet_vals[] <- lapply(facet_vals[], as.factor)
232-
layout[] <- lapply(layout[], as.factor)
231+
facet_vals[] <- lapply(facet_vals[], as_unordered_factor)
232+
layout[] <- lapply(layout[], as_unordered_factor)
233233

234234
missing_facets <- setdiff(names(vars), names(facet_vals))
235235
if (length(missing_facets) > 0) {

R/utilities.R

+6
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,9 @@ deprecate_warn0 <- function(..., user_env = NULL) {
811811
user_env <- user_env %||% getOption("ggplot2_plot_env") %||% caller_env(2)
812812
lifecycle::deprecate_warn(..., user_env = user_env)
813813
}
814+
815+
as_unordered_factor <- function(x) {
816+
x <- as.factor(x)
817+
class(x) <- setdiff(class(x), "ordered")
818+
x
819+
}

0 commit comments

Comments
 (0)