I'd like to add a small table (for example as a legend) to a plot in R. I think of something like:
t <- wantedTableMethod(
row("param1", "param2", "param3", "param4")
, row(value11, value12, value13, cell(value14, adj=0))
, row(value21, value22, value23, value24)
, row(value31, value32, value33, cell(value34, adj=1))
border = F
)
plot(1,1)
legend("topleft", t)
All values of a column should have the same offset. Is something like this possible in R, or do I need to align each value manually?
The
plotrix
package has aaddtable2plot
function you can pass adata.frame
ormatrix
toUsing the example from the help page
It is designed to work as similarly to
legend
as possible.If you're really averse to external packages, you can accomplish a version of this in
base
R as well:Caveat coder that since
v
will be coerced tocharacter
, you'll have to be careful about float formatting (sprintf
is your friend). There are also other bells & whistles liketext.col
to help spiffen up the plot a bit more if you'd like.