x11 {grDevices} | R Documentation |
the X11()
and x11()
functions are
simple wrappers to windows()
for historical
compatibility convenience: Calling x11()
or X11()
would work in most
cases to open an interactive graphics device.
In R versions before 3.6.0, the Windows version had a shorter
list of formal arguments. Consequently, calls to X11(*)
with arguments should name them for back compatibility.
Almost all information below does not apply on Windows.
X11
starts a graphics device driver for
the X Window System (version 11). This can only be done on
machines/accounts that have access to an X server.
x11
is recognized as a synonym for X11
.
The R function is a wrapper for two devices, one based on Xlib (https://en.wikipedia.org/wiki/Xlib) and one using cairographics (http://www.cairographics.org).
X11(display = "", width, height, pointsize, gamma, bg, canvas, fonts, family, xpos, ypos, title, type, antialias) X11.options(..., reset = FALSE)
display |
the display on which the graphics window will appear. The default is to use the value in the user's environment variable DISPLAY. This is ignored (with a warning) if an X11 device is already open on another display. |
width, height |
the width and height of the plotting window, in
inches. If |
pointsize |
the default pointsize to be used. Defaults to |
gamma |
gamma correction fudge factor. Colours in R are sRGB; if your monitor does not conform to sRGB, you might be able to improve things by tweaking this parameter to apply additional gamma correction to the RGB channels. By default 1 (no additional gamma correction). |
bg |
colour, the initial background colour. Default
|
canvas |
colour. The colour of the canvas, which is visible only
when the background colour is transparent. Should be an opaque colour
(and any alpha value will be ignored). Default |
fonts |
for |
family |
The default family: a length-one character string. This
is primarily intended for cairo-based devices, but for |
xpos, ypos |
integer: initial position of the top left corner of the
window, in pixels. Negative values are from the opposite corner,
e.g. |
title |
character string, up to 100 bytes. With the default,
|
type |
character string, one of |
antialias |
for cairo types, the type of anti-aliasing (if any)
to be used. One of |
reset |
logical: should the defaults be reset to their defaults? |
... |
Any of the arguments to |
The defaults for all of the arguments of X11
are set by
X11.options
: the ‘Arguments’ section gives the
‘factory-fresh’ defaults.
The initial size and position are only hints, and may not be acted on by the window manager. Also, some systems (especially laptops) are set up to appear to have a screen of a different size to the physical screen.
Option type
selects between two separate devices: R can be
built with support for neither, type = "Xlib"
or both. Where
both are available, types "cairo"
, "nbcairo"
and
"dbcairo"
offer
antialiasing of text and lines.
translucent colours.
scalable text, including to sizes like 4.5 pt.
full support for UTF-8, so on systems with suitable fonts you can plot in many languages on a single figure (and this will work even in non-UTF-8 locales). The output should be locale-independent.
There are three variants of the cairo-based device. type =
"nbcairo"
has no buffering. type = "cairo"
has some
buffering, and supports dev.hold
and dev.flush
.
type = "dbcairo"
buffers output and updates the screen about
every 100ms (by default). The refresh interval can be set (in units
of seconds) by e.g. options(X11updates = 0.25)
: the
value is consulted when a device is opened. Updates are only looked
for every 50ms (at most), and during heavy graphics computations only
every 500ms.
Which version will be fastest depends on the X11 connection and the
type of plotting. You will probably want to use a buffered type
unless backing store is in use on the X server (which for example it
always is on macOS displays), as otherwise repainting when the
window is exposed will be slow. On slow connections type =
"dbcairo"
will probably give the best performance.
Because of known problems with font selection on macOS without
Pango (for example, the CRAN distribution), type = "cairo"
is
not the default there. These problems have included mixing up bold
and italic (since worked around), selecting incorrect glyphs and ugly
or missing symbol glyphs.
All devices which use an X11 server (including the type =
"Xlib"
versions of bitmap devices such as png
) share
internal structures, which means that they must use the same
display
and visual. If you want to change display, first close
all such devices.
The cursor shown indicates the state of the device. If quiescent the cursor is an arrow: when the locator is in use it is a crosshair cursor, and when plotting computations are in progress (and this can be detected) it is a watch cursor. (The exact cursors displayed will depend on the window manager in use.)
This section applies only to type = "Xlib"
.
An initial/default font family for the device can be specified via
the fonts
argument, but if a device-independent R graphics font
family is specified (e.g., via par(family =)
in the graphics
package), the X11 device makes use of the X11 font database (see
X11Fonts
) to convert the R graphics font family to an
X11-specific font family description. If family
is supplied as
an argument, the X11 font database is used to convert that, but
otherwise the argument fonts
(with default given by
X11.options
) is used.
X11 chooses fonts by matching to a pattern, and it is quite possible
that it will choose a font in the wrong encoding or which does not
contain glyphs for your language (particularly common in
iso10646-1
fonts).
The fonts
argument is a two-element character vector, and the
first element will be crucial in successfully using
non-Western-European fonts. Settings that have proved useful include
"-*-mincho-%s-%s-*-*-%d-*-*-*-*-*-*-*"
for CJK languages and
"-cronyx-helvetica-%s-%s-*-*-%d-*-*-*-*-*-*-*"
for Russian.
For UTF-8 locales, the XLC_LOCALE
databases provide mappings
between character encodings, and you may need to add an entry for your
locale (e.g., Fedora Core 3 lacked one for ru_RU.utf8
).
The cairographics-based devices work directly with font family names
such as "Helvetica"
which can be selected initially by the
family
argument and subsequently by par
or
gpar
. There are mappings for the three
device-independent font families, "sans"
for a sans-serif font
(to "Helvetica"
), "serif"
for a serif font (to
"Times"
) and "mono"
for a monospaced font (to
"Courier"
).
The font selection is handled by Pango
(usually via
fontconfig
) or fontconfig
(on macOS and perhaps
elsewhere). The results depend on the fonts installed on the system
running R – setting the environmnent variable FC_DEBUG to 1
normally allows some tracing of the selection process.
This works best when high-quality scalable fonts are installed,
usually in Type 1 or TrueType formats: see the “R Installation
and Administration Manual” for advice on how to obtain and install
such fonts. At present the best rendering (including using kerning)
will be achieved with TrueType fonts: see
http://www.freedesktop.org/software/fontconfig/fontconfig-user.html
for ways to set up your system to prefer them. The default family
("Helvetica"
) is likely not to use kerning: alternatives which
should if you have them installed are "Arial"
,
"DejaVu Sans"
and "Liberation Sans"
(and perhaps
"FreeSans"
). For those who prefer fonts with serifs, try
"Times New Roman"
, "DejaVu Serif"
and "Liberation
Serif"
. To match LaTeX text, use something like "CM Roman"
.
Problems with incorrect rendering of symbols (e.g., of
quote(pi)
and expression(10^degree)
)
have been seen on Linux systems which have the Wine
symbol font installed – fontconfig
then prefers this and
misinterprets its encoding. Adding the following lines
to ‘~/.fonts.conf’ or ‘/etc/fonts/local.conf’ may circumvent
this problem by preferring the URW Type 1 symbol font.
<fontconfig> <match target="pattern"> <test name="family"><string>Symbol</string></test> <edit name="family" mode="prepend" binding="same"> <string>Standard Symbols L</string> </edit> </match> </fontconfig>
A test for this is to run at the command line fc-match Symbol
.
If that shows symbol.ttf
that may be the Wine symbol font – use
locate symbol.ttf
to see if it is found from a directory with
wine in the name.
The standard X11 resource geometry
can be used to specify the
window position and/or size, but will be overridden by values
specified as arguments or non-NA
defaults set in
X11.options
. The class looked for is R_x11
. Note that
the resource specifies the width and height in pixels and not in
inches. See for example man X (or
https://www.x.org/releases/current/).
An example line in ‘~/.Xresources’ might be
R_x11*geometry: 900x900-0+0
which specifies a 900 x 900 pixel window at the top right of the screen.
X11 supports several ‘visual’ types, and nowadays almost all
systems support ‘truecolor’ which X11
will use by
default. This uses a direct specification of any RGB colour up to the
depth supported (usually 8 bits per colour). Other visuals make use
of a palette to support fewer colours, only grays or even only
black/white. The palette is shared between all X11 clients, so it can
be necessary to limit the number of colours used by R.
The default for type = "Xlib"
is to use the best possible colour
model for the visual of the X11 server: these days this will almost
always be ‘truecolor’. This can be overridden by the
colortype
argument of X11.options
. Note: All
X11
and type = "Xlib"
bmp
, jpeg
,
png
and tiff
devices share a colortype
which is
set when the first device to be opened. To change the
colortype
you need to close all open such devices, and
then use X11.options(colortype =)
.
The colortype types are tried in the order "true"
,
"pseudo"
, "gray"
and "mono"
(black or white
only). The values "pseudo"
and "pseudo.cube"
provide
two colour strategies for a pseudocolor visual. The first strategy
provides on-demand colour allocation which produces exact colours
until the colour resources of the display are exhausted (when plotting
will fail). The second allocates (if possible) a standard colour
cube, and requested colours are approximated by the closest value in
the cube.
With colortype
equal to "pseudo.cube"
or "gray"
successively smaller palettes are tried until one is completely
allocated. If allocation of the smallest attempt fails the device will
revert to "mono"
. For "gray"
the search starts at 256
grays for a display with depth greater than 8, otherwise with half
the available colours. For "pseudo.cube"
the maximum cube size
is set by X11.options(maxcolorsize =)
and defaults to
256. With that setting the largest cube tried is 4 levels each for
RGB, using 64 colours in the palette.
The cairographics-based devices most likely only work (or work correctly) with ‘TrueColor’ visuals, although in principle this depends on the cairo installation: a warning is given if any other visual is encountered.
type = "Xlib"
supports ‘TrueColor’,
‘PseudoColor’, ‘GrayScale’, StaticGray
and
MonoChrome
visuals: ‘StaticColor’ and
‘DirectColor’ visuals are handled only in black/white.
Anti-aliasing is only supported for cairographics-based devices, and
applies to both graphics and fonts. It is generally preferable for
lines and text, but can lead to undesirable effects for fills,
e.g. for image
plots, and so is never used for fills.
antialias = "default"
is in principle platform-dependent, but
seems most often equivalent to antialias = "gray"
.
This section describes the implementation of the conventions for graphics devices set out in the “R Internals Manual”.
The default device size is 7 inches square.
Font sizes are in big points.
The default font family is Helvetica.
Line widths in 1/96 inch, minimum one pixel for type =
"Xlib"
, 0.01 otherwise.
For type = "Xlib"
circle radii are in pixels with
minimum one.
Colours are interpreted by the X11 server, which is assumed to conform to sRGB.
## Not run: if(.Platform$OS.type == "unix") { # Only on unix-alikes, possibly Mac, ## put something like this is your .Rprofile to customize the defaults setHook(packageEvent("grDevices", "onLoad"), function(...) grDevices::X11.options(width = 8, height = 6, xpos = 0, pointsize = 10)) } ## End(Not run)