showtext_opts {showtext}R Documentation

Setting Options for 'showtext' package

Description

The two versions of this function are equivalent, but the "underscore" naming is preferred.

This function sets parameters that will affect the appearance of the graphs created with showtext.

Usage

showtext_opts(...)

showtext.opts(...)

Arguments

...

Options to be set, expressed in name = value pairs. It can also be a list containing these pairs (for example, the list returned by a previous call of showtext_opts()). Currently accepted parameters are nseg and dpi. See the Options Used section.

Options Used

nseg

Parameter to control the smoothness of the outlines of glyphs, typically used in vector graphics devices such as pdf() and svg(). It is the number of line segments to approximate a piece of curve in the glyph. The larger nseg is, the smoother text outlines would be, but also with larger file size for vector graphics. Usually a value between 5~20 would be enough.

dpi

An integer that gives the resolution of the device. This parameter is only used in bitmap and on-screen graphics devices such as png() and x11(), to determine the pixel size of text from point size. For example, if dpi is set to 96, then a character with 12 point size will have a pixel size of 12 * 96 / 72 = 16.

Author(s)

Yixuan Qiu <https://statr.me/>

Examples

## Not run: 
## Set dpi to 200
op = showtext_opts(dpi = 200)

png("dpi_200.png", 800, 800, res = 200)
par(family = "sans")
showtext_begin()

set.seed(123)
plot(density(rnorm(100)))

showtext_end()
dev.off()

## Restore old options
showtext_opts(op)

png("dpi_96.png", 800, 800, res = 96)
par(family = "sans")
showtext_begin()

set.seed(123)
plot(density(rnorm(100)))

showtext_end()
dev.off()

## End(Not run)

[Package showtext version 0.9-7 Index]