coord_justif: Calculate X, y Positions and H|vjust Values for Entries

Description Usage Arguments Details Value See Also

View source: R/plotting_util.bare.R


Calculate coordinates and h|vjust values for entry text strings, to achieve the desired justification and alignment with respect to cell boundaries. This is an internal utility function, not intended to be called by package users.


coord_justif(df, x0, x1, y0, y1, size, align=df$align)



Data frame with one row per entry. Required columns are hjust, vjust, hpad, vpad, angle. angle must be a multiple of 90 degrees.

x0, x1, y0, y1

Numeric vectors with one element per entry, giving the coordinates (in mm) of the boundaries of the cell(s) containing each entry. Note that the origin is at the top left of the table.


Data frame with one row per entry, and columns hsize, vsize, and descender. The first two are the dimensions, in mm, of an unrotated rectangle just enclosing the (possibly rotated) entry text. (So hsize is always measured parallel to the x-axis and vsize parallel to the y-axis.) descender is the amount of space included in hsize or vsize to allow for text descenders. (This is 0 for a textGrob, but larger for richtext_grob and textbox_grob.) Functions entrySize_mm and calc_rcsize return such a data frame (the latter in the sizeInfo component).


Optional numeric vector with one element per entry. It specifies horizontal alignment of multiple lines within an entry *with respect to each other*. 0 means all lines in the entry are aligned at their left edge ("left justified"), 1 means they are all aligned at their right edge ("right justified"), 0.5 means they are aligned at their centers. The default is to use column align in df if present and not NA. Otherwise it depends on text rotation specified by df$angle; for unrotated text it is set equal to df$hjust.


The need to jointly calculate x, y, gg_hjust, and gg_vjust is due to a difference between tablesgg and ggplot2 in their interpretations of text justification. ggplot2 interprets justification parameters as indicating position of text relative to the (x,y) coordinates used to draw the text: 0 means to the right/above (x,y), 1 means to the left/below (x,y). tablesgg interprets justification parameters as position relative to the boundaries of the table cell(s) containing the entry text: 0 means at the left/top boundary, 1 means at the right/bottom boundary.

This function takes cell boundary coordinates x0, x1, y0, y1 and tablesgg-type justification parameters and converts them to the ggplot2-type (x,y) coordinates and justification parameters. In doing so it is also necessary to take any text rotation (specified by graphical property angle) into account.

Values provided to geom_* functions should be x, y, hjust=gg_hjust, and vjust=gg_vjust. If the geom_* function has an halign argument (e.g., for geom_textbox), set it to gg_hjust.

Justification values in [0, 1] will never position text closer to cell boundaries than the padding specified by df$hpad and df$vpad.


Data frame with one row per row of df. Columns are:

x, y

Coordinates to give to a geom_* function when drawing the entry text.

gg_hjust, gg_vjust

hjust and vjust values to give to a geom_* function.

See Also

entrySize_mm, calc_rcsize

tablesgg documentation built on June 3, 2021, 1:06 a.m.