Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Bar Chart Options

We illustrate some options in drawing bar charts from the lattice package. First a simple plot. We use NO_CONVERSION for r.data_frame so that the data frame retains the column names and for r.barchart so that the barchart can be printed to the device (otherwise it simply returns a data structure of the information).

[width=0.7]rplot-bar-horizontal


library("lattice")
pdf('graphics/rplot-bar-horizontal.pdf')
  dataset <- data.frame(month=c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
                          1, 2, 3, 4),
                        year=c(2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004,
                          2004, 2004, 2004, 2004, 2005, 2005, 2005, 2005),
                        mean=c(3.8, 3.2, 3.4, 3.0, 3.8, 3.2, 3.4, 3.0,
                          3.9, 3.2, 3.4, 3.0, 3.9, 3.2, 3.4, 3.0))
  trellis.par.set(theme=col.whitebg())
  barchart(month ~ mean | year, data=dataset)
dev.off()

http://rattle.togaware.com/code/rplot-bar-horizontal.R

If we add horizontal = False, layout = (1,2) to the call to the r.barchart function, we can rotate the graphics:

[width=0.8]rplot-bar-vertical



Copyright © 2004-2006 [email protected]
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware.