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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tinyplot
Type: Package
Title: Lightweight Extension of the Base R Graphics System
Version: 0.2.1
Version: 0.2.1.99
Date: 2024-08-25
Authors@R:
c(
Expand Down
2 changes: 2 additions & 0 deletions R/tinyplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ tinyplot.default = function(
facet.args[["nrow"]] = attr(facet, "facet_nrow")
}
}
facet_attr = attributes(facet) ## TODO: better solution for restoring facet attributes?

if (is.null(x)) {
## Special catch for rect and segment plots without a specified y-var
Expand Down Expand Up @@ -737,6 +738,7 @@ tinyplot.default = function(
# Note: We're do this up front, so we can make some adjustments to legend cex
# next (if there are facets). But the actual drawing of the facets will only
# come later.
attributes(facet) = facet_attr ## TODO: better solution for restoring facet attributes?
fargs = facet_layout(facet = facet, facet.args = facet.args, add = add)
list2env(fargs, environment())

Expand Down
21 changes: 10 additions & 11 deletions R/type_density.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ tinyplot.density = function(
## override if bg = "by"
if (!is.null(bg) || !is.null(fill)) type = "area"

# catch for facet_grid
if (!is.null(facet)) {
facet_attributes = attributes(facet)
# facet_grid = attr(facet, "facet_grid")
## ensure factor and preserve facet attributes
if (!is.null(facet) && !is.factor(facet)) {
facet_attr = attributes(facet)
facet = factor(facet)
facet_attr[["class"]] <- NULL
for (i in names(facet_attr)) attr(facet, i) <- facet_attr[[i]]
}
facet_attr = attributes(facet) ## TODO: better solution for restoring facet attributes?

if (inherits(x, "density")) {
object = x
Expand Down Expand Up @@ -164,14 +167,10 @@ tinyplot.density = function(
if (is.null(xlab)) xlab = paste0("N = ", object$n, " Bandwidth = ", sprintf("%.4g", object$bw))
if (is.null(main)) main = paste0(paste(object$call, collapse = "(x = "), ")")

# if (!is.null(facet)) attr(facet, "facet_grid") = facet_grid
## facet handling
if (!is.null(facet)) {
if (!is.null(facet_attributes[["levels"]])) {
facet = factor(facet, levels = facet_attributes[["levels"]])
} else {
facet = factor(facet)
}
attr(facet, "facet_grid") = facet_attributes[["facet_grid"]]
facet = factor(facet, levels = facet_attr[["levels"]])
attributes(facet) = facet_attr ## TODO: better solution for restoring facet attributes?
}

tinyplot.default(
Expand Down
Loading