Example jgraph scripts

The unix utility jgraph is the best available tool for massaging data into two-dimensional graphs. The scripts describe the graphs at a fairly low level, however, and some experience is required to get the output you want. In this page, I've collected some jgraph scripts I've written for different purposes.

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

I find it useful to format jgraph scripts carefully, as can be seen in the examples on this page. I also find it useful to override most of the defaults, such as axis length, font, and so on.

In this ``log'' graph (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, data file), several lines are plotted from the one data file.

In this awk-based graph (source, data file, data file), awk is used in a slightly richer way; it filters the data, printing an average every tenth point instead of printing every point.

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

There are two ways to place text on a graph. One is with newstring, as in

newstring x 3.3 y 8.5 fontsize 9 : Upper
Another is with marktype, as in this graph with strings (source), and with horizontal and vertical delimiting regions.

Error bars

A graph with error bars (source, data 1, data 2, data 3, data 4, awk script) and points. Note the shifting of points to left and right to separate out the points shown at each integer level.

Bar graphs

Another useful form of graph is a bar graph (source). As this example shows, generating the bars is slightly tricky: for each bar, it is necessary to choose width and placement. However, the bars follow a simple, regular pattern, so this is easy to do with a script.

A variant of this graph is to place text labels (source) on the x axis.

Yet another variant of this graph is to use long labels (source) that have to be rotated to fit. These can be done, with some difficult, with newstring. The rotation is anti-clockwise, about the centre of the string. Thus, since the intention is to place the right-hand end of the string at a particular point, the location of the middle of each string has to be found individually. (It is not clear why this was done this way, when the vjr directive could have been used.)

A more principled way of doing this is with the generic hash_labels formatting directive, as in this version of the above bargraph (source).

Bar graphs can become very rich, as shown in this complex example. The source was built using a simple bash script using the two input files manybars.data and manybars.in.

Other stuff

It can be useful to add gridlines, but annoying (sometimes) to have them at the major hash marks. They can be easily added as newcurves; for example, use

newcurve pts 0 50 100 50 gray 0.7 linewidth 0.3 marktype none linetype dashed
to add a faint horizontal line at height 50 on a graph with domain [0,100]. While it is tiresome to add a newcurve instruction for every gridline, it is straightforward to generate them with an awk script.

Return to Justin Zobel's home page.

[To the RMIT Home Page]