Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ related to plot layering. See "Bug fixes" below.

### Bug fixes

- `type_text()` no longer converts a categorical axis to a numeric one.
(#730 @grantmcdermott)
- Fixed a bug where consecutive plots with (i) logged axes under (ii) a dynamic
theme would error, due to a stale `par("xlog")`/`par("ylog")` state. We now
avoid this by grabbing the log state directly from the top-level `log`
Expand Down
18 changes: 15 additions & 3 deletions R/type_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,26 @@ data_text = function(labels = NULL, labeller = NULL, clim = c(0.5, 2.5)) {
labels = tinylabel(labels, labeller)
}
datapoints$labels = labels
# Collapse a categorical axis to its level positions, keeping the levels as
# the axis labels. (#730)
if (is.factor(datapoints$x)) {
datapoints$x = as.numeric(datapoints$x)
xlvls = levels(datapoints$x)
xlabs = seq_along(xlvls)
names(xlabs) = xlvls
datapoints$x = as.integer(datapoints$x)
} else {
xlabs = NULL
}
if (is.factor(datapoints$y)) {
datapoints$y = as.numeric(datapoints$y)
ylvls = levels(datapoints$y)
ylabs = seq_along(ylvls)
names(ylabs) = ylvls
datapoints$y = as.integer(datapoints$y)
} else {
ylabs = NULL
}

env2env(environment(), settings, "datapoints")
env2env(environment(), settings, c("datapoints", "xlabs", "ylabs"))
}
return(fun)
}
Expand Down
61 changes: 61 additions & 0 deletions inst/tinytest/_tinysnapshot/text_categorical_x.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions inst/tinytest/test-type_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ expect_snapshot_plot(f, label = "text_labels_nse")
expect_error(tinyplot(mpg ~ wt, data = mtcars, type = "text", labels = c("a", "b")))
# top-level `labels` overrides the constructor-level arg
expect_silent(tinyplot(1:3, type = type_text(labels = "x"), labels = c("a", "b", "c")))

# A categorical axis stays categorical (#730)
f = function() {
tinyplot(x = LETTERS[1:2], y = 1:2, type = "text")
}
expect_snapshot_plot(f, label = "text_categorical_x")
Loading