-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathecdf_plot.Rd
More file actions
129 lines (114 loc) · 4.27 KB
/
Copy pathecdf_plot.Rd
File metadata and controls
129 lines (114 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/other-visualizations.R
\name{ecdf_plot}
\alias{ecdf_plot}
\title{Create ECDF Plot with Optional Boxplot Insert}
\usage{
ecdf_plot(
normed_data = NULL,
type = c("rna", "ribo", "te"),
samples_selected = NULL,
un_selected_cols = c("gene_id", "gene_name", "gene_biotype"),
ref_group = NULL,
colors = NULL,
ecdf_xlim = NULL,
box_ylim = NULL,
insert_box = FALSE,
x_pos = 0.45,
y_pos = 0.4,
width = 0.2,
height = 0.65
)
}
\arguments{
\item{normed_data}{A list containing normalized data with elements:
\itemize{
\item \code{tpm.rna}: TPM values for RNA-seq data
\item \code{tpm.ribo}: TPM values for Ribosome profiling data
\item \code{te}: Translation efficiency values
}
Each element should be a data frame with columns: gene_id, gene_name,
gene_biotype, and sample columns.}
\item{type}{Character string specifying data type. One of "rna", "ribo", or "te".
Default is c("rna", "ribo", "te").}
\item{samples_selected}{Character vector of sample names to include in the plot.
If NULL, all samples will be used.}
\item{un_selected_cols}{Character vector of column names to exclude from
pivoting (typically gene annotation columns like gene_id, gene_name).
Default: c("gene_id", "gene_name", "gene_biotype").}
\item{ref_group}{Character string specifying the reference group for statistical
comparisons. Should match one of the sample names.}
\item{colors}{Named character vector of colors for each sample. If NULL,
default ggplot2 colors will be used.}
\item{ecdf_xlim}{Numeric vector of length 2 specifying x-axis limits for the
ECDF plot. If NULL, automatic limits will be used.}
\item{box_ylim}{Numeric vector of length 2 specifying y-axis limits for the
boxplot insert. If NULL, automatic limits will be used.}
\item{insert_box}{Logical indicating whether to insert a boxplot. Default is FALSE.}
\item{x_pos}{Numeric value specifying the x position of the boxplot insert
(as proportion of plot width). Default is 0.45.}
\item{y_pos}{Numeric value specifying the y position of the boxplot insert
(as proportion of plot height). Default is 0.4.}
\item{width}{Numeric value specifying the width of the boxplot insert
(as proportion of plot width). Default is 0.2.}
\item{height}{Numeric value specifying the height of the boxplot insert
(as proportion of plot height). Default is 0.65.}
}
\value{
A list containing:
\itemize{
\item \code{plot}: A ggplot2 object containing the ECDF plot (with optional boxplot insert)
\item \code{statistics}: A data frame with statistical comparison results from Wilcoxon tests
}
}
\description{
This function creates an empirical cumulative distribution function (ECDF) plot
for RNA-seq, Ribosome profiling, or Translation Efficiency (TE) data. It can
optionally include an inserted boxplot and performs statistical comparisons
between samples.
}
\details{
The function performs the following steps:
\enumerate{
\item Selects the appropriate data based on the \code{type} parameter
\item Converts data from wide to long format
\item Filters out NA and infinite values
\item Performs pairwise Wilcoxon tests using the specified reference group
\item Creates an ECDF plot with log2-transformed values
\item Optionally adds a boxplot insert using cowplot
}
}
\note{
This function requires the following packages:
\itemize{
\item \code{ggplot2}
\item \code{reshape2}
\item \code{dplyr}
\item \code{ggpubr}
\item \code{cowplot} (only if \code{insert_box = TRUE})
}
}
\examples{
\dontrun{
# Basic ECDF plot for TE data
result <- ecdf_plot(normed_data = my_data,
type = "te",
samples_selected = c("sample1", "sample2", "sample3"),
ref_group = "sample1")
# ECDF plot with boxplot insert and custom colors
result <- ecdf_plot(normed_data = my_data,
type = "te",
samples_selected = c("sample1", "sample2", "sample3"),
ref_group = "sample1",
colors = c("sample1" = "blue", "sample2" = "red", "sample3" = "green"),
insert_box = TRUE,
x_pos = 0.5, y_pos = 0.3)
# Access the plot and statistics
print(result$plot)
print(result$statistics)
}
}
\seealso{
\code{\link[ggplot2]{stat_ecdf}}, \code{\link[ggpubr]{compare_means}},
\code{\link[cowplot]{ggdraw}}
}