Analysis of the iris Data

Download (0)

Full text

(1)

Analysis of the iris Data

Created on \Sexpr{date()}

(Notice that the since the Sexpr was bolded, the result is bolded. Don't half-bold the

command, it will throw and error in R since xml and R code would be inter-mixed. This is also true of code chunks, so be careful how you copy and paste.)

<<loadLibs,echo=FALSE,results=hide>>=

# I usually load the libraries first so that any output produced by loading the library does not end up in the document

library(MASS) library(lattice) library(grid) data(iris)

@

To mimic the R documentation of the iris data,

This famous (Fisher's or Anderson's) iris data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for \Sexpr{dim(iris)[1]/3} flowers from each of

\Sexpr{length(levels(iris$Species))} species of iris. The species are

\Sexpr{paste(levels(iris$Species), collapse = ", ")}.

I like lists (not really). Here is a bulleted list of the species:

<<showOutputList,echo=FALSE,results=xml>>=

odfItemize(levels(iris$Species))

@

(2)

We can make a fancy plot of the data using lattice and insert that into the document.

<<irisSplom,echo=FALSE,results=hide, fig = TRUE>>=

trellis.par.set(col.whitebg(), warn = FALSE) out <- splom(iris[,-5],

groups = iris$Species, pscales = 0,

auto.key = list(columns = 3)) print(out)

@

We can also create a table of the correlation matrix for the virginica species:

<<corrTable,echo=FALSE,results=xml>>=

odfTable(

cor(iris[iris$Species == "virginica",-5]), digits = 3)

@

or show the means (ignoring species):

<<meanTable,echo=FALSE,results=xml>>=

irisMeans <- as.data.frame(lapply(iris[,-5], mean)) odfTable(

irisMeans,

useRowNames = FALSE, digits = 3)

@

Here is an example of changing the formatting within a table. Let's make the font red for the minimum mean value:

<<meanTable2,echo=FALSE,results=xml>>=

# get the styles that would be used

newStyles <- tableStyles(irisMeans, useRowNames = FALSE ,header = names(irisMeans))

# change the minimum mean cell text style. To see the list # of available styles, use getStyleDefs()

newStyles$text[,which.min(irisMeans)] <- "ArialHighlight"

odfTable(

irisMeans,

useRowNames = FALSE, digits = 3,

styles = newStyles)

@

To process this file, you might use:

library(odfWeave)

odfWeave("/path/to/simple.odt", "/path/to/output.odt")

(3)

and that produces the final odt file.

The following R packages were loaded when this analysis was run:

<<pkgList,echo=FALSE,results=xml>>=

odfTable(pkgVersions(type = "matrix"))

@

Figure

Updating...

References

Related subjects :