r - How is jitter determined in ggplot? -
i looking on documentation on jitter in ggplot while making plots, , realized don't understand argument.
it states arguments are:
width: degree of jitter in x direction. defaults 40% of resolution of data.
and
height: degree of jitter in y direction. defaults 40% of resolution of data.
my question is, resolution, , how determined?
also, can override , provide value, in example below use 0.1:
geom_point(position = position_jitter(w = 0.1, h = 0.1))
what units belong 0.1? right assume proportion of resolution?
if @ source first find this:
positionjitter <- proto(position, { objname <- "jitter" adjust <- function(., data) { if (empty(data)) return(data.frame()) check_required_aesthetics(c("x", "y"), names(data), "position_jitter") if (is.null(.$width)) .$width <- resolution(data$x, 0 = false) * 0.4 if (is.null(.$height)) .$height <- resolution(data$y, 0 = false) * 0.4 trans_x <- null trans_y <- null if(.$width > 0) { trans_x <- function(x) jitter(x, amount = .$width) } if(.$height > 0) { trans_y <- function(x) jitter(x, amount = .$height) } transform_position(data, trans_x, trans_y) } })
and wouldn't know it, resolution
exported function (or search sources landing here):
function (x, 0 = true) { if (is.integer(x) || zero_range(range(x, na.rm = true))) return(1) x <- unique(as.numeric(x)) if (zero) { x <- unique(c(0, x)) } min(diff(sort(x))) }
so...there go!
"resolution" in context means "the smallest distance between 2 elements in vector".
this value (40% of resolution) passed on factor
argument jitter
, has it's own little song , dance:
the result, r, r <- x + runif(n, -a, a) n <- length(x) , amount argument (if specified).
let z <- max(x) - min(x) (assuming usual case). amount added either provided positive argument amount or otherwise computed z, follows:
if amount == 0, set <- factor * z/50 (same s).
if amount null (default), set <- factor * d/5 d smallest difference between adjacent unique (apart fuzz) x values.
Comments
Post a Comment