Title: | Useful Functions for Visualization |
---|---|
Description: | In ancient Roman mythology, 'Pluto' was the ruler of the underworld and presides over the afterlife. 'Pluto' was frequently conflated with 'Plutus', the god of wealth, because mineral wealth was found underground. When plotting with R, you try once, twice, practice again and again, and finally you get a pretty figure you want. It's a 'plot tour', a tour about repetition and reward. Hope 'plutor' helps you on the tour! |
Authors: | William Song [aut, cre] |
Maintainer: | William Song <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-20 04:30:51 UTC |
Source: | https://github.com/william-swl/plutor |
scale_color_identity()
assign colors by a column in a tibble, for the convenience to
use scale_color_identity()
assign_colors(df, by, colors = sci_colors("npg", 10), na = "#F5F5F5")
assign_colors(df, by, colors = sci_colors("npg", 10), na = "#F5F5F5")
df |
tibble |
by |
assign colors according to this column |
colors |
a vector of color values |
na |
if colors are not enough, fill na values |
tibble
assign_colors(mini_diamond, cut, colors = sci_colors("nejm", 8))
assign_colors(mini_diamond, cut, colors = sci_colors("nejm", 8))
colors of nucleotides and amino acids
bioletter_colors
bioletter_colors
bioletter_colors
colors for biological letters like amino acids or nucleotides
according to the print format
RColorBrewer
package presetsselect colors from RColorBrewer
package presets
brewer_colors(name, n = 3, ...)
brewer_colors(name, n = 3, ...)
name |
presets name |
n |
number of colors |
... |
other arguments of |
colors
brewer_colors("Blues", 5)
brewer_colors("Blues", 5)
width and height of built-in canvas
canvas_size
canvas_size
canvas_size
canvas sizes list
according to the print format
trans cm to inch
cm2inch(x)
cm2inch(x)
x |
cm value |
inch value
cm2inch(1)
cm2inch(1)
trans cm to pt
cm2pt(x)
cm2pt(x)
x |
cm value |
pt value
cm2pt(1)
cm2pt(1)
geom_compare
from a ggplot
objectextract the result of geom_compare
from a ggplot
object
extract_compare(p)
extract_compare(p)
p |
ggplot object |
compare tibble
add p value and fold change on a plot
geom_compare( mapping = NULL, data = NULL, stat = "compare", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, lab_pos = NULL, step_increase = 0.1, tip_length = 0.02, lineend = "round", cp_label = c("psymbol"), ns_lineheight_just = 0.2, ignore_ns = FALSE, fc_method = NULL, comparisons = NULL, paired = FALSE, alternative = "two.sided", test_method = "wilcoxon", ns_symbol = "NS", cp_ref = NULL, cp_inline = FALSE, brackets_widen = 0, fc_digits = 2, cp_result = NULL, cp_manual = NULL )
geom_compare( mapping = NULL, data = NULL, stat = "compare", position = "identity", ..., na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, lab_pos = NULL, step_increase = 0.1, tip_length = 0.02, lineend = "round", cp_label = c("psymbol"), ns_lineheight_just = 0.2, ignore_ns = FALSE, fc_method = NULL, comparisons = NULL, paired = FALSE, alternative = "two.sided", test_method = "wilcoxon", ns_symbol = "NS", cp_ref = NULL, cp_inline = FALSE, brackets_widen = 0, fc_digits = 2, cp_result = NULL, cp_manual = NULL )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
... |
Other arguments passed on to |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
lab_pos |
position of the label brackets |
step_increase |
the increase height for next bracket, a ratio according to the whole panel height |
tip_length |
the length for tips at the ends of the brackets, a ratio according to the whole panel height |
lineend |
Line end style (round, butt, square). |
cp_label |
which values will be add on the plot, a character vector
with some of |
ns_lineheight_just |
if show |
ignore_ns |
if |
fc_method |
fold change method, default is |
comparisons |
a list of two-element vector, to assign the comparisons should be performed |
paired |
paired test or not, |
alternative |
one of |
test_method |
|
ns_symbol |
the symbol of non-significant, |
cp_ref |
reference item, the others will be compared with it |
cp_inline |
draw in line or not, default is |
brackets_widen |
widen the brackets, can be a negative value |
fc_digits |
fold change digits |
cp_result |
comparation result tibble |
cp_manual |
manual comparisons table,
please refer to |
ggplot
object
The describe geom is used to create description values plot, including center symbol and error symbol. The center symbol can be mean, median or other custom functions, the error symbol can be sd, quantile or other custom functions.
geom_describe( mapping = NULL, data = NULL, stat = "describe", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, lineend = "round", show_error = TRUE, center_symbol = "bar", center_width = 0.3, error_width = 0.2, center_func = mean, low_func = function(x, na.rm) { mean(x, na.rm = na.rm) - sd(x, na.rm = na.rm) }, high_func = function(x, na.rm) { mean(x, na.rm = na.rm) + sd(x, na.rm = na.rm) }, ... )
geom_describe( mapping = NULL, data = NULL, stat = "describe", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, lineend = "round", show_error = TRUE, center_symbol = "bar", center_width = 0.3, error_width = 0.2, center_func = mean, low_func = function(x, na.rm) { mean(x, na.rm = na.rm) - sd(x, na.rm = na.rm) }, high_func = function(x, na.rm) { mean(x, na.rm = na.rm) + sd(x, na.rm = na.rm) }, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
lineend |
Line end style (round, butt, square). |
show_error |
show error symbol |
center_symbol |
one of |
center_width |
if |
error_width |
the width of the error bar |
center_func |
the center function, |
low_func |
the low error function, |
high_func |
the high error function, |
... |
Other arguments passed on to |
ggplot
object
geom2trace.GeomCompare
geom2trace.GeomCompare(data, params, plot)
geom2trace.GeomCompare(data, params, plot)
data , params , plot
|
params |
no return value
geom2trace.GeomDescribe
geom2trace.GeomDescribe(data, params, plot)
geom2trace.GeomDescribe(data, params, plot)
data , params , plot
|
params |
no return value
GeomCompare
GeomCompare
GeomCompare
An object of class GeomCompare
(inherits from Geom
, ggproto
, gg
) of length 6.
GeomDescribe
GeomDescribe
GeomDescribe
An object of class GeomDescribe
(inherits from Geom
, ggproto
, gg
) of length 5.
generate gradient colors
gradient_colors(x, n)
gradient_colors(x, n)
x |
colors |
n |
number of colors to output |
gradient colors
gradient_colors(c("blue", "red"), 10)
gradient_colors(c("blue", "red"), 10)
trans inch to cm
inch2cm(x) in2cm(x) cm2in(x)
inch2cm(x) in2cm(x) cm2in(x)
x |
inch value |
cm value
inch2cm(1)
inch2cm(1)
trans inch to mm
inch2mm(x) in2mm(x)
inch2mm(x) in2mm(x)
x |
inch value |
mm value
inch2mm(1)
inch2mm(1)
trans geom line point and theme line point to the real point
lpt(x)
lpt(x)
x |
line point in geom or theme |
real point
lpt(1)
lpt(1)
Minimal tibble dataset adjusted from diamond
mini_diamond
mini_diamond
mini_diamond
A data frame with 100 rows and 7 columns:
unique id
2 category variables
4 continuous variables
...
adjusted from ggplot2
trans mm to inch
mm2inch(x) mm2in(x)
mm2inch(x) mm2in(x)
x |
mm value |
inch value
mm2inch(1)
mm2inch(1)
trans mm to pt
mm2pt(x)
mm2pt(x)
x |
mm value |
pt value
mm2pt(1)
mm2pt(1)
set size, resolution and default theme
pl_init( width = 4, height = 3, res = 300, w = NULL, h = NULL, theme = theme_pl() )
pl_init( width = 4, height = 3, res = 300, w = NULL, h = NULL, theme = theme_pl() )
width |
width |
height |
height |
res |
resolution, 300 as default |
w |
alias of width |
h |
alias of height |
theme |
default theme |
no return value
pl_init()
pl_init()
save plot, support save into a blank canvas
pl_save( plot, filename, width, height, units = "in", canvas = NULL, canvas_pos_x = 0.5, canvas_pos_y = 0.1, ... )
pl_save( plot, filename, width, height, units = "in", canvas = NULL, canvas_pos_x = 0.5, canvas_pos_y = 0.1, ... )
plot |
ggplot object |
filename |
filename |
width |
plot width |
height |
plot height |
units |
units, 'in' for inch as default. Can be 'in', 'cm' |
canvas |
|
canvas_pos_x |
from 0 to 1, the horizontal position of plot in canvas |
canvas_pos_y |
from 0 to 1, the vertical position of plot in canvas |
... |
other arguments from |
no return value
set repr size and resolution
pl_size(width = 4, height = 3, res = 300, w = NULL, h = NULL)
pl_size(width = 4, height = 3, res = 300, w = NULL, h = NULL)
width |
width |
height |
height |
res |
resolution, 300 as default |
w |
alias of width |
h |
alias of height |
no return value
pl_size(width = 3, height = 2)
pl_size(width = 3, height = 2)
plot colors
plot_colors(x, ncol = 10, show_name = TRUE)
plot_colors(x, ncol = 10, show_name = TRUE)
x |
color values |
ncol |
color number of each row |
show_name |
use vector names as label, |
ggplot object
plot_colors(gradient_colors(c("blue", "red"), 10))
plot_colors(gradient_colors(c("blue", "red"), 10))
a new Position object to create float x position
position_floatxPL(float = -0.05, cycle = 2)
position_floatxPL(float = -0.05, cycle = 2)
float |
float range, a ratio according to the whole panel height |
cycle |
float cycle |
Position object
a new Position object to create float y position
position_floatyPL(float = -0.05, cycle = 2)
position_floatyPL(float = -0.05, cycle = 2)
float |
float range, a ratio according to the whole panel height |
cycle |
float cycle |
Position object
PositionFloatxPL
PositionFloatxPL
PositionFloatxPL
An object of class PositionFloatxPL
(inherits from Position
, ggproto
, gg
) of length 4.
PositionFloatyPL
PositionFloatyPL
PositionFloatyPL
An object of class PositionFloatyPL
(inherits from Position
, ggproto
, gg
) of length 4.
trans pt to cm
pt2cm(x)
pt2cm(x)
x |
pt value |
cm value
pt2cm(1)
pt2cm(1)
trans pt to mm
pt2mm(x)
pt2mm(x)
x |
pt value |
mm value
pt2mm(1)
pt2mm(1)
revert the position scale transformation
revert_pos_scale(s)
revert_pos_scale(s)
s |
ScaleContinuousPosition object, e.g. scales$y in compute_group() |
function
scale element according to a vector of element scales
scale_ele(level, base, ele_scales)
scale_ele(level, base, ele_scales)
level |
output level |
base |
value of base level |
ele_scales |
vector of element scales |
value of output level
scale_ele(level = 2, base = 5, ele_scales = c(1, 2))
scale_ele(level = 2, base = 5, ele_scales = c(1, 2))
scale_x_continuous()
to show axis minor breaksA variant of scale_x_continuous()
to show axis minor breaks
scale_x_continuous_pl( name = waiver(), breaks = waiver(), minor_breaks = NULL, n.breaks = NULL, labels = waiver(), limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = "identity", guide = ggh4x::guide_axis_minor(), position = "bottom", sec.axis = waiver(), show_minor_breaks = TRUE, minor_break_step = NULL )
scale_x_continuous_pl( name = waiver(), breaks = waiver(), minor_breaks = NULL, n.breaks = NULL, labels = waiver(), limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = "identity", guide = ggh4x::guide_axis_minor(), position = "bottom", sec.axis = waiver(), show_minor_breaks = TRUE, minor_break_step = NULL )
name |
The name of the scale. Used as the axis or legend title. If
|
breaks |
One of:
|
minor_breaks |
One of:
|
n.breaks |
An integer guiding the number of major breaks. The algorithm
may choose a slightly different number to ensure nice break labels. Will
only have an effect if |
labels |
One of:
|
limits |
One of:
|
expand |
use |
oob |
use |
na.value |
Missing values will be replaced with this value. |
trans |
For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". A transformation object bundles together a transform, its inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
guide |
A function used to create a guide or its name. See
|
position |
For position scales, The position of the axis.
|
sec.axis |
|
show_minor_breaks |
show minor breaks or not |
minor_break_step |
the step of minor breaks |
scale object
scale_x_log10()
to show axis minor breaks and
better axis labelsA variant of scale_x_log10()
to show axis minor breaks and
better axis labels
scale_x_log10_pl( name = waiver(), breaks = NULL, minor_breaks = NULL, n.breaks = NULL, labels = NULL, limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = scales::log10_trans(), guide = ggh4x::guide_axis_minor(), position = "bottom", sec.axis = waiver(), show_minor_breaks = TRUE )
scale_x_log10_pl( name = waiver(), breaks = NULL, minor_breaks = NULL, n.breaks = NULL, labels = NULL, limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = scales::log10_trans(), guide = ggh4x::guide_axis_minor(), position = "bottom", sec.axis = waiver(), show_minor_breaks = TRUE )
name |
The name of the scale. Used as the axis or legend title. If
|
breaks |
One of:
|
minor_breaks |
One of:
|
n.breaks |
An integer guiding the number of major breaks. The algorithm
may choose a slightly different number to ensure nice break labels. Will
only have an effect if |
labels |
One of:
|
limits |
One of:
|
expand |
use |
oob |
use |
na.value |
Missing values will be replaced with this value. |
trans |
For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". A transformation object bundles together a transform, its inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
guide |
A function used to create a guide or its name. See
|
position |
For position scales, The position of the axis.
|
sec.axis |
|
show_minor_breaks |
show minor breaks or not |
scale object
scale_y_continuous()
to show axis minor breaksA variant of scale_y_continuous()
to show axis minor breaks
scale_y_continuous_pl( name = waiver(), breaks = waiver(), minor_breaks = NULL, n.breaks = NULL, labels = waiver(), limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = "identity", guide = ggh4x::guide_axis_minor(), position = "left", sec.axis = waiver(), show_minor_breaks = TRUE, minor_break_step = NULL )
scale_y_continuous_pl( name = waiver(), breaks = waiver(), minor_breaks = NULL, n.breaks = NULL, labels = waiver(), limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = "identity", guide = ggh4x::guide_axis_minor(), position = "left", sec.axis = waiver(), show_minor_breaks = TRUE, minor_break_step = NULL )
name |
The name of the scale. Used as the axis or legend title. If
|
breaks |
One of:
|
minor_breaks |
One of:
|
n.breaks |
An integer guiding the number of major breaks. The algorithm
may choose a slightly different number to ensure nice break labels. Will
only have an effect if |
labels |
One of:
|
limits |
One of:
|
expand |
use |
oob |
use |
na.value |
Missing values will be replaced with this value. |
trans |
For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". A transformation object bundles together a transform, its inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
guide |
A function used to create a guide or its name. See
|
position |
For position scales, The position of the axis.
|
sec.axis |
|
show_minor_breaks |
show minor breaks or not |
minor_break_step |
the step of minor breaks |
scale object
scale_y_log10()
to show axis minor breaks
and better axis labelsA variant of scale_y_log10()
to show axis minor breaks
and better axis labels
scale_y_log10_pl( name = waiver(), breaks = NULL, minor_breaks = NULL, n.breaks = NULL, labels = NULL, limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = scales::log10_trans(), guide = ggh4x::guide_axis_minor(), position = "left", sec.axis = waiver(), show_minor_breaks = TRUE )
scale_y_log10_pl( name = waiver(), breaks = NULL, minor_breaks = NULL, n.breaks = NULL, labels = NULL, limits = NULL, expand = ggplot2::expansion(), oob = scales::oob_keep, na.value = NA_real_, trans = scales::log10_trans(), guide = ggh4x::guide_axis_minor(), position = "left", sec.axis = waiver(), show_minor_breaks = TRUE )
name |
The name of the scale. Used as the axis or legend title. If
|
breaks |
One of:
|
minor_breaks |
One of:
|
n.breaks |
An integer guiding the number of major breaks. The algorithm
may choose a slightly different number to ensure nice break labels. Will
only have an effect if |
labels |
One of:
|
limits |
One of:
|
expand |
use |
oob |
use |
na.value |
Missing values will be replaced with this value. |
trans |
For continuous scales, the name of a transformation object or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "date", "exp", "hms", "identity", "log", "log10", "log1p", "log2", "logit", "modulus", "probability", "probit", "pseudo_log", "reciprocal", "reverse", "sqrt" and "time". A transformation object bundles together a transform, its inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
guide |
A function used to create a guide or its name. See
|
position |
For position scales, The position of the axis.
|
sec.axis |
|
show_minor_breaks |
show minor breaks or not |
scale object
ggsci
package presetsselect colors from ggsci
package presets
sci_colors(name, n = 3, alpha = 1)
sci_colors(name, n = 3, alpha = 1)
name |
presets name |
n |
number of colors |
alpha |
alpha |
colors
sci_colors("npg", 5)
sci_colors("npg", 5)
StatCompare
StatCompare
StatCompare
An object of class StatCompare
(inherits from Stat
, ggproto
, gg
) of length 6.
StatCountPL
StatCountPL
StatCountPL
An object of class StatCountPL
(inherits from Stat
, ggproto
, gg
) of length 4.
StatDescribe
StatDescribe
StatDescribe
An object of class StatDescribe
(inherits from Stat
, ggproto
, gg
) of length 4.
StatFuncPL
StatFuncPL
StatFuncPL
An object of class StatFuncPL
(inherits from Stat
, ggproto
, gg
) of length 4.
StatMeanPL
StatMeanPL
StatMeanPL
An object of class StatMeanPL
(inherits from Stat
, ggproto
, gg
) of length 4.
a new extensible theme
theme_pl( base_size = 10, base_line_size = lpt(base_size/10), base_rect_size = lpt(1), size_scales = c(5, 6, 7), margin_factor = 0.25, plot_margin_factor = 0.5, legend_spacing_factor = 1.2, font_family = "", ... )
theme_pl( base_size = 10, base_line_size = lpt(base_size/10), base_rect_size = lpt(1), size_scales = c(5, 6, 7), margin_factor = 0.25, plot_margin_factor = 0.5, legend_spacing_factor = 1.2, font_family = "", ... )
base_size |
base size of fonts and margins |
base_line_size |
base linewidth |
base_rect_size |
base linewidth of the rectangles |
size_scales |
a vector of element size scales, namely:
|
margin_factor |
factor to adjust the element margins according to size_scales |
plot_margin_factor |
factor to adjust the plot margins according to
|
legend_spacing_factor |
factor to adjust the space of legend items
according to |
font_family |
font family |
... |
arguments from ggplot2::theme() |
theme object of ggplot
theme_pl()
theme_pl()
a blank theme
theme_pl0(...)
theme_pl0(...)
... |
arguments of theme_pl() |
theme object of ggplot
theme_pl0()
theme_pl0()
trans geom text or point to the real point
tpt(x) ppt(x)
tpt(x) ppt(x)
x |
text point in geom |
real point
tpt(1)
tpt(1)
perform the position scale transformation
trans_pos_scale(s)
trans_pos_scale(s)
s |
ScaleContinuousPosition object, e.g. scales$y in compute_group() |
function