Togaware DATA MINING
Desktop Survival Guide
by Graham Williams
Google

Bar Chart Displays

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

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

Image rplot-bar-vertical



Copyright © Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
The PDF version is a formatted comprehensive draft book (with over 800 pages).
Brought to you by Togaware. This page generated: Sunday, 22 August 2010