stack.for.trellis: Stack a dataframe such that it is ideal for Lattice graphics...

View source: R/stack-for-trellis-function.R

stack.for.trellisR Documentation

Stack a dataframe such that it is ideal for Lattice graphics plotting

Description

Reorganize dataframe in a way needed for trellis plotting using the lattice graphical package. This is more advanced function than make.groups. For example: You conduct two experiments and fit a triple exponental curve to each experiment. In the dataframe with fitting results, you will typically end up with three columns each holding the results of the three individual time constants. This function can reorginize the dataframe such that all time constants are stacked on top of each other (in one single column e.g. called t.const). An additional column (e.g. called components = "slow", "medium", "fast") tells what is what. Initial dataframe: ID t1 t2 t3 A 0.1 5.0 100.4 B 0.2 5.1 102.0

Result after the call stack.for.trellis(df,c("t1","t2","t3"),col.name="t.const",col.name.which="component") ID t.const component A 0.1 fast B 0.2 fast A 5.0 medium B 5.1 medium A 100.4 slow B 102.0 slow

It is now possible to mate a dotplot as follows dotplot(ID~t.const|component,data=df.stacked).

Usage

df.testdata <- data.frame(ID=c("A","B"),t1=c(0.1,0.2),t2=c(5.0,5.1),t3=c(100.4,102.0),junk=c(1,1),junk2=c(3,3))
   stack.for.trellis(df.testdata,c("t1","t2","t3"),col.name="t.const",col.name.which="component",remove.stacked=T,remove.others=T,remove.never="ID")
   stack.for.trellis(df.testdata,c("t1","t2","t3"),col.name="t.const",col.name.which="component",remove.stacked=T,remove.others=T)
   stack.for.trellis(df.testdata,c("t1","t2","t3"),col.name="t.const",col.name.which="component")

Arguments

df

is the input dataframe

vars

is a vector of names of the variables in df to be stacked

col.name

is the name of the column in the new (stacked) data frame with the "real" data

col.name.which

is the name of the column in the new (stacked) data frame where the identifier is put. By default this is simply called "which".

labels

are names of the different identifiers.

remove.stacked:

If TRUE, the columns that were used for the stacking willbe removed in the output.

remove.others:

If TRUE columns that were not used for the stacking will be removed (e.g. junk1 and junk2 in the example above).

remove.never:

Column names that should never be removed regardless of the settings of remove.stacked or remove.others.

Value

A reorgainzed data frame

Author(s)

Claus E. Andersen


claus-e-andersen/clanLattice documentation built on Oct. 14, 2023, 10:41 a.m.