plot_sedesign | R Documentation |
Plot contrasts from sedesign object (in development), showing one-way contrasts as block arrow, and two-way contrasts as two block arrows connected in proper order.
plot_sedesign(
sedesign,
se = NULL,
factor_names = NULL,
factor_sep = "_",
contrast_sep = "-",
axis1 = NULL,
axis2 = NULL,
axis3 = NULL,
axis4 = NULL,
which_contrasts = NULL,
contrast_style = c("comp", "contrast", "none"),
contrast_labels = NULL,
oneway_position = 0.9,
twoway_position = 0.5,
contrast_position = NULL,
contrast_depths = NULL,
sestats = NULL,
sestats_style = c("label", "number", "simple label"),
assay_names = NULL,
cutoff_names = NULL,
label_cex = 1,
arrow_ex = NULL,
flip_twoway = FALSE,
colorset = NULL,
twoway_lwd = 5,
extend_ex = 0.5,
extend_angle = 10,
bump_factor = 1,
group_buffer = 0.02,
group_border = "grey65",
group_fill = "grey95",
replicate_color = "grey40",
replicate_cex = 0.8,
do_plot = TRUE,
plot_margins = c(0.1, 0.1, 0.1, 0.1),
plot_type = c("base", "grid"),
verbose = FALSE,
debug = FALSE,
...
)
sedesign |
|
se |
|
factor_names |
|
factor_sep |
|
contrast_sep |
|
axis1 , axis2 , axis3 , axis4 |
|
which_contrasts |
one of the following:
When a two-way contrast is defined, its component one-way contrasts are also included. |
contrast_style |
|
contrast_labels |
|
oneway_position , twoway_position |
|
contrast_position |
|
contrast_depths |
|
sestats |
|
sestats_style |
|
assay_names , cutoff_names |
|
label_cex |
|
arrow_ex |
|
flip_twoway |
|
colorset |
|
twoway_lwd |
|
extend_ex |
|
extend_angle |
|
bump_factor |
|
group_buffer |
|
group_border , group_fill |
|
replicate_color |
|
replicate_cex |
|
do_plot |
|
plot_margins |
|
plot_type |
|
verbose |
|
debug |
|
... |
additional arguments are ignored. |
contrast |
|
TODO:
Mostly done: Confirm functionality with different combinations of axis values.
Confirm functionality with only one factor on one axis.
Adjust drawing order:
Group contrasts into sets of two-way contrasts which share any one one-way contrast with each other. This group should be drawn together as a set, to minimize weird effects of overlaps.
Do not draw a one-way contrast independently when it is already being rendered as part of a two-way contrast.
Implement method to assign colors to contrasts.
Simplest option: Allow color_sub
whose names match values in
contrast_names(sedesign)
.
Next potential option: Use color_sub
to match each group name,
then define either solid color from colorjam::blend_colors()
, or
using a color gradient for each one-way block arrow.
Two-way connectors use the first contrast end color, and second contrast start color as a gradient.
If colors are not defined per group, call design2colors()
?
DONE. Confirm/implement method to display fewer factors on axes than are present in the underlying group labels.
Improve location of axis labels - currently uses jamba::groupedAxis()
however they appear too distant from the figure itself.
Determine method to "recognize" factor order from colData(se)
.
Simplest option is to use argument factor_names
to match
colnames(colData(se))
(when supplied) and use that to define
factor order.
One option is to update group_to_sedesign()
so it stores the
factor design data as a data.frame
with proper factor level order.
This update could also benefit platjam::design2colors()
by
informing the necessary colData()
colnames to use.
A simpler option is to update sedesign
to include
colnames(colData(se))
as a character
vector, without having to store
the full data.frame
. It would requiring passing both the
sedesign
and se
objects together.
Another option is to require colnames(colData(se))
to match
the order in the group names defined in colnames(sedesign@design)
.
DONE. implement block arrows functions for improved quality output.
consider grid
graphics (package vwline
) or ggplot2
output.
implement sensible method to display a subset of one-way or two-way contrasts. For example, two-way contrasts are easier to see when showing only a subset, perhaps only along one common axis.
Consider implementing gradient colors for block arrows.
This enhancement requires changing block arrow from one polygon to a list of polygons, so each smaller polygon has its own color from the color gradient.
Two-way contrasts:
Handle two-way contrasts for which the one-way contrasts may not also be defined.
Change drawing order so the one-way block arrow label is not overdrawn by the two-way connector.
This step probably requires grouping one-way and two-way contrasts so that for each two-way contrast, each one-way contrast is drawn, then the two-way connector, then the one-way labels.
Probably need helper function draw_twoway_contrast()
which calls draw_oneway_contrast()
, draw_twoway_connector()
,
and draw_oneway_label()
. The one-way steps can be "skipped".
To be "fancy", when a one-way contrast would be rendered multiple times, the rendering should be "skipped" and rendered only the last time, so the label would always be rendered after the incoming two-way connector, and so the one-way contrast (and its label) would only need to be rendered once overall.
invisible list
of data.frame
representing individual
contrasts to be rendered. Mainly useful for reviewing the
data used to produce the figure.
Other jam experiment design:
check_sedesign()
,
contrast2comp()
,
contrast_colors_by_group()
,
contrast_names_to_sedesign()
,
contrasts_to_factors()
,
contrasts_to_venn_setlists()
,
draw_oneway_contrast()
,
draw_twoway_contrast()
,
filter_contrast_names()
,
groups_to_sedesign()
,
sedesign_to_factors()
,
validate_sedesign()
isamples_1 <- paste0(
rep(c("DMSO", "Etop", "DMSO", "Etop"), each=6),
"_",
rep(c("NF", "Flag"), each=12),
"_",
rep(c("WT", "KO", "WT", "KO", "WT", "D955N", "WT", "D955N"), each=3),
"_",
LETTERS[1:3])
# simple data.frame with group information
idf <- data.frame(jamba::rbindList(strsplit(isamples_1, "_")))[,1:3]
rownames(idf) <- isamples_1;
# convert to sedesign
sedesign_1 <- groups_to_sedesign(idf)
# plot the contrasts
plot_sedesign(sedesign_1)
# re-order the factors along each axis
plot_sedesign(sedesign_1, axis1=1, axis2=3, axis3=2)
# flip the group ordering for two-way contrasts
# (These are mathematically equivalent, but shown in flipped orientation)
plot_sedesign(sedesign_1, axis1=1, axis2=3, axis3=2, flip_twoway=TRUE)
# plot only the two-way contrasts
is_twoway <- grepl("[(]", contrast_names(sedesign_1))
plot_sedesign(sedesign_1, which_contrasts=which(is_twoway),
axis1=1, axis2=3, axis3=2)
group_names <- paste0(
rep(c("DMSO", "Etop"), each=4),
"_",
rep(c("NF", "Flag"), each=2),
"_",
rep(c("WT", "KO"), 4))
sedesign <- groups_to_sedesign(group_names)
plot_sedesign(sedesign)
# plot only the two-way contrasts
is_twoway <- grepl("[(]", contrast_names(sedesign))
plot_sedesign(sedesign, which_contrasts=which(is_twoway),
axis1=1, axis2=3, axis3=2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.