Learn R Programming

sparkTable (version 0.1.3)

sparkTable_Config: Create meta objects which are later to be used as input-objects for the plot-function.

Description

Generation of a meta-object which can be used by the print.sparkTable-function. Tis object also contains the properties of the plots.

Usage

sparkTable_Config(df, groups, groupVar, vars, typeNumeric, typePlot, output)

Arguments

df
a data.frame or matrix of input-data
groups
which characteristics of the grouping variable should be used
groupVar
variable name of a grouping-variable
vars
variable names of variables to be plotted
typeNumeric
list or vector of the same length as the number of variables used, each list element can be a vector or NULL,defines the number put into the table (see overview in details)
typePlot
vector or list either "line", "box" or "bar"
output
output format, currently "html" and "eps" are possible

Value

  • Returns an object of class meta including $metaData and metaInfo
  • metaDataList of information and properties of every single graphic, for details look at the spark_init function
  • metaInfoList of information about the output properties, chosen variables, plot type, groups. If the output is "eps" it contains filenames and the latex code. If the output is "html" it contains the html-header and the html-table

Details

typeNumeric can be:

max

min

mean

last

ind1--ind2 : e.g. 1--10 or 10--100

indexN: eg index1 gives the first value

... in principle every function that takes a vector and returns a single value (median, quantile,......)

See Also

print.sparkTable, setPara, sparkTable_Config, spark, spark_init, sparkHTML,, sparkEPS

Examples

Run this code
# This function produces an artificial data set of N time units

genDF <- function(N) {
	groups <- c("AT","DE","CH","UK","IT")
	nrRows <- N*length(groups)
	df <- data.frame(
			time=rep(1:N, length(groups)), 
			groups=rep(groups, each=N),
			V1=round(rnorm(nrRows, 25, 25),2),
			V2=round(rnorm(nrRows, 125, 55),2),
			V3=round(rnorm(nrRows, 100, 15),2),
			V4=round(rnorm(nrRows, 150, 65),2),
			V5=round(rnorm(nrRows, 40, 85),2)
	)
	df
}

# generate a data.frame
df <- genDF(20)

# creating EPS output:

meta <- sparkTable_Config(df, groups=c("AT","UK"), 
		groupVar="groups", 
		vars=c("V1","V2","V5"), 
		typeNumeric="mean", 
		typePlot="box",
		output="eps")

# this meta object can now be used to generate an EPS-output in R
eps.text <- print(meta, outdir="examples")

# creating HTML file

meta <- sparkTable_Config(df, groups=c("AT","UK","IT"), 
		groupVar="groups", 
		vars=c("V1","V2","V5"), 
		typeNumeric=list(c("mean","1--3","max","4--5","last"),c("mean","1--3","max"),c("mean","1--3","max"))
		, 
		typePlot=list(c("line","box"),"line","line"),
		output="html")

obj <- print(meta,outdir="examples",outfile="test.html")

### production index
data(dat)
pi_jahr <- dat[1:4,]
pi_monat <- dat[6:nrow(dat),]
transform_for_meta <- function(x,time="row",vars=NULL){
  if(time!="row"){
    x <- t(x)                
  }
  if(!is.null(vars)){
    x <- x[,vars]    
  }
  gr <- vector()
  val <- vector()
  for(i in 1:ncol(x)){
    gr <- c(gr,rep(names(x)[i],nrow(x)))
    val <- c(val,x[,i]) 
  }
  data.frame(group=gr,values=val,stringsAsFactors=FALSE)
}
pi_j2 <- transform_for_meta(pi_jahr)
pi_m2 <- transform_for_meta(pi_monat)
j <- vector()
for(i in 6:20){
  j <- c(j,paste(rep(1990+i,12),1:12,sep="-"))
}
pi_m2$values2 <- pi_m2$values
meta <- sparkTable_Config(df=pi_m2,groups=unique(pi_m2[,1]),groupVar=names(pi_m2)[1],
    vars=names(pi_m2)[2:3], 
    typeNumeric=list(NA,c("51--62"))
    , 
    typePlot=list("line",NA),
    output="html")
meta$metaData <- setPara(meta$metaData, "ch", 25,col=1)
obj <- print(meta,outfile="test.html",outdir="examples")

Run the code above in your browser using DataLab