Analysis of the iris Data

Download (0)

Full text


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.)


# 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:





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:



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


or show the means (ignoring species):


irisMeans <-[,-5], mean)) odfTable(


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:


# 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"



useRowNames = FALSE, digits = 3,

styles = newStyles)


To process this file, you might use:


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


and that produces the final odt file.

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


odfTable(pkgVersions(type = "matrix"))





Related subjects :