png                   package:base                   R Documentation

JPEG and PNG graphics devices

Description:

     A graphics device for JPEG or PNG format bitmap files.

Usage:

     jpeg(filename = "Rplot.jpeg", width = 480, height = 480,
          pointsize = 12, quality = 75, bg = "white", ...)
     png(filename ="Rplot.png", width = 480, height = 480,
         pointsize = 12, bg = "white", ...)

Arguments:

filename: the name of the output file.

   width: the width of the device in pixels.

  height: the height of the device in pixels.

pointsize: the default pointsize of plotted text.

 quality: the `quality' of the JPEG image, as a percentage. Smaller
          values will give more compression but also more degradation
          of the image.

      bg: default background colour.

     ...: additional arguments to the `X11' device.

Details:

     Plots in PNG and JPEG format can easily be converted to many other
     bitmap formats, and both can be displayed in most modern web
     browsers. The PNG format is lossless and is best for line diagrams
     and blocks of solid colour. The JPEG format is lossy, but may be
     useful for image plots, for example.

     `png' supports transparent backgrounds: use `bg = "transparent"'.
     Not all PNG viewers render files with transparency correctly. When
     transparency is in use a very light grey is used as the background
     and so will appear as transparent if used in the plot. This allows
     opaque white to be used, as on the example.

     R can be compiled without support for either or both of these
     devices: this will be reported if you attempt to use them on a
     system where they are not supported.  They will not be available
     if R has been started with `--gui=none' (and will give a different
     error message), and they may not be usable unless the X11 display
     is available to the owner of the R process.

Value:

     A plot device is opened: nothing is returned to the R interpreter.

Note:

     These are based on the `X11' device, so the additional arguments
     to that device work, but are rarely appropriate.  The colour
     handling will be that of the `X11' device in use.

Author(s):

     Guido Masarotto and Brian Ripley

See Also:

     `Devices', `dev.print'

     `capabilities' to see if these devices are supported by this build
     of R.

     `bitmap' provides an alternative way to generate PNG and JPEG
     plots that does not depend on accessing the X11 display but does
     depend on having GhostScript installed.

Examples:

     ## these examples will work only if the devices are available
     ## and the X11 display is available.

     ## copy current plot to a PNG file
     dev.print(png, file="myplot.png", width=480, height=480)

     png(file="myplot.png", bg="transparent")
     plot(1:10)
     rect(1, 5, 3, 7, col="white")
     dev.off()

     jpeg(file="myplot.jpeg")
     example(rect)
     dev.off()

