<CRANTaskView>

  <name>Graphics</name>
  <topic>Graphic Displays &amp; Dynamic Graphics &amp; Graphic Devices &amp; Visualization </topic>
  <maintainer email="nikko@hailmail.net">Nicholas Lewin-Koh</maintainer>
  <version>2015-01-07</version>
  
  <info>
    <p>R is rich with facilities for creating and developing interesting graphics.
    Base R contains functionality for many plot types including coplots, 
    mosaic plots, biplots, and the list goes on. There are devices such as 
    postscript, png, jpeg and pdf for outputting graphics as well as device
    drivers for all platforms running R. <pkg>lattice</pkg> and 
    grid are supplied with R's recommended packages and are 
    included in every binary distribution. <pkg>lattice</pkg> is an R 
    implementation of William Cleveland's trellis graphics, while grid 
    defines a much more flexible graphics environment than the base R graphics.</p>
    
    <p>R's base graphics are implemented in the same way as in the S3
    system developed by Becker, Chambers, and Wilks. There is a static
    device, which is treated as a static canvas and objects are drawn on
    the device through R plotting commands. The device has a set of global
    parameters such as margins and layouts which can be manipulated by the
    user using <code>par()</code> commands. The R graphics engine does not maintain a
    user visible graphics list, and there is no system of double
    buffering, so objects cannot be easily edited without redrawing a whole
    plot. This situation may change in R 2.7.x, where developers are working on double 
    buffering for R devices. Even so, the base R graphics can produce many plots with
    extremely fine graphics in many specialized instances.</p> 

    <p>One can quickly run into trouble with R's base graphic system if
    one wants to design complex layouts where scaling is maintained
    properly on resizing, nested graphs are desired or more interactivity
    is needed. grid was designed by Paul Murrell to overcome
    some of these limitations and as a result packages like
    <pkg>lattice</pkg>, <pkg>ggplot2</pkg>, <pkg>vcd</pkg> or <pkg>hexbin</pkg> use
    grid for the underlying primitives. When using plots designed with
    grid one needs to keep in mind that grid is based on a system of
    viewports and graphic objects. To add objects one needs to use grid
    commands, e.g., <code>grid.polygon()</code> rather than <code>polygon()</code>. Also grid
    maintains a stack of viewports from the device and one needs to make
    sure the desired viewport is at the top of the stack. There is a great
    deal of explanatory documentation included with grid as
    vignettes.</p>   


    <p>The graphics packages in R can be organized roughly into the following 
    topics, which range from the more user oriented at the top to the more developer 
    oriented at the bottom. The categories are not mutually exclusive but are for the 
    convenience of presentation:</p>
    <ul>

      <li><i>Plotting</i>:
          Enhancements for specialized plots can be found in <pkg>plotrix</pkg>,
	  for polar plotting, <pkg>vcd</pkg> for categorical data, <pkg>hexbin</pkg>
	  for hexagon binning, <pkg>gclus</pkg> for ordering plots and 
          <pkg>gplots</pkg>
	  for some plotting enhancements. Some specialized graphs, like Chernoff faces 
          are implemented in <pkg>aplpack</pkg>, which also has a nice implementation 
          of Tukey's bag plot.
          
          For 3D plots <pkg>lattice</pkg>,
	  <pkg>scatterplot3d</pkg> and <pkg>misc3d</pkg> provide a selection of plots for
	  different kinds of 3D plotting. <pkg>scatterplot3d</pkg> is based on R's base
	  graphics system, while <pkg>misc3d</pkg> is based on
          <pkg>rgl</pkg>. The package <pkg>onion</pkg> for visualizing 
          quaternions and octonions is well suited to display 3D graphics
          based on derived meshes.</li> 

      <li><i>Graphic Applications</i>: This area is not much different from the plotting 
          section except that these packages have tools that may not for display, but can 
          aid in creating effective displays. Also included are packages with more esoteric 
          plotting methods. For specific subject areas, like maps, or clustering the excellent
          task views contributed by other dedicated useRs is an excellent place to start.
          <ul>
          <li><i>Effect ordering</i>:
          The <pkg>gclus</pkg> package focuses on the ordering of graphs to accentuate cluster 
           structure or natural ordering in the data. While not for graphics directly 
          <pkg>cba</pkg> and <pkg>seriation</pkg> 
          have functions for creating 1 dimensional orderings from higher dimensional criteria. 
 	  For ordering an array of displays, <pkg>biclust</pkg> can be useful.</li>
          <li><i>Large Data Sets</i>:
	  Large data sets can present very different challenges from moderate and small 
          datasets. Aside from overplotting, rendering 1,000,000 points can tax even modern 
          GPU's. For bivariate data <pkg>ash</pkg> can produce a bivariate smoothed histogram very 
          quickly, and 
          <pkg>hexbin</pkg> can bin bivariate
          data onto a hexagonal lattice, the advantage being that the irregular lines and 
          orientation of hexagons do not create linear artifacts. For multivariate data, 
          <pkg>hexbin</pkg> can be used to create a scatterplot matrix, combined with <pkg>lattice</pkg>.
          An alternative is to use <pkg>scagnostics</pkg> to produce a scaterplot matrix
          of "data about the data", and look for interesting combinations of variables.</li>
          <li><i>Trees and Graphs</i>: 
           <pkg>ape</pkg> and <pkg>ade4</pkg> have functions for plotting 
           phylogenetic trees, which can be used for plotting dendrograms from 
           clustering procedures. While these packages produce decent graphics, they 
           do not use sophisticated algorithms for node placement, so may not be useful
           for very large trees. <pkg>igraph</pkg> has the Tilford-Rheingold algorithm 
           implementead and is useful for plotting larger trees. <pkg>diagram</pkg> has 
           facilities for flow diagrams and simple graphs. For more sophisticated graphs 
           <bioc>Rgraphviz</bioc> and <pkg>igraph</pkg> have functions for plotting and 
           layout, especially useful for representing large networks.</li>
          </ul>
	  </li>
      <li><i>Graphics Systems</i>: <pkg>lattice</pkg> is built on top of the grid
          graphics system and is an R implementation of William Cleveland's trellis
	  system for S-PLUS. <pkg>lattice</pkg> allows for building many types of plots
	  with sophisticated layouts based on conditioning. <pkg>ggplot2</pkg> is an R 
          implementation of the system described in "A Grammar of Graphics" by Leland 
          Wilkinson. Like <pkg>lattice</pkg>, <pkg>ggplot2</pkg> (also built on top of grid)
	  assists in trellis-like graphics, but allows for much more. Since it is built on
	  the idea of a semantics for graphics there is much more emphasis on reshaping
	  data, transformation, and assembling the elements of a plot.</li>

      <li><i>Devices</i>: Whereas grid is built on top of
          the R graphics engine, many in the R community have found the R
          graphics engine somewhat inflexible and have written separate device
          drivers that either emphasize interactivity or plotting in various
          graphics formats. R base supplies devices for PostScript, PDF, JPEG
          and other formats. Devices on CRAN include <pkg>cairoDevice</pkg> which
          is a device based libcairo, which can actually render to many device
          types. The cairo device is desgned to work with <pkg>RGtk2</pkg>,
          which is an interface to the Gimp Tool Kit, similar to pyGTK2.
	  <pkg>RSvgDevice</pkg> is an SVG device driver and interfaces well with
          with vector drawing programs. When SVG devices are for web display developers should be
          aware that internet explorer does not support SVG, but has their own
          standard. Trust Microsoft.
          <pkg>rgl</pkg> provides a device driver
          based on OpenGL, and is good for 3D and interactive
          development. Lastly, the Augsburg group supplies a set of packages
          that includes a Java-based device, <pkg>JavaGD</pkg>.</li>
      <li><i>Colors</i>: The package <pkg>colorspace</pkg> provides a set of functions for
          transforming between color spaces and <code>mixcolor()</code> for mixing colors
          within a color space.
	  Based on the HCL colors provided in <pkg>colorspace</pkg>, <pkg>vcd</pkg>
	  provides a set of functions for choosing color palettes suitable for
	  coding categorical variables (<code>rainbow_hcl()</code>) and numerical 
	  information (<code>sequential_hcl()</code>, <code>diverge_hcl()</code>). Similar
	  types of palettes are provided in <pkg>RColorBrewer</pkg>. <pkg>dichromat</pkg>
          is focused on palettes for color-impaired viewers.</li>
      <li><i>Interactive Graphics</i>: There are several efforts to
          implement interactive graphics systems that interface well with R. In an interactive 
          system the user can interactively query the graphics on the screen with the mouse, 
          or a moveable brush to zoom, pan and query on the device as well as link with 
          other views of the data. <pkg>rggobi</pkg>
          embeds the GGobi interactive graphics system within R, so that one can display a data
          frame or several in GGobi directly from R. The package has functions
          to support longitudinal data, and graphs using GGobi's edge set
          functionality. The RoSuDA repository maintained and developed by the
          University of Augsburg group has two packages, <pkg>iplots</pkg> and iwidgets as
          well as their Java development environment including a Java
          device, <pkg>JavaGD</pkg>. Their interactive graphics tools contain functions for
          alpha blending, which produces darker shading around areas with more
          data. This is exceptionally useful for parallel coordinate plots where
          many lines can quickly obscure patterns. <pkg>playwith</pkg> has facilities for 
          building interactive versions of R graphics using the <pkg>cairoDevice</pkg> and 
          <pkg>RGtk2</pkg>. Lastly, the <pkg>rgl</pkg> package has mechanisms for
          interactive manipulation of plots, especially 3D rotations and surfaces.</li>        
      <li><i>Development</i>: For development of specialized
          graphics packages in R, grid should probably be the first
          consideration for any new plot type. <pkg>rgl</pkg> has better tools for
          3D graphics, since the device is interactive, though it can be slow. 
          An alternative is to use Java and
          the Java device in the RoSuDA packages, though Java has its own
          drawbacks. For porting plotting code to grid, using the
          package <pkg>gridBase</pkg> presents a nice intermediate step to embed
          base graphics in grid graphics and vice versa.</li> 
    </ul>
  </info>

  <packagelist>
    <pkg>ade4</pkg>
    <pkg>animation</pkg>
    <pkg>ape</pkg>
    <pkg>aplpack</pkg>
    <pkg>ash</pkg>
    <pkg>biclust</pkg>
    <pkg>cairoDevice</pkg>
    <pkg>Cairo</pkg>
    <pkg>cba</pkg>
    <pkg>colorspace</pkg>
    <pkg>diagram</pkg>
    <pkg>dichromat</pkg>
    <pkg>gclus</pkg>
    <pkg priority="core">ggplot2</pkg>
    <pkg>gplots</pkg>
    <pkg>gridBase</pkg>
    <pkg>hexbin</pkg>
    <pkg>igraph</pkg>
    <pkg>iplots</pkg>
    <pkg>IDPmisc</pkg>
    <pkg>JavaGD</pkg>
    <pkg>klaR</pkg> 
    <pkg priority="core">lattice</pkg>
    <pkg>latticeExtra</pkg>
    <pkg>misc3d</pkg>
    <pkg>onion</pkg>
    <pkg>playwith</pkg>
    <pkg priority="core">plotrix</pkg>
    <pkg priority="core">RColorBrewer</pkg>
    <pkg priority="core">rgl</pkg>
    <pkg>rggobi</pkg>
    <pkg>RGraphics</pkg>
    <pkg>RGtk2</pkg>
    <pkg>RSvgDevice</pkg>
    <pkg>RSVGTipsDevice</pkg>
    <pkg>scagnostics</pkg>
    <pkg>tkrplot</pkg>
    <pkg>scatterplot3d</pkg>
    <pkg>seriation</pkg>
    <pkg priority="core">vcd</pkg>
    <pkg>vioplot</pkg>
    <pkg>xgobi</pkg>
  </packagelist>

  <links>
    <view>Cluster</view>
    <view>Multivariate</view> 
    <view>Spatial</view>
    <bioc>Rgraphviz</bioc>
    <a href="http://rgraphgallery.blogspot.com/">R Graph Gallery</a>
    <a href="http://www.stat.auckland.ac.nz/~paul/">Paul Murrell's home page</a>
    <a href="http://www.rosuda.org/software/">RoSuDA R packages</a>
    <a href="http://www.ggobi.org/">GGobi Data Visualization System</a>

  </links>

</CRANTaskView>
