Skip to content

Commit

Permalink
scales_add_defaults: find discrete/date/datetime/continuous scale type
Browse files Browse the repository at this point in the history
Previously, it used trans_type to find the appropriate transformation.
Now it uses scale_type to find the appropriate scale -- and the scale
definitions contain information about which trans to use ("date",
"time", "identity").
  • Loading branch information
wch committed Jun 27, 2012
1 parent 6132fc5 commit 1b3ff24
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions R/scales-.r
Expand Up @@ -77,21 +77,14 @@ scales_add_defaults <- function(scales, data, aesthetics, env) {
if (length(datacols) == 0) return()

for(aes in new_aesthetics) {
disc <- is.discrete(datacols[[aes]])
type <- if (disc) "discrete" else "continuous"
type <- scale_type(datacols[[aes]])
scale_name <- paste("scale", aes, type, sep="_")

# Skip aesthetics with no scales (e.g. group, order, etc)
scale_f <- find_global(scale_name)
if (is.null(scale_f)) next

if (disc) {
args <- list()
} else {
args <- list(trans = trans_type(datacols[[aes]]))
}
scale <- do.call(scale_f, args)
scales$add(scale)

scales$add(scale_f())
}

}
Expand All @@ -112,13 +105,15 @@ find_global <- function(name) {
NULL
}

# Determine default transformation for continuous scales
trans_type <- function(x) {
if (inherits(x, "Date")) {
# Determine default type of a scale
scale_type <- function(x) {
if (is.discrete(x)) {
"discrete"
} else if (inherits(x, "Date")) {
"date"
} else if (inherits(x, "POSIXt")) {
"time"
"datetime"
} else {
"identity"
"continuous"
}
}

0 comments on commit 1b3ff24

Please sign in to comment.