TeachingDemos (version 2.10)

gp.open: Alpha version functions to send plotting commands to GnuPlot

Description

These functions allow you to open a connection to a gnuplot process, send data and possibly other information to gnuplot for it to plot, then close gnuplot and clean up temporary files and variables. These functions are alpha level at best, use at your own risk.

Usage

gp.open(where='c:/progra~1/GnuPlot/bin/pgnuplot.exe')
gp.close(pipe=gpenv$gp)
gp.send(cmd='replot',pipe=gpenv$gp)
gp.plot(x,y,type='p',add=FALSE, title=deparse(substitute(y)),pipe=gpenv$gp)
gp.splot(x,y,z, add=FALSE, title=deparse(substitute(z)), pipe=gpenv$gp,
  datafile=tempfile())

Arguments

where

Path to GnuPlot Executable

pipe

The pipe object connected to GnuPlot (returned from gp.open), warning: changing this from the default will probably break things

cmd

Text string, the command to be sent verbatim to the GnuPlot process

x

The x coordinates to plot

y

the y coordinates to plot

z

the z coordinates to splot

type

Either 'p' or 'l' for plotting points or lines

add

Logical, should the data be added to the existing plot or start a new plot

title

The title or legend entry

datafile

The file to store the data in for transfer to gnuplot

Value

gp.open returns and invisible copy of the pipe connection object (to pass to other functions, but don't do this because it doesn't work right yet).

The other 3 functions don't return anything meaningful. All functions are run for their side effects.

Details

These functions provide a basic interface to the GnuPlot program (you must have GnuPlot installed (separate install)), gp.open runs GnuPlot and establishes a pipe connection, gp.close sends a quite command to gnuplot and cleans up temporary variables and files, gp.send sends a command to the GnuPlot process verbatim, and gp.plot sends data and commands to the process to create a standard scatterplot or line plot.

References

http://www.gnuplot.info/

See Also

plot

Examples

Run this code
# NOT RUN {
 
# }
# NOT RUN {
x <- 1:10
y <- 3-2*x+x*x+rnorm(10)

gp.open()
gp.plot(x,y)
gp.send('replot 3-2*x+x**2')

tmp <- expand.grid(x=1:10, y=1:10)
tmp <- transform(tmp, z=(x-5)*(y-3))
gp.splot(tmp$x, tmp$y, tmp$z)

gp.close()
 
# }

Run the code above in your browser using DataCamp Workspace