# position: Find or assign the implied position for graphing the levels... In HH: Statistical Analysis and Data Display: Heiberger and Holland

## Description

The default values for plotting a factor `x` are the integers `1:length(levels(x))`. These functions provide a way of specifying alternate plotting locations for the levels.

## Usage

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21``` ```position(x) position(x) <- value ## S3 method for class 'positioned' is.numeric(x, ...) ## S3 method for class 'positioned' as.numeric(x, ...) ## S3 method for class 'positioned' x[..., drop=FALSE] ## S3 method for class 'positioned' is.na(x) as.positioned(x) as.position(x) is.positioned(x) positioned(x, ..., value) ## S3 method for class 'positioned' print(x, ...) ## S3 method for class 'positioned' unique(x, incomparables = FALSE, ...) unpositioned(x, ...) ```

## Arguments

 `x` numeric vector or factor `value` numerical values to be associated with `levels(x)`. The `length(value)` must equal `length(levels(as.factor(x)))`. `...` other arguments. `drop` See `Extract`. `incomparables` See `unique`.

## Value

`position(x) <- value` first forces its argument to be an ordered factor and then assigns the `value` to the `"position"` attribute of the ordered factor. The result is assigned class `"positioned"` and returned.

`position(x)` returns the position values associated with `levels(x)`. If `x` is a positioned factor, then the `"position"` attribute is returned. If `x` is a factor, then the integers `1:length(levels(x))` are returned. For anything else, `as.numeric(x)` is returned.

`as.position(x)` returns a numeric vector the length of the original vector. If `x` inherits from `"factor"`, then the values in the vector are the values in `position(x)` subscripted by the levels of the factor. If `x` is numeric, then `x` itself is returned.

`unpositioned(x)` removes the `"position"` attribute and removes the `"positioned"` value from the the `class` of the object.

## Author(s)

Richard M. Heiberger <rmh@temple.edu>

`panel.interaction2wt`, `factor`.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118``` ```## ordered with character levels defaults to ## integer position of specified levels tmp <- ordered(c("mm","cm","m","m","mm","cm"), levels=c("mm","cm","m")) ## size order tmp as.numeric(tmp) levels(tmp) position(tmp) as.position(tmp) as.positioned(tmp) positioned(tmp) unpositioned(tmp) unique(tmp) ## position is assigned to ordered in specified order tmp <- ordered(c("cm","mm","m","m","mm","cm"), levels=c("mm","cm","m")) ## size order levels(tmp) position(tmp) <- c(-3, -2, 0) ## log10 assigned in size order tmp as.numeric(tmp) levels(tmp) position(tmp) as.position(tmp) as.positioned(tmp) positioned(tmp) unpositioned(tmp) unique(tmp) ## numeric stays numeric tmp <- c(0.010, 0.001, 1.000, 1.000, 0.001, 0.010) tmp as.numeric(tmp) levels(tmp) position(tmp) as.position(tmp) as.positioned(tmp) positioned(tmp) unpositioned(tmp) unique(tmp) ## factor with numeric levels, position is integer position in size order tmp <- factor(c(0.010, 0.001, 1.000, 1.000, 0.001, 0.010)) tmp as.numeric(tmp) levels(tmp) position(tmp) as.position(tmp) as.positioned(tmp) positioned(tmp) unpositioned(tmp) unique(tmp) ## ordered with numeric levels, position is numeric value in size order tmp <- ordered(c(0.010, 0.001, 1.000, 1.000, 0.001, 0.010)) tmp as.numeric(tmp) levels(tmp) position(tmp) as.position(tmp) as.positioned(tmp) positioned(tmp) unpositioned(tmp) unique(tmp) ## factor with numeric levels ## position is assigned in size order tmp <- factor(c(0.010, 0.001, 1.000, 1.000, 0.001, 0.010)) levels(tmp) position(tmp) <- c(-3, -2, 0) ## log10 assigned in size order tmp as.numeric(tmp) levels(tmp) position(tmp) as.position(tmp) as.positioned(tmp) positioned(tmp) unpositioned(tmp) unique(tmp) ## boxplots coded by week tmp <- data.frame(Y=rnorm(40, rep(c(20,25,15,22), 10), 5), week=ordered(rep(1:4, 10))) position(tmp\$week) <- c(1, 2, 4, 8) bwplot(Y ~ week, horizontal=FALSE, scales=list(x=list(limits=c(0,9), at=position(tmp\$week), labels=position(tmp\$week))), data=tmp, panel=panel.bwplot.intermediate.hh) #### You probably don't want to use the next two examples. #### You need to be aware of their behavior. ## ## factor with character levels defaults to ## integer position of sorted levels. ## you probably DON'T want to do this! tmp <- factor(c("cm","mm","m","m","mm","cm")) ## default alphabetic order tmp as.numeric(tmp) levels(tmp) ## you probably DON'T want to do this! position(tmp) ## you probably DON'T want to do this! as.numeric(tmp) ## ## position is assigned to factor in default alphabetic order. ## you probably DON'T want to do this! tmp <- factor(c("cm","mm","m","m","mm","cm")) levels(tmp) position(tmp) <- c(-3, -2, 0) ## assigned in default alphabetic order tmp as.numeric(tmp) levels(tmp) ## you probably DON'T want to do this! position(tmp) ## you probably DON'T want to do this! as.numeric(tmp) ```