cranvas (version 0.8.5)

prefer_height: Preferred height and width of layers with texts

Description

The height and width of a layer which draws texts often involves with the number of line breaks ('\n') in the texts. These two functions give the preferred height and width of a layer as a rule of thumb.

Usage

prefer_height(text)
prefer_width(text, horizontal = TRUE)

Arguments

text
the character vector to be drawn in the layer
horizontal
logical: the text is drawn horizontally (TRUE) or vertically (FALSE)

Value

The height or width (numeric).

Details

Usually the height and width of the title layer and x- and y-axis layers need to be adjusted dynamically.

Examples

Run this code
prefer_height("a label")
prefer_height("this is\na label")
prefer_width("abc")
prefer_width("a long long label")
prefer_width("line\nbreaks")  # 'breaks' dominates the width because it is wider
prefer_width("multiple\nvertical\nlines", horizontal = FALSE)

Run the code above in your browser using DataCamp Workspace