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
9 changes: 7 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ Bugs fixes:

- The `cex` argument should be respected when using `type="bg"`. Thanks to
@rjknell for report #307 and @vincentarelbundock for the fix.

- The `lwd` argument should be passed down to `pt.lwd` for type "p". Sets proper line weight for the border of pch symbols in legend. Report in #319 and fix in #320 by @kscott-1.
- The `lwd` argument is now correctly passed down to `pt.lwd` for type `"p"`,
which sets proper line weight for the border of pch symbols in legend. Report
in #319 and fix in #320 by @kscott-1.
- Passing `x` and/or `y` as character variables now triggers the same default
plot type behaviour as factors, e.g. boxplots. (#323 @grantmcdermott)
- Scatter plots (`type_points()`/`"p"`) now work even if `x` or `y` is a factor
or character variable. (#323 @grantmcdermott)

## 0.3.0

Expand Down
5 changes: 3 additions & 2 deletions R/sanitize.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ sanitize_type = function(type, x, y, dots) {
assert_choice(type, types, null.ok = TRUE)

if (is.null(type)) {
if (!is.null(x) && is.factor(x) && !is.factor(y)) {
if (!is.null(x) && (is.factor(x) || is.character(x)) && !(is.factor(y) || is.character(y))) {
# enforce boxplot type for y ~ factor(x)
type = type_boxplot
} else if (is.factor(y)) {
} else if (is.factor(y) || is.character(y)) {
# enforce spineplot type for factor(y) ~ x
type = type_spineplot
} else {
Expand All @@ -49,6 +49,7 @@ sanitize_type = function(type, x, y, dots) {
"lines" = type_lines,
"lm" = type_lm,
"loess" = type_loess,
"p" = type_points,
"pointrange" = type_pointrange,
"points" = type_points,
"polygon" = type_polygon,
Expand Down
2 changes: 0 additions & 2 deletions R/type_jitter.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ data_jitter = function(factor, amount) {
fun = function(datapoints, ...) {
x = datapoints$x
y = datapoints$y
if (is.character(x)) x = as.factor(x)
if (is.character(y)) y = as.factor(y)
if (is.factor(x)) {
xlvls = levels(x)
xlabs = seq_along(xlvls)
Expand Down
30 changes: 29 additions & 1 deletion R/type_points.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,41 @@
type_points = function() {
out = list(
draw = draw_points(),
data = NULL,
data = data_points(),
name = "p"
)
class(out) = "tinyplot_type"
return(out)
}

data_points = function() {
fun = function(datapoints, ...) {
# catch for factors (we should still be able to "force" plot these with points)
if (is.factor(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)) {
ylvls = levels(datapoints$y)
ylabs = seq_along(ylvls)
names(ylabs) = ylvls
datapoints$y = as.integer(datapoints$y)
} else {
ylabs = NULL
}

out = list(
datapoints = datapoints,
xlabs = xlabs,
ylabs = ylabs
)
return(out)
}
}

draw_points = function() {
fun = function(ix, iy, icol, ibg, ipch, ilwd, cex, ...) {
Expand Down