R Graphics

From Wiki
Revision as of 23:42, 16 September 2011 by Scott (talk | contribs) (Graphics package functions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Packages

graphics package is first choice; lattice package is well suited for splitting data by a conditioning variable

Graphics package functions

Each function has dozens of options for customization

  • plot(x, y) will plot vectors x and y as scatter plot
  • matplot(x, y) plot corresponding points in an arbitrary pair of corresponding data objects
  • smoothscatter(x, y) plots density of points for a very large number of points
  • acf(ts) autocorrelation function plot for time series
  • barplot(x) has many options
  • pie(x) is pie chart
  • persp(x, y, z) plot a three-dimensional surface as viewed from a high point above
  • image(x, y, z) plot a three-dimensional surface as viewed from directly above
  • contour(x,y,z) like image, but contour map
  • heatmap(x) plot a single variable on two axes, each representing a different factor
  • hist(x) histogram, (to make a finer plot: hist(x, breaks=20)
  • plot(density(x)) density plot is a continuous histogram

Print graphics to a file

To print to a PNG file:

png("test.png")
plot(density(lpt))
dev.off()

Options: width (numeric), height (numeric), units ("in" for inches, etc), res (resolution as pixels per unit)

Other file types: bmp, jpeg, tiff, postscript, pdf, pictex, xfig.