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 @@ -38,6 +38,8 @@ where the formatting is also better._
bug report in #449.
- Numeric labellers now work on appropriate `x`/`y` variables, even if the
plot type internally coerces it to factor (e.g., `"boxplot"`)
- `type_text()` can now also deal with factor `x`/`y` variables by converting
them to numeric which helps to add text to barplots etc. (#470 @zeileis)


### Internals
Expand Down
2 changes: 2 additions & 0 deletions R/type_text.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ data_text = function(labels, clim = c(0.5, 2.5)) {
stop(msg, call. = FALSE)
}
datapoints$labels = labels
if (is.factor(datapoints$x)) datapoints$x = as.numeric(datapoints$x)
if (is.factor(datapoints$y)) datapoints$y = as.numeric(datapoints$y)

# browser()
bubble = FALSE
Expand Down
68 changes: 68 additions & 0 deletions inst/tinytest/_tinysnapshot/barplot_text_issue469.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions inst/tinytest/test-type_barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ f = function() {
tinyplot(~ cyl, data = mtcars, type = "barplot", xlevels = 3:1)
}
expect_snapshot_plot(f, label = "barplot_xlevels_issue430")

f = function() {
tab = as.data.frame(xtabs(~ cyl, data = mtcars))
tinyplot(Freq ~ cyl, data = tab, type = "barplot")
tinyplot_add(type = "text", labels = tab$Freq, pos = 3, xpd = TRUE)
}
expect_snapshot_plot(f, label = "barplot_text_issue469")