Example R scripts

The open-source statistical package R is able to produce a variety of fine graphs that can be easily exported into PDF and postscript formats.

This page demonstrates how easily a large variety of graphs can be generated. (Of course, other tools are also available for creating graphs -- here is a page that shows how to generate the same graphs using jgraph.)

Some general things. This is not a basic introduction to R. See

In this ``log'' graph (pdf, source, data file 1, data file 2), a logarithmic scale is used on the y axis. Note some of the features on this graph.

In this multi-line graph (source, pdf, data file), several lines are plotted from the one data file.

In this graph (source, pdf, data file, data file), simple R commands are used to filter the data, and print an average every tenth point instead of printing every point.

A graph with two axes (source, pdf, data) is useful for plotting two curves that have the same domain but different ranges.

Text is placed on this graph (pdf, source) using the text function. The most basic form of the function is

text(x, y, "text")

Error bars

A graph with error bars (source, pdf, data 1, data 2, data 3, data 4) and points. Note

Bar graphs

Another useful form of graph is a bar graph (pdf, source, data).

Tips 'n' tricks

"join"ing two files

f1 <- read.table("data1",col.names=c("word","freq"))
f2 <- read.table("data2",col.names=c("word","length"))

d <- merge(f1,f2,by="word")
d now has three columns word, freq, length
this saves having to use awk as a preprocessor...

Maintained by Andrew Turpin [To the RMIT Home Page]