Programs->R->Graphics Reference
Graphics Reference
Home
  What's New
  Downloads
Programs
  CSS Editor
  TCP/IP
  rInstaller
  R
    Tutorial
    Reference
    Graphics Reference
    Namespaces
  R2
  Java
Publications
  ODBC Browser
  Internet Server

Red Corona
Mail me




R Graphics Reference

The R graphics is not an interactive GUI, it is just a way of displaying graphics, in the same way as the PostScript graphics system. In other words, it only provides an output interface, not an input one.

Note that, like PostScript, the origin is the bottom left corner of the display area (the cyan box), and that the y co-ordinates count up from the bottom. This is true of the R standard graphics as well as the PostScript style graphics.

There are three sections to this reference:

PostScript style graphics (function prefix #ps)

This is a set of functions that is intended to mirror the PostScript graphics syntax as closely as possible. Although I have made an attempt to get this exactly right, there are certain functions that I do not do at the minute, and there may be bugs in it. Anyway, here are the definitions:
  • #ps.newpath: Starts a new path, wiping the current path and subpath.
  • #ps.closepath: Closes the current subpath by returning the current point to the start of it.
  • nx ny #ps.moveto: Sets the current point to nx, ny, and starts a new subpath.
  • nx ny #ps.rmoveto: Moves the current point nx, ny pixels up and across,
  • nx ny #ps.lineto: Draws a line from the current point to nx, ny, then moves it.
  • nx ny #ps.rlineto: Draws a line from the current point to nx, ny pixels above and to the right of it, then moves it.
  • #ps.currentpoint: Puts the current point (in user space) onto the stack as two numeric scalars, the x and y co-ordinates.
  • #ps.stroke: Outlines the current path, then starts a new one. To keep the current path, e.g. if you want to fill the same path, use the sequence #ps.gsave #ps.stroke #ps.grestore.
  • #ps.fill: Closes and fills all subpaths on the current path, including the current subpath. #ps.fill then starts a new path – to keep the current path, e.g. if you want to outline the same path, use the sequence #ps.gsave #ps.fill #ps.grestore.
  • #ps.fillsubpath: Fills the current subpath, starting a new subpath.
  • cv #ps.show: Shows the text cv in the current font at the current point.
  • #ps.showpage: Displays the graphics window.
  • #ps.gsave: Saves the current graphics state on the graphics stack.
  • #ps.grestore: Restores the graphics state on top of the graphics stack.

R standard graphics (function prefix #g)

  • n1 n2 n3 n4 #g.line: Draws a line from n1, n2 to n3, n4.
  • n1 n2 n3 n4 #g.rect: Draws a rectangle between n1, n2 and n3, n4.
  • n1 n2 n3 n4 #g.frect: Draws a rectangle between n1, n2 and n3, n4, then fills it.
  • nv #g.pline: Draws a polyline using nv as a list of x, y, ... etc. pairs.
  • nv #g.fpoly: Fills a polygon using nv as a list of x, y, ... etc. pairs.
  • nv #g.ptick: Draws a polytick set using nv as a list of x, y, x, y ... etc. fours.
  • nv #g.prect: Draws a polyrect set using nv as a list of x, y, x, y ... etc. fours.
  • nv #g.fprect: Fills a polyrect set using nv as a list of x, y, x, y ... etc. fours.
  • #g.display: Displays the graphics window.

Property setters and generic functions

  • nx ny #ps.setdisplaysize or #g.setdisplaysize: Resizes the graphics display so it can accommodate nx by ny points, on the current pixels-per-point conversion ratio (see #ps.setppt).
  • #ps.getdisplaysize or #g.getdisplaysize: Puts the current window size, in points, onto the stack as two numeric scalars.
  • n #ps.setppt or #g.setppt (not implemented yet!): Sets the pixels-per-point ratio to be n pixels to 1 point. This defaults to 1.
  • #ps.getppt or #g.getppt (not implemented yet!): Returns the current pixels-per-point ratio.
  • nx ny #ps.scale or #g.scale: Scales the co-ordinate system.
  • nx ny #ps.translate or #g.translate: Moves the co-ordinate system.
  • n #ps.rotate or #g.rotate: Rotates the co-ordinate system through n degrees anti-clockwise.
    Note that text is not rotated.
  • #ps.resetctm or #g.resetctm: Resets the co-ordinate system.
  • #ps.reset or #g.reset: Blanks the graphics display and resets graphics variables.
  • nr ng nb #ps.setrgbcolour or #g.setcolour: Sets the current colour to have RGB content (nr, ng, nb).
  • nh ns nb #ps.sethsbcolour or #g.sethsbcolour: Sets the current colour to have HSB (hue, saturation, brightness) content (nh, ns, nb).
  • n #ps.setgrey or #g.setgrey: Sets the current colour to have RGB content of 255*n.
  • n1 n2 n3 #ps.setfont or #g.setfont: Sets the current font to be font n1, size n2, and style n3 from Plain, Italic, Bold or BoldItalic (0, 1, 2, or 3).
    The font faces are:
    1. Times
    2. Helvetica/Arial
    3. Courier
    4. "Dialog"
    5. Symbol

Page and site © Richard Smith 2001
Please send any comments to richard@redcorona.com - thank you.
 Top   Home