Cairo initializes a new graphics device that uses the cairo
graphics library for rendering. The current implementation produces
high-quality PNG, JPEG, TIFF bitmap files, high resolution PDF files
with embedded fonts, SVG graphics and PostScript files. It also
provides X11 and Windows interactive graphics devices. Unlike other
devices it supports all graphics features including alpha blending,
anti-aliasing etc.
CairoX11, CairoPNG, CairoPDF, CairoPS and
CairoSVG are convenience wrappers of Cairo that take the
same arguments as the corresponding device it replaces such as
X11, png, pdf, etc. Use of the Cairo
function is encouraged as it is more flexible than the wrappers.
name of the file to be created or connection to write
to. Only PDF, PS and PNG types support connections. For X11
type file specifies the display name. If NULL or
"" a reasonable default will be chosen which is
"plot.type" for file-oriented types and value of the
DISPLAY environment variable for X11. For image types
the file name can contain printf-style formatting expecting
one integer parameter which is the page number, such as
"Rplot%03d.png". The page numbers start at one.
type
output type. This version of Cario supports "png", "jpeg"
and "tiff" bitmaps (png/tiff with transparent background), "pdf"
PDF-file with embedded fonts, "svg" SVG-file, "ps" PostScript-file,
"x11" X11 interactive window and "win" Windows graphics.
A special type "raster" creates an image back-end that produces no
actual output file but can be used in conjunction with any of
dev.capture(), grid.cap() or Cairo:::.image()
to create in-memory images.
Depending on the support of various backends in cairo graphics some
of the options may not be available for your system. See
Cairo.capabilities function.
pointsize
initial text size (in points).
canvas
canvas color (must be opaque). The canvas is only used
by devices that display graphics on a screen and the canvas is only
visible only if bg is transparent.
bg
plot background color (can include alpha-component or be
transparent alltogether).
units
units for of the width and height
specifications. It can be any of "px" (pixels),
"in" (inches), "pt" (points), "cm"
(centimeters) or "mm" (millimeters).
dpi
DPI used for the conversion of units to pixels. If set to
"auto" the DPI resolution will be determined by the
back-end.
...
additional backend specific parameters (e.g. quality
setting for JPEG (0..100), compression for TIFF
(0,1=none, 5=LZW (default), 7=JPEG, 8=Adobe Deflate),
locator for a custom locator function in image back-ends)
All parameters
listed below are defined by the other devices are are used by
the wrappers to make it easier replace other devices by
Cairo. They are described in detail in the documentation
corresponding to the device that is being replaced.
display
X11 display, see X11
gamma
gamma correction
xpos
see X11
ypos
see X11
filename
same as file in Cairo
res
resolution in ppi, see png, will
override dpi in Cairo if set to anything other
than NA or NULL. Note that cairographics does not
support tagging PNG output files with DPI so the raster image will
be produced with the dpi setting, but readers may render it at
some default dpi setting.
quality
quality of the jpeg, see jpeg
onefile
logical: if true (the default) allow multiple
figures in one file (see pdf). false is currently
not supported by vector devices
family
font family, see pdf
title
see pdf (ignored)
fonts
see pdf, ignored, Cairo
automatically detects and embeds fonts
version
PDF version, see pdf (ignored)
paper
see pdf (ignored, Cairo uses device dimensions)
encoding
see pdf (ignored, Cairo uses
native enconding except for symbols)
fg
see pdf (ignored)
pagecentre
see pdf (ignored, Cairo
uses device dimensions and thus it is irrelevant)
record
Windows-specific, ignored on unix
rescale
Windows-specific, ignored on unix
xpinch
Windows-specific, ignored on unix
ypinch
Windows-specific, ignored on unix
buffered
Windows-specific, ignored on unix
restoreConsole
Windows-specific, ignored on unix
horizontal
see postscript (ignored)
print.it
see postscript (ignored)
command
see postscript (ignored)
colormodel
see postscript (ignored,
Cairo always uses RGB or ARGB)
Value
The (invisible) return value is NULL if the device couldn't be created
or a Cairo object if successful. The vaule of the object is the
device number.
Known issues
The X11 backend is quite slow. The reason is the cairographics
implementation of the backend, so we can't do much about
it. It should be possible to drop cairographics' Xlib
backend entirely and use image backend copied into an X11
window instead. We may try that in future releases.
TrueType (and OpenType) fonts are supported when this package is compiled
against a cairo graphics library configured with FreeType and
Fontconfig support. Therefore make sure have a cairo graphics
library with all bells and whistles to get a good result.
R math symbols are supported, but require a TrueType "Symbol" font accessible
to Cairo under that name.
See Also
CairoFonts
Examples
# very simple KDE
Cairo(600, 600, file="plot.png", type="png", bg="white")
plot(rnorm(4000),rnorm(4000),col="#ff000018",pch=19,cex=2) # semi-transparent red
dev.off() # creates a file "plot.png" with the above plot
# you can use any Cairo backend and get the same result
# vector, bitmap or on-screen
CairoPDF("plot.pdf", 6, 6, bg="transparent")
data(iris)
attach(iris)
plot(Petal.Length, rep(-0.03,length(Species)), xlim=c(1,7),
ylim=c(0,1.7), xlab="Petal.Length", ylab="Density",
pch=21, cex=1.5, col="#00000001", main = "Iris (yet again)",
bg=c("#ff000020","#00ff0020","#0000ff20")[unclass(Species)])
for (i in 1:3)
polygon(density(Petal.Length[unclass(Species)==i],bw=0.2),
col=c("#ff000040","#00ff0040","#0000ff40")[i])
dev.off()
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(Cairo)
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Cairo/Cairo.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Cairo
> ### Title: Create a new Cairo-based graphics device
> ### Aliases: Cairo CairoX11 CairoPNG CairoPDF CairoSVG CairoPS CairoWin
> ### CairoJPEG CairoTIFF
> ### Keywords: device
>
> ### ** Examples
>
> # very simple KDE
> Cairo(600, 600, file="plot.png", type="png", bg="white")
> plot(rnorm(4000),rnorm(4000),col="#ff000018",pch=19,cex=2) # semi-transparent red
> dev.off() # creates a file "plot.png" with the above plot
png
2
>
> # you can use any Cairo backend and get the same result
> # vector, bitmap or on-screen
> CairoPDF("plot.pdf", 6, 6, bg="transparent")
> data(iris)
> attach(iris)
> plot(Petal.Length, rep(-0.03,length(Species)), xlim=c(1,7),
+ ylim=c(0,1.7), xlab="Petal.Length", ylab="Density",
+ pch=21, cex=1.5, col="#00000001", main = "Iris (yet again)",
+ bg=c("#ff000020","#00ff0020","#0000ff20")[unclass(Species)])
> for (i in 1:3)
+ polygon(density(Petal.Length[unclass(Species)==i],bw=0.2),
+ col=c("#ff000040","#00ff0040","#0000ff40")[i])
> dev.off()
png
2
>
>
>
>
>
> dev.off()
null device
1
>