Details
Internally the matrix is converted to long form and visualized as a scatter (or other type) of each column’s values against their row index. Each column is mapped to a separate by category, so a matrix with multiple columns produces a grouped plot. Optionally, it can also be faceted via facet = “by”. This mirrors the base R matplot convention of plotting the columns of a matrix against the row numbers. If the matrix has column names, these are used as the group (and legend) labels. Single-column matrices are drawn as a simple index plot with no grouping or legend.
The “tile” and “heatmap” types are an exception, since the matplot convention makes little sense for them. Instead the matrix is laid out as a grid—columns along the x-axis, rows along the y-axis—with the matrix values supplied as the fill. The y-axis is reversed so that the first row sits at the top, matching how one reads a matrix (cf. heatmap and image); pass an explicit ylim to override. Both axis titles are suppressed, since the dimnames already label the ticks, and so is the legend, since the fill merely re-encodes the matrix’s own values. Pass an explicit legend (or xlab/ylab) to override either. See Examples.