ggmatplot
is a quick and easy way of plotting the columns of two matrices
or data frames against each other using
ggplot2
.
ggmatplot(
x = NULL,
y = NULL,
plot_type = c("point", "line", "both", "density", "histogram", "boxplot", "dotplot",
"errorplot", "violin", "ecdf"),
color = NULL,
fill = NULL,
shape = NULL,
linetype = NULL,
xlim = c(NA, NA),
ylim = c(NA, NA),
log = NULL,
main = NULL,
xlab = NULL,
ylab = NULL,
legend_label = NULL,
legend_title = NULL,
desc_stat = "mean_se",
asp = NA,
...
)
Vectors or matrices of data.
The number of rows of x
and y
should be the same.
Either x
or y
should be a vector, unless the number of columns of x
and y
are the same.
Missing values (NAs) are allowed.
If either x
or y
is missing, the other is used as y
and a vector of
1:n
is used as x
.
A string specifying the type of plot. Possible plot types
are point
, line
, both
(point + line), density
, histogram
, boxplot
,
dotplot
, errorplot
, violin
, and ecdf
. Default plot_type is point
.
Vectors of colors. Defining only one of them will update
both color
and fill
aesthetics of the plot by default, unless they are
both defined simultaneously.
The number of colors should match the higher number of columns of
matrices x
or y
, and will correspond to each of those columns.
If only a single color is given, the same color will be used for all columns.
A vector of shapes or line types respectively.
The number of shapes/line types should match the higher number of columns
of matrices x
or y
, and will correspond to each of those columns.
If only a single shape/line type is given, the same shape/line type will be used for all columns.
Ranges of x and y axes.
Each of them should be a two element vector specifying the lower and upper limits of the scale.
If the larger value is given first, the scale will be reversed. If one of
the limits is given as NA
, the corresponding limit from the range of data
will be used.
A string defining which axes to transform into a log scale.
(x
, y
or xy
)
Strings to update plot title, x axis label, y axis label and legend title respectively.
A vector of strings, to rename the legend labels.
Descriptive statistics to be used for visualizing errors,
in errorplot
. Possible values are mean_se
, mean_sd
, mean_range
,
median_iqr
and median_range
. Default desc_stat is mean_se
.
The y/x aspect ratio.
Other arguments passed on to the plot. Possible arguments are those that can be passed on to the underlying ggplot layers.
A ggplot object. The columns of the input matrices will be plotted against each other using the defined plot type.
ggmatplot
plots are built upon ggplot2 layers
. The following is a list of
ggmatplot
plot types, along with their underlying
ggplot geoms
or stats
.
point geom_point
line geom_line
both geom_point
+
geom_line
density geom_density
histogram geom_histogram
boxplot geom_boxplot
dotplot geom_dotplot
errorplot geom_pointrange
violin geom_violin
ecdf stat_ecdf
# Define a data set
iris_sub <- subset(iris, Species == "setosa")
ggmatplot(iris_sub[, c(1, 3)], iris_sub[, c(2, 4)])
# Modify legend label and axis
ggmatplot(iris_sub[, c(1, 3)], iris_sub[, c(2, 4)],
shape = c(4, 6),
legend_label = c("Sepal", "Petal"), legend_title = "",
xlab = "Length", ylab = "Width"
)