View source: R/axis_combmatrix.R
axis_combmatrix | R Documentation |
The function splits the text based on the sep
argument and
views each occurring element as potential set.
axis_combmatrix(
sep = "[^[:alnum:]]+",
levels = NULL,
override_plotting_function = NULL,
xlim = NULL,
ylim = NULL,
expand = TRUE,
clip = "on",
ytrans = "identity"
)
sep |
The separator that is used to split the string labels. Can be a
regex. Default: |
levels |
The selection of string elements that are displayed in the combination matrix axis. Default: NULL, which means simply all elements in the text labels are used |
override_plotting_function |
to achieve maximum flexibility, you can
provide a custom plotting function. For more information, see details.
Default: |
xlim , ylim |
The limits fort the x and y axes |
expand |
Boolean with the same effect as in
|
clip |
String with the same effect as in
|
ytrans |
transformers for y axis. For more information see
|
Technically the function appends a coord
system to the ggplot object.
To maintain compatibility additional arguments like ytrans
,
ylim
, and clip
are forwarded to coord_trans()
.
Note: make sure that the argument to the 'x' aesthetic is
character vector that contains the sep
sequence. The only
exception is if axis_combmatrix()
is combined with a
scale_x_mergelist()
. This pattern works because in the
first step scale_x_mergelist()
turns a list argument
to 'x' into a character vector that axis_combmatrix()
can work with.
For maximum flexibility, you can use the 'override_plotting_function' parameter
which returns a ggplot and is called with a tibble
with one entry per point of the combination matrix. Specifically, it contains
the collapsed label string
an ordered factor with the labels on the left of the plot
consecutive numbering of the points
a list column that contains the splitted labels
the x-position of the point
boolean to indicate if this element is active in the intersection
the row of the point
See the examples how the override_plotting_function
looks that recreates
the default combination matrix
library(ggplot2)
mtcars$combined <- paste0("Cyl: ", mtcars$cyl, "_Gears: ", mtcars$gear)
head(mtcars)
ggplot(mtcars, aes(x=combined)) +
geom_bar() +
axis_combmatrix(sep = "_")
# Example of 'override_plotting_function'
ggplot(mtcars, aes(x=combined)) +
geom_bar() +
axis_combmatrix(sep = "_", override_plotting_function = function(df){
ggplot(df, aes(x= at, y= single_label)) +
geom_rect(aes(fill= index %% 2 == 0), ymin=df$index-0.5,
ymax=df$index+0.5, xmin=0, xmax=1) +
geom_point(aes(color= observed), size = 3) +
geom_line(data= function(dat) dat[dat$observed, ,drop=FALSE],
aes(group = labels), size= 1.2) +
ylab("") + xlab("") +
scale_x_continuous(limits = c(0, 1), expand = c(0, 0)) +
scale_fill_manual(values= c(`TRUE` = "white", `FALSE` = "#F7F7F7")) +
scale_color_manual(values= c(`TRUE` = "black", `FALSE` = "#E0E0E0")) +
guides(color="none", fill="none") +
theme(
panel.background = element_blank(),
axis.text.x = element_blank(),
axis.ticks.y = element_blank(),
axis.ticks.length = unit(0, "pt"),
axis.title.y = element_blank(),
axis.title.x = element_blank(),
axis.line = element_blank(),
panel.border = element_blank()
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.