png                package:grDevices                R Documentation

_J_P_E_G _a_n_d _P_N_G _g_r_a_p_h_i_c_s _d_e_v_i_c_e_s

_D_e_s_c_r_i_p_t_i_o_n:

     A graphics device for JPEG or PNG format bitmap files.

_U_s_a_g_e:

     jpeg(filename = "Rplot%03d.jpeg", width = 480, height = 480,
          pointsize = 12, quality = 75, bg = "white", res = NA, ...)

     png(filename = "Rplot%03d.png", width = 480, height = 480,
         pointsize = 12, bg = "white",  res = NA, ...)

_A_r_g_u_m_e_n_t_s:

filename: the name of the output file. The page number is substituted
          if a C integer format is included in the character string, as
          in the default.  (The result must be less than 'PATH_MAX'
          characters long, and may be truncated if not. See
          'postscript' for further details.)  Tilde expansion is
          performed where supported by the platform.

   width: the width of the device in pixels.

  height: the height of the device in pixels.

pointsize: the default pointsize of plotted text, interpreted at 72
          dpi, so one point is approximately one pixel.

 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.

     res: The nominal resolution in dpi which will be recorded in the
          bitmap file, if a positive integer.

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

_D_e_t_a_i_l_s:

     Plots in PNG and JPEG format can easily be converted to many other
     bitmap formats, and both can be displayed in 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 may not be usable
     unless the X11 display is available to the owner of the R process.

     By default no resolution is recorded in the file.  Readers will
     often assume a nominal resolution of 72dpi when none is recorded. 
     As resolutions in PNG files are recorded in pixels/metre, the dpi
     value will be changed slightly.

     For graphics parameters that make use of dimensions in inches, a
     resolution of 96dpi is assumed.

     'png' will use a palette if there are less than 256 colours on the
     page, and record a 24-bit RGB file otherwise.

_V_a_l_u_e:

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

_W_a_r_n_i_n_g_s:

     Note that the 'width' and 'height' are in pixels not inches. A
     warning will be issued if both are less than 20.

     If you plot more than one page on one of these devices and do not
     include something like '%d' for the sequence number in 'file', the
     file will contain the last page plotted.

_N_o_t_e:

     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.

_A_u_t_h_o_r(_s):

     Guido Masarotto and Brian Ripley

_S_e_e _A_l_s_o:

     '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.  (Devices 'GDD' in CRAN
     package 'GDD' and 'CairoJPEG' / 'CairoPNG' in CRAN package 'Cairo'
     are alternatives using several other additional pieces of
     software.)

_E_x_a_m_p_l_e_s:

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

     ## copy current plot to a (large) PNG file
     ## Not run: dev.print(png, file="myplot.png", width=1024, height=768)

     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()
     ## End(Not run)

