# Title: R Output Methods
# Date: 2008-02-01
# Project: CFL R graphics


# To output the graphics in a specific format, you must specify a special
# 'driver' before plotting. Once the driver is openned, plot like normal, 
# and when you're finished call 'dev.off()' to write the file.


# Tiff Format
# The 'bitmap' device allows for TIFF output. For a full list of bitmaps it can output, 
# see 'help(bitmap)'. 
#
# Units: The dimension units that height and width are given in
# Height and Width: Dimensions of the image in units specified by 'units'
# Res: Resolution of the image in dots per inch
bitmap(file='Tiff Output.tiff', type='tiffg4', height=6, width=6, res=300, units='in')

# Plot your graph
plot(1:10,1:10)

# Write the file
dev.off()


# PDF Format
# The 'pdf' device allows for PDF output.
#
# Height and Width: Dimensions of the image in inches
# Onefile: If true, it plots multiple figures on a page. If false,
#	   each figure gets its own numbered page.
# Family: The font family used to render text. You can use most fonts
#	  available to your computer.
# Paper: The type of paper determines the pdf size.
# Pointsize: Font size.
pdf(file='PDF Output.pdf', height=6, width=6, onefile=TRUE, family='Helvetica', paper='letter', pointsize=12)

# Plot your graph
plot(1:10,1:10)

# Write the file
dev.off()

# SVG Format
# SVG stands for 'Scalable Vector Graphics'. It is a relatively new format that 
# allows for direct editting and manipulation in programs such as Adobe (r) Illustrator
# or Inkscape. 
#
# This format requires the package RSVGDevice.
#
# Height and Width: Dimensions of the image in inches
# Onefile: If true, it plots multiple figures on a page. If false,
#	   each figure gets its own numbered page.

library(RSVGDevice)
devSVG(file='SVG Output.svg', height=6, width=6, onefile=TRUE)

# Plot your graph
plot(1:10,1:10)

# Write the file
dev.off()