geom_table
adds a textual table directly to the ggplot using syntax
similar to that of geom_label
.
geom_table(mapping = NULL, data = NULL, stat = "identity",
position = "identity", ..., parse = FALSE, check_overlap = FALSE,
na.rm = FALSE, show.legend = NA, inherit.aes = TRUE)
A layer specific dataset - only needed if you want to override the plot defaults.
The statistical transformation to use on the data for this layer, as a string.
Position adjustment, either as a string, or the result of a call to a position adjustment function.
If TRUE, the labels will be parsed into expressions and displayed as described in ?plotmath.
If TRUE
, text that overlaps previous text in the
same layer will not be plotted.
If FALSE
(the default), removes missing values with a
warning. If TRUE
silently removes missing values.
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped. FALSE
never includes, and TRUE
always includes.
If FALSE
, overrides the default aesthetics, rather
than combining with them. This is most useful for helper functions that
define both data and aesthetics and shouldn't inherit behaviour from the
default plot specification, e.g. borders
.
You can modify table alignment with the vjust
and
hjust
aesthetics. These can either be a number between 0
(right/bottom) and 1 (top/left) or a character ("left", "middle", "right",
"bottom", "center", "top").
Note the "width" and "height" like of a text element are 0, so stacking and dodging tables will not work by default, and axis limits are not automatically expanded to include all tables. Obviously, tables do have height and width, but they are physical units, not data units. The amount of space they occupy on that plot is not constant in data units: when you resize a plot, tables stay the same size, but the size of the axes changes.
This geometry is inspired on answers to two questions in Stackoverflow. In contrast to these earlier examples, the current geom obeys the grammar of graphics, and attempts to be consistent with the behaviour of 'ggplot2' geometries. https://stackoverflow.com/questions/12318120/adding-table-within-the-plotting-region-of-a-ggplot-in-r
https://stackoverflow.com/questions/25554548/adding-sub-tables-on-each-panel-of-a-facet-ggplot-in-r?
function tableGrob
as it is used to
construct the table.