Title: | Some Useful Functions for Statistics and Visualization |
---|---|
Description: | Offers a range of utilities and functions for everyday programming tasks. 1.Data Manipulation. Such as grouping and merging, column splitting, and character expansion. 2.File Handling. Read and convert files in popular formats. 3.Plotting Assistance. Helpful utilities for generating color palettes, validating color formats, and adding transparency. 4.Statistical Analysis. Includes functions for pairwise comparisons and multiple testing corrections, enabling perform statistical analyses with ease. 5.Graph Plotting, Provides efficient tools for creating doughnut plot and multi-layered doughnut plot; Venn diagrams, including traditional Venn diagrams, upset plots, and flower plots; Simplified functions for creating stacked bar plots, or a box plot with alphabets group for multiple comparison group. |
Authors: | Chen Peng [aut, cre] |
Maintainer: | Chen Peng <[email protected]> |
License: | GPL-3 |
Version: | 0.2.7 |
Built: | 2024-11-21 05:39:20 UTC |
Source: | https://github.com/asa12138/pcutils |
Add alpha for a Rcolor
add_alpha(color, alpha = 0.3)
add_alpha(color, alpha = 0.3)
color |
Rcolor |
alpha |
alpha, default 0.3 |
8 hex color
add_alpha("red", 0.3)
add_alpha("red", 0.3)
Add an analysis for a project
add_analysis(analysis_n, title = analysis_n, pro_dir = getwd())
add_analysis(analysis_n, title = analysis_n, pro_dir = getwd())
analysis_n |
analysis name |
title |
Rmd file title |
pro_dir |
project directory, default is current directory |
No return value
Add a global gg_theme and colors for plots
add_theme(set_theme = NULL)
add_theme(set_theme = NULL)
set_theme |
your theme |
No return value
add_theme()
add_theme()
Change factor levels
change_fac_lev(x, levels = NULL, last = FALSE)
change_fac_lev(x, levels = NULL, last = FALSE)
x |
vector |
levels |
custom levels |
last |
put the custom levels to the last |
factor
change_fac_lev(letters[1:5], levels = c("c", "a"))
change_fac_lev(letters[1:5], levels = c("c", "a"))
Plot china map
china_map(china_shp = NULL, download_dir = "pcutils_temp", text_param = NULL)
china_map(china_shp = NULL, download_dir = "pcutils_temp", text_param = NULL)
china_shp |
china.json file |
download_dir |
download_dir, "pcutils_temp" |
text_param |
parameters parse to |
a ggplot
Copy a data.frame
copy_df(df)
copy_df(df)
df |
a R data.frame object |
No return value
Copy a vector
copy_vector(vec)
copy_vector(vec)
vec |
a R vector object |
No return value
Plot correlation
cor_plot( env, env2 = NULL, geom = ggcor::geom_square, mode = 1, method = "pearson", mode_param = NULL, colors = get_cols(pal = "bluered")[2:10] )
cor_plot( env, env2 = NULL, geom = ggcor::geom_square, mode = 1, method = "pearson", mode_param = NULL, colors = get_cols(pal = "bluered")[2:10] )
env |
dataframe1 |
env2 |
dataframe2 (default:NULL) |
geom |
geom, default: |
mode |
plot mode (1~4) |
method |
one of "pearson","kendall","spearman" |
mode_param |
parameters parse to |
colors |
color, default is |
ggplot
if (interactive()) { data(otutab) cor_plot(metadata[, 3:10]) cor_plot(metadata[, 3:10], mode = 2) cor_plot(metadata[, 3:10], mode = 3) cor_plot(t(otutab)[, 1:50], mode = 4) }
if (interactive()) { data(otutab) cor_plot(metadata[, 3:10]) cor_plot(metadata[, 3:10], mode = 2) cor_plot(metadata[, 3:10], mode = 3) cor_plot(t(otutab)[, 1:50], mode = 4) }
uniq -c
in shell to count a vectorLike uniq -c
in shell to count a vector
count2(df)
count2(df)
df |
two columns: first is type, second is number |
two columns: first is type, second is number
count2(data.frame(group = c("A", "A", "B", "C", "C", "A"), value = c(2, 2, 2, 1, 3, 1)))
count2(data.frame(group = c("A", "A", "B", "C", "C", "A"), value = c(2, 2, 2, 1, 3, 1)))
Print some message with =
dabiao( str = "", ..., n = 80, char = "=", mode = c("middle", "left", "right"), print = FALSE )
dabiao( str = "", ..., n = 80, char = "=", mode = c("middle", "left", "right"), print = FALSE )
str |
output strings |
... |
strings will be paste together |
n |
the number of output length |
char |
side chars default:= |
mode |
"middle", "left" or "right" |
print |
print or message? |
No return value
dabiao("Start running!")
dabiao("Start running!")
Detach packages
del_ps(p_list, ..., origin = NULL)
del_ps(p_list, ..., origin = NULL)
p_list |
a vector of packages list |
... |
packages |
origin |
keep the original Namespace |
No return value
This function converts a data frame with three columns (from, to, count) into a distance matrix. The rows and columns of the matrix are all unique names from the 'from' and 'to' columns, and the matrix values are filled with counts.
df2distance(data)
df2distance(data)
data |
A data frame containing three columns: from, to, count. |
A distance matrix where rows and columns are all unique names from 'from' and 'to' columns.
data <- data.frame( from = c("A", "A", "B", "D"), to = c("B", "C", "A", "B"), count = c(1, 2, 3, 4) ) df2distance(data)
data <- data.frame( from = c("A", "A", "B", "D"), to = c("B", "C", "A", "B"), count = c(1, 2, 3, 4) ) df2distance(data)
df to link table
df2link(test, fun = sum)
df2link(test, fun = sum)
test |
df with at least 3 columns |
fun |
function to summary the elements number, defalut: |
data.frame
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, ] -> test df2link(test)
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, ] -> test df2link(test)
This function converts a distance matrix into a data frame with three columns: from, to, count. The rows and columns of the matrix are all unique names from the 'from' and 'to' columns,
distance2df(distance_matrix)
distance2df(distance_matrix)
distance_matrix |
A distance matrix where rows and columns are all unique names from 'from' and 'to' columns. |
A data frame containing three columns: from, to, count.
distance_matrix <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7, 8), nrow = 3) distance2df(distance_matrix)
distance_matrix <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7, 8), nrow = 3) distance2df(distance_matrix)
This function downloads specific genomic files from NCBI's FTP server based on the provided accession number. It supports downloading different types of files, or the entire directory containing the files.
download_ncbi_genome_file( accession, out_dir = ".", type = "gff", file_suffix = NULL, timeout = 300 )
download_ncbi_genome_file( accession, out_dir = ".", type = "gff", file_suffix = NULL, timeout = 300 )
accession |
A character string representing the NCBI accession number (e.g., "GCF_001036115.1_ASM103611v1" or "GCF_001036115.1"). The accession can start with "GCF" or "GCA". |
out_dir |
A character string representing the directory where the downloaded files will be saved. Defaults to the current working directory ("."). |
type |
A character string representing the type of file to download. Supported types are "all", "gff", "fna". If "all" is specified, the function will prompt the user to use command line tools to download the entire directory. Defaults to "gff". |
file_suffix |
A character string representing the specific file suffix to download.
If specified, this will override the |
timeout |
A numeric value representing the maximum time in seconds to wait for the download. Defaults to 300. |
If the provided accession
does not contain the version suffix (e.g., "GCF_001036115.1"),
the function will query the NCBI FTP server to determine the full accession name.
When type
is set to "all", the function cannot download the entire directory
directly but provides a command line example for the user to download the directory
using tools like wget
.
No value
## Not run: download_ncbi_genome_file("GCF_001036115.1", out_dir = "downloads", type = "gff") download_ncbi_genome_file("GCF_001036115.1", out_dir = "downloads", file_suffix = "_genomic.fna.gz") ## End(Not run)
## Not run: download_ncbi_genome_file("GCF_001036115.1", out_dir = "downloads", type = "gff") download_ncbi_genome_file("GCF_001036115.1", out_dir = "downloads", file_suffix = "_genomic.fna.gz") ## End(Not run)
This function downloads a file from the provided URL and saves it to the specified location.
download2(url, file_path, timeout = 300, force = FALSE, proxy = FALSE, ...)
download2(url, file_path, timeout = 300, force = FALSE, proxy = FALSE, ...)
url |
The URL from which to download the file. |
file_path |
The full path to the file. |
timeout |
timeout, 300s |
force |
FALSE, if TRUE, overwrite existed file |
proxy |
use proxy, default is FALSE |
... |
add |
No value
Explode a data.frame if there are split charter in one column
explode(df, column, split = ",")
explode(df, column, split = ",")
df |
data.frame |
column |
column |
split |
split string |
data.frame
df <- data.frame(a = 1:2, b = c("a,b", "c"), c = 3:4) explode(df, "b", ",")
df <- data.frame(a = 1:2, b = c("a,b", "c"), c = 3:4) explode(df, "b", ",")
Fit a distribution
fittest(a)
fittest(a)
a |
a numeric vector |
distribution
Generate labels position
generate_labels( labels = NULL, input = c(0, 0), nrows = NULL, ncols = NULL, x_offset = 0.3, y_offset = 0.15, just = 1 )
generate_labels( labels = NULL, input = c(0, 0), nrows = NULL, ncols = NULL, x_offset = 0.3, y_offset = 0.15, just = 1 )
labels |
labels |
input |
c(0,0) |
nrows |
default: NULL |
ncols |
default: NULL |
x_offset |
0.3 |
y_offset |
0.15 |
just |
0~5 |
matrix
library(ggplot2) labels <- vapply(1:8, \(i)paste0(sample(LETTERS, 4), collapse = ""), character(1)) df <- data.frame(label = labels, generate_labels(labels)) ggplot(data = df) + geom_label(aes(x = X1, y = X2, label = label))
library(ggplot2) labels <- vapply(1:8, \(i)paste0(sample(LETTERS, 4), collapse = ""), character(1)) df <- data.frame(label = labels, generate_labels(labels)) ggplot(data = df) + geom_label(aes(x = X1, y = X2, label = label))
Get n colors
get_cols(n = 11, pal = NULL, n_break = 5)
get_cols(n = 11, pal = NULL, n_break = 5)
n |
how many colors you need |
pal |
"col1", "col2", "col3"; or a vector of colors, you can get from: |
n_break |
default: 5 |
a vector of n colors
get_cols(10, "col2") -> my_cols scales::show_col(my_cols) scales::show_col(get_cols(15, RColorBrewer::brewer.pal(5, "Set2")))
get_cols(10, "col2") -> my_cols scales::show_col(my_cols) scales::show_col(get_cols(15, RColorBrewer::brewer.pal(5, "Set2")))
Heatmap by ggplot
ggheatmap( otutab, pal = NULL, scale = "none", rowname = TRUE, colname = TRUE, tile_params = list(), row_cluster = FALSE, col_cluster = FALSE, row_annotation = NULL, col_annotation = NULL, annotation_pal = NULL )
ggheatmap( otutab, pal = NULL, scale = "none", rowname = TRUE, colname = TRUE, tile_params = list(), row_cluster = FALSE, col_cluster = FALSE, row_annotation = NULL, col_annotation = NULL, annotation_pal = NULL )
otutab |
otutab |
pal |
the main color pal, a vector of colors |
scale |
"none", "row", "column" |
rowname |
show row names? |
colname |
show column names? |
tile_params |
tile_params parsed to |
row_cluster |
cluster the row? |
col_cluster |
cluster the column? |
row_annotation |
row annotation |
col_annotation |
column annotation |
annotation_pal |
the annotation color pal, a list. e.g. list(Group=c("red","blue")) |
a ggplot
if (interactive()) { data(otutab) ggheatmap(otutab[1:30, ], scale = "row", row_annotation = otutab[1:30, 1:2], col_annotation = metadata[, c(2, 4)] ) }
if (interactive()) { data(otutab) ggheatmap(otutab[1:30, ], scale = "row", row_annotation = otutab[1:30, 1:2], col_annotation = metadata[, c(2, 4)] ) }
gg histogram
gghist(x, text_pos = c(0.8, 0.8), ...)
gghist(x, text_pos = c(0.8, 0.8), ...)
x |
vector |
text_pos |
text postion, default is c(0.8, 0.8) |
... |
parameters parse to |
ggplot
if (requireNamespace("ggpubr")) { gghist(rnorm(100)) }
if (requireNamespace("ggpubr")) { gghist(rnorm(100)) }
Plot a doughnut chart
gghuan( tab, reorder = TRUE, mode = "1", topN = 5, name = TRUE, percentage = TRUE, bar_params = NULL, text_params = NULL, text_params2 = NULL )
gghuan( tab, reorder = TRUE, mode = "1", topN = 5, name = TRUE, percentage = TRUE, bar_params = NULL, text_params = NULL, text_params2 = NULL )
tab |
two columns: first is type, second is number |
reorder |
reorder by number? |
mode |
plot style, 1~3 |
topN |
plot how many top items |
name |
label the name |
percentage |
label the percentage |
bar_params |
parameters parse to |
text_params |
parameters parse to |
text_params2 |
parameters parse to |
a ggplot
a <- data.frame(type = letters[1:6], num = c(1, 3, 3, 4, 5, 10)) gghuan(a) + scale_fill_pc() gghuan(a, bar_params = list(col = "black"), text_params = list(col = "#b15928", size = 3), text_params2 = list(col = "#006d2c", size = 5) ) + scale_fill_pc() gghuan(a, mode = 2) + scale_fill_pc() gghuan(a, mode = 3) + scale_fill_pc()
a <- data.frame(type = letters[1:6], num = c(1, 3, 3, 4, 5, 10)) gghuan(a) + scale_fill_pc() gghuan(a, bar_params = list(col = "black"), text_params = list(col = "#b15928", size = 3), text_params2 = list(col = "#006d2c", size = 5) ) + scale_fill_pc() gghuan(a, mode = 2) + scale_fill_pc() gghuan(a, mode = 3) + scale_fill_pc()
gghuan2 for multi-doughnut chart
gghuan2( tab = NULL, huan_width = 1, circle_width = 1, space_width = 0.2, circle_label = NULL, name = TRUE, percentage = FALSE, text_params = NULL, circle_label_params = NULL, bar_params = NULL )
gghuan2( tab = NULL, huan_width = 1, circle_width = 1, space_width = 0.2, circle_label = NULL, name = TRUE, percentage = FALSE, text_params = NULL, circle_label_params = NULL, bar_params = NULL )
tab |
a dataframe with hierarchical structure |
huan_width |
the huan width (numeric vector) |
circle_width |
the center circle width |
space_width |
the space width between doughnuts (0~1). |
circle_label |
the center circle label |
name |
label the name |
percentage |
label the percentage |
text_params |
parameters parse to |
circle_label_params |
parameters parse to |
bar_params |
parameters parse to |
a ggplot
data.frame( a = c("a", "a", "b", "b", "c"), b = c("a", LETTERS[2:5]), c = rep("a", 5), number = 1:5 ) %>% gghuan2()
data.frame( a = c("a", "a", "b", "b", "c"), b = c("a", LETTERS[2:5]), c = rep("a", 5), number = 1:5 ) %>% gghuan2()
ggmosaic for mosaic plot
ggmosaic( tab, rect_params = list(), rect_space = 0, show_number = c("number", "percentage", "none")[1], number_params = list(), x_label = c("top", "bottom", "none")[1], y_label = c("right", "left", "none")[1], label_params = list(), chisq_test = TRUE )
ggmosaic( tab, rect_params = list(), rect_space = 0, show_number = c("number", "percentage", "none")[1], number_params = list(), x_label = c("top", "bottom", "none")[1], y_label = c("right", "left", "none")[1], label_params = list(), chisq_test = TRUE )
tab |
your dataframe, must have 3 columns, the third column must be numeric |
rect_params |
parameters parse to |
rect_space |
rect_space, defalut 0. |
show_number |
show "number" or "percentage" or "none" |
number_params |
parameters parse to |
x_label |
show x label on "top" or "bottom" or "none" |
y_label |
show y label on "right" or "left" or "none" |
label_params |
parameters parse to |
chisq_test |
whether show chisq test |
a ggplot
data(mtcars) tab <- dplyr::count(mtcars, gear, cyl) ggmosaic(tab, show_number = "number", x_label = "top", y_label = "right", chisq_test = TRUE )
data(mtcars) tab <- dplyr::count(mtcars, gear, cyl) ggmosaic(tab, show_number = "number", x_label = "top", y_label = "right", chisq_test = TRUE )
Get a ggplot xlim and ylim
ggplot_lim(p)
ggplot_lim(p)
p |
ggplot |
list
Translate axis label of a ggplot
ggplot_translator( gg, which = c("x", "y"), from = "en", to = "zh", keep_original_label = FALSE, original_sep = "\n", verbose = TRUE )
ggplot_translator( gg, which = c("x", "y"), from = "en", to = "zh", keep_original_label = FALSE, original_sep = "\n", verbose = TRUE )
gg |
a ggplot object to be translated |
which |
vector contains one or more of 'x', 'y', 'label', 'fill', 'color'..., or 'facet_x', 'facet_y', 'labs' and 'all' to select which texts to be translated. |
from |
source language |
to |
target language |
keep_original_label |
keep the source language labels |
original_sep |
default, '\n' |
verbose |
verbose |
ggplot
## Not run: df <- data.frame( Subject = c("English", "Math"), Score = c(59, 98), Motion = c("sad", "happy") ) ggp <- ggplot(df, mapping = aes(x = Subject, y = Score, label = Motion)) + geom_text() + geom_point() + labs(x = "Subject", y = "Score", title = "Final Examination") ggplot_translator(ggp, which = "all") ## End(Not run)
## Not run: df <- data.frame( Subject = c("English", "Math"), Score = c(59, 98), Motion = c("sad", "happy") ) ggp <- ggplot(df, mapping = aes(x = Subject, y = Score, label = Motion)) + geom_text() + geom_point() + labs(x = "Subject", y = "Score", title = "Final Examination") ggplot_translator(ggp, which = "all") ## End(Not run)
Grepl applied on a data.frame
grepl.data.frame(pattern, x, ...)
grepl.data.frame(pattern, x, ...)
pattern |
search pattern |
x |
your data.frame |
... |
addtitional arguments for gerpl() |
a logical matrix
matrix(letters[1:6], 2, 3) |> as.data.frame() -> a grepl.data.frame("c", a) grepl.data.frame("\\w", a)
matrix(letters[1:6], 2, 3) |> as.data.frame() -> a grepl.data.frame("c", a) grepl.data.frame("\\w", a)
Plot a boxplot
group_box( tab, group = NULL, metadata = NULL, mode = 1, group_order = NULL, facet_order = NULL, paired = FALSE, paired_line_param = list(), alpha = FALSE, method = "wilcox", alpha_param = list(), point_param = NULL, p_value1 = FALSE, p_value2 = FALSE, only_sig = TRUE, stat_compare_means_param = NULL, trend_line = FALSE, trend_line_param = list() )
group_box( tab, group = NULL, metadata = NULL, mode = 1, group_order = NULL, facet_order = NULL, paired = FALSE, paired_line_param = list(), alpha = FALSE, method = "wilcox", alpha_param = list(), point_param = NULL, p_value1 = FALSE, p_value2 = FALSE, only_sig = TRUE, stat_compare_means_param = NULL, trend_line = FALSE, trend_line_param = list() )
tab |
your dataframe |
group |
which colname choose for group or a vector |
metadata |
the dataframe contains the group |
mode |
1~9, plot style, try yourself |
group_order |
the order of x group |
facet_order |
the order of the facet |
paired |
if paired is TRUE, points in different groups will be connected by lines. So the row names order is important. |
paired_line_param |
parameters parse to |
alpha |
whether plot a group alphabeta by test of method |
method |
test method:wilcox, tukeyHSD, LSD, (default: wilcox), see |
alpha_param |
parameters parse to |
point_param |
parameters parse to |
p_value1 |
multi-test of all group |
p_value2 |
two-test of each pair |
only_sig |
only_sig for p_value2 |
stat_compare_means_param |
parameters parse to |
trend_line |
add a trend line |
trend_line_param |
parameters parse to |
a ggplot
a <- data.frame(a = 1:18, b = runif(18, 0, 5)) group_box(a, group = rep(c("a", "b", "c"), each = 6))
a <- data.frame(a = 1:18, b = runif(18, 0, 5)) group_box(a, group = rep(c("a", "b", "c"), each = 6))
Performs multiple mean comparisons for a data.frame
group_test( df, group, metadata = NULL, method = "wilcox.test", pattern = NULL, p.adjust.method = "none", threads = 1, verbose = TRUE )
group_test( df, group, metadata = NULL, method = "wilcox.test", pattern = NULL, p.adjust.method = "none", threads = 1, verbose = TRUE )
df |
a data.frame |
group |
The compare group (categories) in your data, one column name of metadata when metadata exist or a vector whose length equal to columns number of df. |
metadata |
sample information dataframe contains group |
method |
the type of test. Default is wilcox.test. Allowed values include:
|
pattern |
a named vector matching the group, e.g. c('G1'=1,'G2'=3,'G3'=2), use the correlation analysis with specific pattern to calculate p-value. |
p.adjust.method |
p.adjust.method, see |
threads |
default 1 |
verbose |
logical |
data.frame
data(otutab) group_test(otutab, metadata$Group, method = "kruskal.test") group_test(otutab[, 1:12], metadata$Group[1:12], method = "wilcox.test")
data(otutab) group_test(otutab, metadata$Group, method = "kruskal.test") group_test(otutab[, 1:12], metadata$Group[1:12], method = "wilcox.test")
Gsub applied on a data.frame
gsub.data.frame(pattern, replacement, x, ...)
gsub.data.frame(pattern, replacement, x, ...)
pattern |
search pattern |
replacement |
a replacement for matched pattern |
x |
your data.frame |
... |
additional arguments for gerpl() |
a data.frame
matrix(letters[1:6], 2, 3) |> as.data.frame() -> a gsub.data.frame("c", "a", a)
matrix(letters[1:6], 2, 3) |> as.data.frame() -> a gsub.data.frame("c", "a", a)
Filter your data
guolv(tab, sum = 10, exist = 1)
guolv(tab, sum = 10, exist = 1)
tab |
dataframe |
sum |
the rowsum should bigger than sum (default:10) |
exist |
the exist number bigger than exist (default:1) |
input object
data(otutab) guolv(otutab)
data(otutab) guolv(otutab)
Group your data
hebing(otutab, group, margin = 2, act = "mean", metadata = NULL)
hebing(otutab, group, margin = 2, act = "mean", metadata = NULL)
otutab |
data.frame |
group |
group vector or one of colnames(metadata) |
margin |
1 for row and 2 for column(default: 2) |
act |
do (default: mean) |
metadata |
metadata |
data.frame
data(otutab) hebing(otutab, metadata$Group) hebing(otutab, "Group", metadata = metadata, act = "sum")
data(otutab) hebing(otutab, metadata$Group) hebing(otutab, "Group", metadata = metadata, act = "sum")
How to set font for ggplot
how_to_set_font_for_plot()
how_to_set_font_for_plot()
No return value
How to set options in a package
how_to_set_options(package = "My_package")
how_to_set_options(package = "My_package")
package |
package name |
No return value
How to update parameters
how_to_update_parameters()
how_to_update_parameters()
No return value
How to use parallel
how_to_use_parallel( loop = function(i) { return(mean(rnorm(100))) } )
how_to_use_parallel( loop = function(i) { return(mean(rnorm(100))) } )
loop |
the main function |
No return value
How to use sbatch
how_to_use_sbatch(mode = 1)
how_to_use_sbatch(mode = 1)
mode |
1~3 |
No return value
Translate text of igraph
igraph_translator( ig, from = "en", to = "zh", which = c("vertex", "edge", "all")[1], verbose = TRUE )
igraph_translator( ig, from = "en", to = "zh", which = c("vertex", "edge", "all")[1], verbose = TRUE )
ig |
igraph object to be translated |
from |
source language |
to |
target language |
which |
vertex, edge, or all |
verbose |
verbose |
igraph object
## Not run: library(igraph) ig <- make_graph(c("happy", "sad", "sad", "angry", "sad", "worried")) plot(ig) ig2 <- igraph_translator(ig) font_file <- "/System/Library/Fonts/Supplemental/Songti.ttc" sysfonts::font_add("Songti", font_file) plot(ig2, vertex.label.family = "Songti") ## End(Not run)
## Not run: library(igraph) ig <- make_graph(c("happy", "sad", "sad", "angry", "sad", "worried")) plot(ig) ig2 <- igraph_translator(ig) font_file <- "/System/Library/Fonts/Supplemental/Songti.ttc" sysfonts::font_add("Songti", font_file) plot(ig2, vertex.label.family = "Songti") ## End(Not run)
Judge if a characteristic is Rcolor
is.ggplot.color(color)
is.ggplot.color(color)
color |
characteristic |
TRUE or FALSE
is.ggplot.color("red") is.ggplot.color("notcolor") is.ggplot.color(NA) is.ggplot.color("#000")
is.ggplot.color("red") is.ggplot.color("notcolor") is.ggplot.color(NA) is.ggplot.color("#000")
Scale a legend size
legend_size(scale = 1)
legend_size(scale = 1)
scale |
default: 1. |
"theme" "gg"
Attach packages or install packages have not benn installed
lib_ps(p_list, ..., all_yes = FALSE, library = TRUE)
lib_ps(p_list, ..., all_yes = FALSE, library = TRUE)
p_list |
a vector of packages list |
... |
packages |
all_yes |
all install try set to yes? |
library |
should library the package or just get Namespace ? |
No return value
my little cat named Guo Dong which drawn by my girlfriend.
rastergrob object.
This function fits a linear regression model using the given data and formula, and returns the coefficients.
lm_coefficients(data, formula, standardize = FALSE, each = TRUE)
lm_coefficients(data, formula, standardize = FALSE, each = TRUE)
data |
A data frame containing the response variable and predictors. |
formula |
A formula specifying the structure of the linear regression model. |
standardize |
Whether to standardize the data before fitting the model. |
each |
each variable do a lm or whole multi-lm |
coefficients The coefficients of the linear regression model.
data <- data.frame( response = c(2, 4, 6, 7, 9), x1 = c(1, 2, 3, 4, 5), x2 = c(2, 3, 6, 8, 9), x3 = c(3, 6, 5, 12, 12) ) coefficients_df <- lm_coefficients(data, response ~ x1 + x2 + x3) print(coefficients_df) plot(coefficients_df)
data <- data.frame( response = c(2, 4, 6, 7, 9), x1 = c(1, 2, 3, 4, 5), x2 = c(2, 3, 6, 8, 9), x3 = c(3, 6, 5, 12, 12) ) coefficients_df <- lm_coefficients(data, response ~ x1 + x2 + x3) print(coefficients_df) plot(coefficients_df)
Make a Gitbook using bookdown
make_gitbook( book_n, root_dir = "~/Documents/R/", mode = c("gitbook", "bs4")[1], author = "Asa12138", bib = "~/Documents/R/pc_blog/content/bib/My Library.bib", csl = "~/Documents/R/pc_blog/content/bib/science.csl" )
make_gitbook( book_n, root_dir = "~/Documents/R/", mode = c("gitbook", "bs4")[1], author = "Asa12138", bib = "~/Documents/R/pc_blog/content/bib/My Library.bib", csl = "~/Documents/R/pc_blog/content/bib/science.csl" )
book_n |
project name |
root_dir |
root directory |
mode |
"gitbook","bs4" |
author |
author |
bib |
cite papers bib, from Zotero |
csl |
cite papers format, default science.csl |
No return value
Make a R-analysis project
make_project(pro_n, root_dir = "~/Documents/R/")
make_project(pro_n, root_dir = "~/Documents/R/")
pro_n |
project name |
root_dir |
root directory |
No return value
Make a new python package
make_py_pkg( pkg_name, path = ".", author = "Your Name", email = "[email protected]", description = "A brief description of your library", license = "MIT" )
make_py_pkg( pkg_name, path = ".", author = "Your Name", email = "[email protected]", description = "A brief description of your library", license = "MIT" )
pkg_name |
package name |
path |
project path, default "." |
author |
author |
email |
|
description |
description |
license |
license |
No return value
if (interactive()) { make_py_pkg("my_python_package", path = "~/projects", author = "John Doe", description = "My Python library", license = "MIT") }
if (interactive()) { make_py_pkg("my_python_package", path = "~/projects", author = "John Doe", description = "My Python library", license = "MIT") }
Match otutab and metadata
match_df(otutab, metadata)
match_df(otutab, metadata)
otutab |
otutab, rownames are features, colnames are samples |
metadata |
metadata, rownames are samples |
list
data(otutab) match_df(otutab, metadata)
data(otutab) match_df(otutab, metadata)
an otutab, metadata and a taxonomy table.
contains an otutab, metadata and a taxonomy table.
contians otutable rawdata
contians metadata
contians taxonomy table
Min_Max scale
mmscale(x, min_s = 0, max_s = 1, n = 1, plot = FALSE)
mmscale(x, min_s = 0, max_s = 1, n = 1, plot = FALSE)
x |
a numeric vector |
min_s |
scale min |
max_s |
scale max |
n |
linear transfer for n=1; the slope will change if n>1 or n<1 |
plot |
whether plot the transfer? |
a numeric vector
x <- runif(10) mmscale(x, 5, 10)
x <- runif(10) mmscale(x, 5, 10)
Multiple regression/ variance decomposition analysis
multireg(formula, data, TopN = 3)
multireg(formula, data, TopN = 3)
formula |
formula |
data |
dataframe |
TopN |
give top variable importance |
ggplot
if (requireNamespace("relaimpo") && requireNamespace("aplot")) { data(otutab) multireg(env1 ~ Group * ., data = metadata[, 2:7]) }
if (requireNamespace("relaimpo") && requireNamespace("aplot")) { data(otutab) multireg(env1 ~ Group * ., data = metadata[, 2:7]) }
anova (parametric) and kruskal.test (non-parametric). Perform one-way ANOVA test comparing multiple groups. LSD and TukeyHSD are post hoc test of anova. dunn and nemenyi are post hoc test of kruskal.test. t.test or wilcox is just perform t.test or wilcox.test in each two group (no p.adjust).
multitest(var, group, print = TRUE, return = FALSE)
multitest(var, group, print = TRUE, return = FALSE)
var |
numeric vector |
group |
more than two-levels group vector |
print |
whether print the result |
return |
return which method result (tukeyHSD or LSD or wilcox?) |
No value or a dataframe.
if (requireNamespace("multcompView")) { multitest(runif(30), rep(c("A", "B", "C"), each = 10), return = "wilcox") }
if (requireNamespace("multcompView")) { multitest(runif(30), rep(c("A", "B", "C"), each = 10), return = "wilcox") }
Show my little cat named Guo Dong which drawn by my girlfriend.
my_cat(mode = 1, picture = 1)
my_cat(mode = 1, picture = 1)
mode |
1~2 |
picture |
1~2 |
a ggplot
My Circle packing plot
my_circle_packing( test, anno = NULL, mode = 1, Group = "level", Score = "weight", label = "label", show_level_name = "all", show_tip_label = TRUE, str_width = 10 )
my_circle_packing( test, anno = NULL, mode = 1, Group = "level", Score = "weight", label = "label", show_level_name = "all", show_tip_label = TRUE, str_width = 10 )
test |
a dataframe with hierarchical structure |
anno |
annotation tablewith rowname for color or fill. |
mode |
1~2 |
Group |
fill for mode2 |
Score |
color for mode1 |
label |
the labels column |
show_level_name |
show which level name? a vector contains some column names. |
show_tip_label |
show_tip_label, logical |
str_width |
str_width |
ggplot
data(otutab) cbind(taxonomy, weight = rowSums(otutab))[1:10, ] -> test if (requireNamespace("igraph") && requireNamespace("ggraph")) { my_circle_packing(test) }
data(otutab) cbind(taxonomy, weight = rowSums(otutab))[1:10, ] -> test if (requireNamespace("igraph") && requireNamespace("ggraph")) { my_circle_packing(test) }
My circo plot
my_circo( df, reorder = TRUE, pal = NULL, mode = c("circlize", "chorddiag")[1], legend = TRUE, ... )
my_circo( df, reorder = TRUE, pal = NULL, mode = c("circlize", "chorddiag")[1], legend = TRUE, ... )
df |
dataframe with three column |
reorder |
reorder by number? |
pal |
a vector of colors, you can get from here too: |
mode |
"circlize","chorddiag" |
legend |
plot legend? |
... |
chordDiagram
if (requireNamespace("circlize")) { data.frame( a = c("a", "a", "b", "b", "c"), b = c("a", LETTERS[2:5]), c = 1:5 ) %>% my_circo(mode = "circlize") data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, c(2, 6, 8)] -> test my_circo(test) }
if (requireNamespace("circlize")) { data.frame( a = c("a", "a", "b", "b", "c"), b = c("a", LETTERS[2:5]), c = 1:5 ) %>% my_circo(mode = "circlize") data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, c(2, 6, 8)] -> test my_circo(test) }
Fit a linear model and plot
my_lm(tab, var, metadata = NULL, smooth_param = list(), facet = TRUE, ...)
my_lm(tab, var, metadata = NULL, smooth_param = list(), facet = TRUE, ...)
tab |
your dataframe |
var |
which colname choose for var or a vector |
metadata |
the dataframe contains the var |
smooth_param |
parameters parse to |
facet |
whether facet? |
... |
parameters parse to |
a ggplot
if (requireNamespace("ggpmisc")) { my_lm(runif(50), var = 1:50) my_lm(c(1:50) + runif(50, 0, 5), var = 1:50) }
if (requireNamespace("ggpmisc")) { my_lm(runif(50), var = 1:50) my_lm(c(1:50) + runif(50, 0, 5), var = 1:50) }
My Sankey plot
my_sankey( test, mode = c("sankeyD3", "ggsankey"), topN = "all", space = 1, width = 0.1, str_width = 20, notshow = c(), D3_params = NULL, ... )
my_sankey( test, mode = c("sankeyD3", "ggsankey"), topN = "all", space = 1, width = 0.1, str_width = 20, notshow = c(), D3_params = NULL, ... )
test |
a dataframe with hierarchical structure |
mode |
"sankeyD3","ggsankey" |
topN |
"all" or numeric vector, determine how many topN shows in each column |
space |
space width for ggsankey |
width |
width |
str_width |
str_width |
notshow |
notshow |
D3_params |
look for parameters in |
... |
additional parameters |
ggplot or htmlwidget
if (interactive()) { data.frame( a = c("a", "a", "b", "b", "c"), aa = rep("a", 5), b = c("a", LETTERS[2:5]), c = 1:5 ) %>% my_sankey(., "gg", num = TRUE) data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, ] -> test my_sankey(test) }
if (interactive()) { data.frame( a = c("a", "a", "b", "b", "c"), aa = rep("a", 5), b = c("a", LETTERS[2:5]), c = 1:5 ) %>% my_sankey(., "gg", num = TRUE) data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, ] -> test my_sankey(test) }
My Sunburst plot
my_sunburst(test, ...)
my_sunburst(test, ...)
test |
a dataframe with hierarchical structure |
... |
look for parameters in |
htmlwidget
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, ] -> test if (requireNamespace("plotly")) { my_sunburst(test) }
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, ] -> test if (requireNamespace("plotly")) { my_sunburst(test) }
My Treemap plot
my_treemap(test, ...)
my_treemap(test, ...)
test |
a three-columns dataframe with hierarchical structure |
... |
look for parameters in |
htmlwidget
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, c(4, 7, 8)] -> test if (requireNamespace("treemap")) { my_treemap(test) }
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, c(4, 7, 8)] -> test if (requireNamespace("treemap")) { my_treemap(test) }
My Voronoi treemap plot
my_voronoi_treemap(test, ...)
my_voronoi_treemap(test, ...)
test |
a three-columns dataframe with hierarchical structure |
... |
look for parameters in |
htmlwidget
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, c(4, 7, 8)] -> test if (requireNamespace("voronoiTreemap")) { my_voronoi_treemap(test) }
data(otutab) cbind(taxonomy, num = rowSums(otutab))[1:10, c(4, 7, 8)] -> test if (requireNamespace("voronoiTreemap")) { my_voronoi_treemap(test) }
an otutab, metadata and a taxonomy table.
contains an otutab, metadata and a taxonomy table.
contians otutable rawdata
contians metadata
contians taxonomy table
This function takes the coefficients and generates a plot to visualize their magnitudes.
## S3 method for class 'coefficients' plot(x, mode = 1, number = FALSE, x_order = NULL, ...)
## S3 method for class 'coefficients' plot(x, mode = 1, number = FALSE, x_order = NULL, ...)
x |
The coefficients to be plotted. |
mode |
The mode of the plot: 1 for bar chart, 2 for lollipop chart. |
number |
show number |
x_order |
order of variables |
... |
add |
ggplot
Plot a gif
plotgif(plist, file, speed = 1, ...)
plotgif(plist, file, speed = 1, ...)
plist |
plot list |
file |
prefix of your .gif file |
speed |
1 |
... |
add |
No return value
Plot a multi-pages pdf
plotpdf( plist, file, width = 8, height = 7, browser = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", ... )
plotpdf( plist, file, width = 8, height = 7, browser = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge", ... )
plist |
plot list |
file |
prefix of your .pdf file |
width |
width |
height |
height |
browser |
the path of Google Chrome, Microsoft Edge or Chromium in your computer. |
... |
additional arguments |
No return value
Prepare a numeric string
pre_number_str(str, split_str = ",", continuous_str = "-")
pre_number_str(str, split_str = ",", continuous_str = "-")
str |
a string contain ',' and '-' |
split_str |
split_str "," |
continuous_str |
continuous_str "-" |
vector
pre_number_str("a1,a3,a5,a6-a10")
pre_number_str("a1,a3,a5,a6-a10")
Prepare a package
prepare_package( pkg_dir = ".", exclude = "print.R", indent_by = 2, check = TRUE, ... )
prepare_package( pkg_dir = ".", exclude = "print.R", indent_by = 2, check = TRUE, ... )
pkg_dir |
defalut: "." |
exclude |
vector for excluding .R files |
indent_by |
indent_by, default: 2 |
check |
check or not, default: TRUE |
... |
other parameters for devtools::check |
No value
Read fasta file
read_fasta(fasta_file)
read_fasta(fasta_file)
fasta_file |
file path |
data.frame
Read some special format file
read.file( file, format = NULL, just_print = FALSE, all_yes = FALSE, density = 120, ... )
read.file( file, format = NULL, just_print = FALSE, all_yes = FALSE, density = 120, ... )
file |
file path |
format |
"blast", "diamond", "fa", "fasta", "fna", "faa", "bib", "gff", "gtf","jpg", "png", "pdf", "svg"... |
just_print |
just print the file |
all_yes |
all_yes? |
density |
the resolution for reading pdf or svg |
... |
additional arguments |
data.frame
Remove outliers
remove.outliers(x, factor = 1.5)
remove.outliers(x, factor = 1.5)
x |
a numeric vector |
factor |
default 1.5 |
a numeric vector
remove.outliers(c(1, 10:15))
remove.outliers(c(1, 10:15))
Transform a rgb vector to a Rcolor code
rgb2code(x, rev = FALSE)
rgb2code(x, rev = FALSE)
x |
vector or three columns data.frame |
rev |
reverse,transform a Rcolor code to a rgb vector |
Rcolor code like "#69C404"
rgb2code(c(12, 23, 34)) rgb2code("#69C404", rev = TRUE)
rgb2code(c(12, 23, 34)) rgb2code("#69C404", rev = TRUE)
Remove the low relative items in each column
rm_low(otutab, relative_threshold = 0.0001)
rm_low(otutab, relative_threshold = 0.0001)
otutab |
otutab |
relative_threshold |
threshold, default: 1e-4 |
data.frame
data(otutab) rm_low(otutab)
data(otutab) rm_low(otutab)
Plot the sampling map
sample_map( metadata, mode = 1, map_params = list(), group = NULL, point_params = list(), label = NULL, label_params = list(), leaflet_pal = NULL, shp_file = NULL, crs = 4326, xlim = NULL, ylim = NULL, add_scale = TRUE, scale_params = list(), add_north_arrow = TRUE, north_arrow_params = list() )
sample_map( metadata, mode = 1, map_params = list(), group = NULL, point_params = list(), label = NULL, label_params = list(), leaflet_pal = NULL, shp_file = NULL, crs = 4326, xlim = NULL, ylim = NULL, add_scale = TRUE, scale_params = list(), add_north_arrow = TRUE, north_arrow_params = list() )
metadata |
metadata must contains "Longitude","Latitude" |
mode |
1~3. 1 use basic data from ggplot2. 2 use a shp_file. 3 use the leaflet. |
map_params |
parameters parse to geom_polygon (mode=1) or geom_sf (mode=2) |
group |
one column name of metadata which mapping to point color |
point_params |
parameters parse to geom_point |
label |
one column name of metadata which mapping to point label |
label_params |
parameters parse to geom_sf_text |
leaflet_pal |
leaflet color palette |
shp_file |
a geojson file parse to |
crs |
crs coordinate: |
xlim |
xlim |
ylim |
ylim |
add_scale |
add annotation_scale |
scale_params |
parameters parse to |
add_north_arrow |
add annotation_north_arrow |
north_arrow_params |
parameters parse to |
map
data(otutab) anno_df <- metadata[, c("Id", "long", "lat", "Group")] colnames(anno_df) <- c("Id", "Longitude", "Latitude", "Group") if (requireNamespace("ggspatial")) { sample_map(anno_df, mode = 1, group = "Group", xlim = c(90, 135), ylim = c(20, 50)) }
data(otutab) anno_df <- metadata[, c("Id", "long", "lat", "Group")] colnames(anno_df) <- c("Id", "Longitude", "Latitude", "Group") if (requireNamespace("ggspatial")) { sample_map(anno_df, mode = 1, group = "Group", xlim = c(90, 135), ylim = c(20, 50)) }
Three-line table
sanxian( df, digits = 3, nrow = 10, ncol = 10, fig = FALSE, mode = 1, background = "#D7261E", ... )
sanxian( df, digits = 3, nrow = 10, ncol = 10, fig = FALSE, mode = 1, background = "#D7261E", ... )
df |
a data.frame |
digits |
how many digits should remain |
nrow |
show how many rows |
ncol |
show how many columns |
fig |
output as a figure |
mode |
1~2 |
background |
background color |
... |
additional arguments e.g.(rows=NULL) |
a ggplot
if (require("kableExtra")) { data(otutab) sanxian(otutab) }
if (require("kableExtra")) { data(otutab) sanxian(otutab) }
Scale a fill color
scale_color_pc( palette = c("col1", "col2", "col3", "bluered"), alpha = 1, n = 11, ... )
scale_color_pc( palette = c("col1", "col2", "col3", "bluered"), alpha = 1, n = 11, ... )
palette |
col1~3; or a vector of colors, you can get from: |
alpha |
alpha |
n |
how many colors you need |
... |
additional |
scale_color
Scale a fill color
scale_fill_pc( palette = c("col1", "col2", "col3", "bluered"), alpha = 1, n = 11, ... )
scale_fill_pc( palette = c("col1", "col2", "col3", "bluered"), alpha = 1, n = 11, ... )
palette |
col1~3; or a vector of colors, you can get from: |
alpha |
alpha |
n |
how many colors you need |
... |
additional |
scale_fill
This function takes a vector of search terms, an optional search engine (default is Google), and an optional base URL to perform web searches. It opens the default web browser with search results for each term.
search_browse(search_terms, engine = "google", base_url = NULL)
search_browse(search_terms, engine = "google", base_url = NULL)
search_terms |
A character vector of search terms to be searched. |
engine |
A character string specifying the search engine to use (default is "google"). Supported engines: "google", "bing". |
base_url |
A character string specifying the base URL for web searches. If not provided, the function will use a default URL based on the chosen search engine. |
No return value
## Not run: search_terms <- c( "s__Pandoraea_pnomenusa", "s__Alicycliphilus_sp._B1" ) # Using Google search engine search_browse(search_terms, engine = "google") # Using Bing search engine search_browse(search_terms, engine = "bing") ## End(Not run)
## Not run: search_terms <- c( "s__Pandoraea_pnomenusa", "s__Alicycliphilus_sp._B1" ) # Using Google search engine search_browse(search_terms, engine = "google") # Using Bing search engine search_browse(search_terms, engine = "bing") ## End(Not run)
Set config
set_pcutils_config(item, value)
set_pcutils_config(item, value)
item |
item |
value |
value |
No value
Split text into parts, each not exceeding a specified character count
split_text(text, nchr_each = 200)
split_text(text, nchr_each = 200)
text |
Original text |
nchr_each |
Maximum character count for each part |
List of divided parts
original_text <- paste0(sample(c(letters, "\n"), 400, replace = TRUE), collapse = "") parts <- split_text(original_text, nchr_each = 200) lapply(parts, nchar)
original_text <- paste0(sample(c(letters, "\n"), 400, replace = TRUE), collapse = "") parts <- split_text(original_text, nchr_each = 200) lapply(parts, nchar)
Squash one column in a data.frame using other columns as id.
squash(df, column, split = ",")
squash(df, column, split = ",")
df |
data.frame |
column |
column name, not numeric position |
split |
split string |
data.frame
df <- data.frame(a = c(1:2, 1:2), b = letters[1:4]) squash(df, "b", ",")
df <- data.frame(a = c(1:2, 1:2), b = letters[1:4]) squash(df, "b", ",")
Plot a stack plot
Plot a area plot
stackplot( otutab, metadata = NULL, group = "Group", get_data = FALSE, bar_params = list(width = 0.7, position = "stack"), topN = 8, others = TRUE, relative = TRUE, legend_title = "", stack_order = TRUE, group_order = FALSE, facet_order = FALSE, style = c("group", "sample")[1], flow = FALSE, flow_params = list(lode.guidance = "frontback", color = "darkgray"), number = FALSE, repel = FALSE, format_params = list(digits = 2), text_params = list(position = position_stack()) ) areaplot( otutab, metadata = NULL, group = "Group", get_data = FALSE, bar_params = list(position = "stack"), topN = 8, others = TRUE, relative = TRUE, legend_title = "", stack_order = TRUE, group_order = FALSE, facet_order = FALSE, style = c("group", "sample")[1], number = FALSE, format_params = list(digits = 2), text_params = list(position = position_stack()) )
stackplot( otutab, metadata = NULL, group = "Group", get_data = FALSE, bar_params = list(width = 0.7, position = "stack"), topN = 8, others = TRUE, relative = TRUE, legend_title = "", stack_order = TRUE, group_order = FALSE, facet_order = FALSE, style = c("group", "sample")[1], flow = FALSE, flow_params = list(lode.guidance = "frontback", color = "darkgray"), number = FALSE, repel = FALSE, format_params = list(digits = 2), text_params = list(position = position_stack()) ) areaplot( otutab, metadata = NULL, group = "Group", get_data = FALSE, bar_params = list(position = "stack"), topN = 8, others = TRUE, relative = TRUE, legend_title = "", stack_order = TRUE, group_order = FALSE, facet_order = FALSE, style = c("group", "sample")[1], number = FALSE, format_params = list(digits = 2), text_params = list(position = position_stack()) )
otutab |
otutab |
metadata |
metadata |
group |
one group name of columns of metadata |
get_data |
just get the formatted data? |
bar_params |
parameters parse to |
topN |
plot how many top species |
others |
should plot others? |
relative |
transfer to relative or absolute |
legend_title |
fill legend_title |
stack_order |
the order of stack fill |
group_order |
the order of x group, can be T/F, or a vector of x, or a name, or "cluster" |
facet_order |
the order of the facet |
style |
"group" or "sample" |
flow |
should plot a flow plot? |
flow_params |
parameters parse to |
number |
show the number? |
repel |
use the ggrepel::geom_text_repel instead of geom_text |
format_params |
parameters parse to |
text_params |
parameters parse to |
a ggplot
a ggplot
data(otutab) stackplot(otutab, metadata, group = "Group") if (interactive()) { stackplot(otutab, metadata, group = "Group", style = "sample", group_order = TRUE, flow = TRUE, relative = FALSE ) } data(otutab) areaplot(otutab, metadata, group = "Id") areaplot(otutab, metadata, group = "Group", style = "sample", group_order = TRUE, relative = FALSE )
data(otutab) stackplot(otutab, metadata, group = "Group") if (interactive()) { stackplot(otutab, metadata, group = "Group", style = "sample", group_order = TRUE, flow = TRUE, relative = FALSE ) } data(otutab) areaplot(otutab, metadata, group = "Id") areaplot(otutab, metadata, group = "Group", style = "sample", group_order = TRUE, relative = FALSE )
Split Composite Names
strsplit2(x, split, colnames = NULL, ...)
strsplit2(x, split, colnames = NULL, ...)
x |
character vector |
split |
character to split each element of vector on, see |
colnames |
colnames for the result |
... |
other arguments are passed to |
data.frame
strsplit2(c("a;b", "c;d"), ";", colnames = c("col1", "col2"))
strsplit2(c("a;b", "c;d"), ";", colnames = c("col1", "col2"))
Transpose data.frame
t2(data)
t2(data)
data |
data.frame |
data.frame
Pie plot
tax_pie(otutab, topN = 6, ...)
tax_pie(otutab, topN = 6, ...)
otutab |
otutab |
topN |
topN |
... |
add |
a ggplot
data(otutab) tax_pie(otutab, topN = 7) + scale_fill_pc()
data(otutab) tax_pie(otutab, topN = 7) + scale_fill_pc()
Radar plot
tax_radar(group_df, ...)
tax_radar(group_df, ...)
group_df |
group_df |
... |
add |
ggplot
if (interactive()) { data(otutab) tax_radar(otutab[1:6, 1:4]) }
if (interactive()) { data(otutab) tax_radar(otutab[1:6, 1:4]) }
an otutab, metadata and a taxonomy table.
contains an otutab, metadata and a taxonomy table.
contians otutable rawdata
contians metadata
contians taxonomy table
Replace a vector by named vector
tidai(x, y, fac = FALSE, keep_origin = FALSE)
tidai(x, y, fac = FALSE, keep_origin = FALSE)
x |
a vector need to be replaced |
y |
named vector |
fac |
consider the factor? |
keep_origin |
keep_origin? |
vector
tidai(c("a", "a", "b", "d"), c("a" = "red", b = "blue")) tidai(c("a", "a", "b", "c"), c("red", "blue")) tidai(c("A" = "a", "B" = "b"), c("a" = "red", b = "blue")) tidai(factor(c("A" = "a", "B" = "b", "C" = "c")), c("a" = "red", b = "blue", c = "green"))
tidai(c("a", "a", "b", "d"), c("a" = "red", b = "blue")) tidai(c("a", "a", "b", "c"), c("red", "blue")) tidai(c("A" = "a", "B" = "b"), c("a" = "red", b = "blue")) tidai(factor(c("A" = "a", "B" = "b", "C" = "c")), c("a" = "red", b = "blue", c = "green"))
Transfer Geographical latitude and longitude to XY(m)
toXY(geo)
toXY(geo)
geo |
a two-columns dataframe, first is latitude, second is longitude |
data.frame
if (interactive()) { data.frame(row.names = letters[1:18], x = runif(18, 30, 35), y = runif(18, 40, 45)) -> geo toXY(geo) }
if (interactive()) { data.frame(row.names = letters[1:18], x = runif(18, 30, 35), y = runif(18, 40, 45)) -> geo toXY(geo) }
Trans format your data
trans(df, method = "normalize", margin = 2, ...)
trans(df, method = "normalize", margin = 2, ...)
df |
dataframe |
method |
"cpm","minmax","acpm","total","log", "max", "frequency", "normalize", "range", "rank", "rrank", "standardize", "pa", "chi.square", "hellinger", "log", "clr", "rclr", "alr" |
margin |
1 for row and 2 for column(default: 2) |
... |
additional |
data.frame
data(otutab) trans(otutab, method = "cpm")
data(otutab) trans(otutab, method = "cpm")
Transfer the format of file
trans_format( file, to_format, format = NULL, ..., browser = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" )
trans_format( file, to_format, format = NULL, ..., browser = "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge" )
file |
input file |
to_format |
transfer to |
format |
input file format |
... |
additional argument |
browser |
the path of Google Chrome, Microsoft Edge or Chromium in your computer. |
file at work directory
language: en, zh, jp, fra, th..., see https://www.cnblogs.com/pieguan/p/10338255.html
translator(words, from = "en", to = "zh", split = TRUE, verbose = TRUE)
translator(words, from = "en", to = "zh", split = TRUE, verbose = TRUE)
words |
words |
from |
source language, default "en" |
to |
target language, default "zh" |
split |
split to blocks when your words are too much |
verbose |
verbose |
vector
## Not run: translator(c("love", "if"), from = "en", to = "zh") ## End(Not run)
## Not run: translator(c("love", "if"), from = "en", to = "zh") ## End(Not run)
Two-group test
twotest(var, group)
twotest(var, group)
var |
numeric vector |
group |
two-levels group vector |
No return value
twotest(runif(20), rep(c("a", "b"), each = 10))
twotest(runif(20), rep(c("a", "b"), each = 10))
Update the NEW.md for a package
update_NEWS_md( package_dir = ".", new_features = character(), bug_fixes = character(), other_changes = character(), ... )
update_NEWS_md( package_dir = ".", new_features = character(), bug_fixes = character(), other_changes = character(), ... )
package_dir |
default: "." |
new_features |
new_features |
bug_fixes |
bug_fixes |
other_changes |
other_changes |
... |
additional info |
No value
Keep the different parameters while use the same name in update first.
update_param(default, update)
update_param(default, update)
default |
default (data.frame, list, vector) |
update |
update (data.frame, list, vector) |
same class of your input (data.frame, list or vector)
update_param(list(a = 1, b = 2), list(b = 5, c = 5))
update_param(list(a = 1, b = 2), list(b = 5, c = 5))
Plot a general venn (upset, flower)
venn(...) ## S3 method for class 'list' venn(aa, mode = "venn", elements_label = TRUE, ...) ## S3 method for class 'data.frame' venn(otutab, mode = "venn", elements_label = TRUE, ...)
venn(...) ## S3 method for class 'list' venn(aa, mode = "venn", elements_label = TRUE, ...) ## S3 method for class 'data.frame' venn(otutab, mode = "venn", elements_label = TRUE, ...)
... |
add |
aa |
list |
mode |
"venn", "venn2", "euler", "upset", "flower", "network" |
elements_label |
logical, show elements label in network? |
otutab |
table |
a plot
a plot
a plot
if (interactive()) { aa <- list(a = 1:3, b = 3:7, c = 2:4) venn(aa, mode = "venn") venn(aa, mode = "euler") venn(aa, mode = "network") venn(aa, mode = "upset") data(otutab) venn(otutab, mode = "flower") }
if (interactive()) { aa <- list(a = 1:3, b = 3:7, c = 2:4) venn(aa, mode = "venn") venn(aa, mode = "euler") venn(aa, mode = "network") venn(aa, mode = "upset") data(otutab) venn(otutab, mode = "flower") }
Write a data.frame to fasta
write_fasta(df, file_path, str_per_line = 70)
write_fasta(df, file_path, str_per_line = 70)
df |
data.frame |
file_path |
output file path |
str_per_line |
how many base or animo acid in one line, if NULL, one sequence in one line. |
No return value