Skip to content

Commit 16210e0

Browse files
committed
add visualize.dist() (fixes #7)
1 parent d3722c3 commit 16210e0

36 files changed

Lines changed: 354 additions & 56 deletions

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export(transform)
2828
export(trimFASTA)
2929
export(visualize.biplot)
3030
export(visualize.boxplot)
31+
export(visualize.dist)
3132
export(visualize.heatmap)
3233
export(visualize.loading)
3334
export(visualize.ma)

R/globals.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ utils::globalVariables(c(
2828
"value", # <preprocessing_scaffold>
2929
"Mean", # <meanVarPlot>
3030
"Variance", # <meanVarPlot>
31+
"R.Condition", # <visualize.dist>
32+
"R.Replicate", # <visualize.dist>
33+
"name", # <visualize.dist>
34+
"value", # <visualize.dist>
35+
"Group", # <visualize.dist>
3136
"R.Condition", # <visualize.heatmap>
3237
"R.Replicate", # <visualize.heatmap>
3338
"R.ConRep", # <visualize.heatmap>

R/visualizations.R

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,73 @@ visualize.boxplot <- function(dataSet) {
5252
}
5353

5454

55+
##----------------------------------------------------------------------------------------
56+
#'
57+
#' Average abundance distributions: Density and ECDF
58+
#'
59+
#' @description
60+
#' Generate distribution plots of proteins' average abundance across conditions
61+
#' and replicates, including both a kernel density estimate and an empirical
62+
#' cumulative distribution function (ECDF).
63+
#'
64+
#' @param dataSet The 2d data set of data.
65+
#'
66+
#' @return
67+
#' An object of class \code{ggplot}.
68+
#'
69+
#' @autoglobal
70+
#'
71+
#' @export
72+
73+
visualize.dist <- function(dataSet) {
74+
75+
plotData <- dataSet %>%
76+
pivot_longer(-c(R.Condition, R.Replicate)) %>%
77+
group_by(name) %>%
78+
summarise(mean = mean(value, na.rm = TRUE),
79+
Group = if_else(any(is.na(value)), "Missing", "Valid"),
80+
.groups = "drop")
81+
82+
if(n_distinct(plotData$Group) > 1) {
83+
84+
ggplot() +
85+
stat_density(
86+
data = plotData %>%
87+
mutate(Panel = factor("Probability Density",
88+
levels = c("Probability Density", "Cumulative Probability"))),
89+
aes(x = mean, color = Group), na.rm = TRUE, geom = "line") +
90+
stat_ecdf(
91+
data = plotData %>%
92+
mutate(Panel = factor("Cumulative Probability",
93+
levels = c("Probability Density", "Cumulative Probability"))),
94+
aes(x = mean, col = Group), na.rm = TRUE, geom = "line", pad = FALSE) +
95+
facet_wrap(~ Panel, scales = "free_y") +
96+
labs(x = "Average Abundance", y = NULL) +
97+
theme_bw() +
98+
theme(legend.position = "bottom")
99+
100+
} else {
101+
102+
ggplot() +
103+
stat_density(
104+
data = plotData %>%
105+
mutate(Panel = factor("Probability Density",
106+
levels = c("Probability Density", "Cumulative Probability"))),
107+
aes(x = mean), na.rm = TRUE, geom = "line") +
108+
stat_ecdf(
109+
data = plotData %>%
110+
mutate(Panel = factor("Cumulative Probability",
111+
levels = c("Probability Density", "Cumulative Probability"))),
112+
aes(x = mean), na.rm = TRUE, geom = "line", pad = FALSE) +
113+
facet_wrap(~ Panel, scales = "free_y") +
114+
labs(x = "Average Abundance", y = NULL) +
115+
theme_bw()
116+
117+
}
118+
119+
}
120+
121+
55122
##----------------------------------------------------------------------------------------
56123
#'
57124
#' Heatmap

_pkgdown.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ reference:
6262
contents:
6363
- visualize.biplot
6464
- visualize.boxplot
65+
- visualize.dist
6566
- visualize.heatmap
6667
- visualize.loading
6768
- visualize.ma

docs/articles/visualization.html

Lines changed: 56 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/visualization.md

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ visualize.boxplot(dataNorm)
5555

5656
![](visualization_files/figure-html/unnamed-chunk-3-1.png)
5757

58+
## Distributions plot
59+
60+
To examine whether missing values are biased towards lower-abundance
61+
proteins, the distribution plot helps clearly distinguish proteins with
62+
and without missing values.
63+
64+
``` r
65+
66+
visualize.dist(dataTran)
67+
```
68+
69+
![](visualization_files/figure-html/unnamed-chunk-4-1.png)
70+
71+
In the left panel, the Missing group is concentrated in the
72+
low-abundance range, showing a sharper peak than the Valid group, whose
73+
distribution is flatter and more diffuse. This indicates that proteins
74+
with missing values generally have lower abundance—a typical pattern in
75+
proteomics and metabolomics, where low-abundance signals are more prone
76+
to missingness (MNAR).
77+
78+
In the right panel, the ECDF reveals the same pattern: the Missing group
79+
rises more quickly and reaches high cumulative probability at lower
80+
abundance levels, confirming that its average-abundance distribution is
81+
left-shifted relative to the Valid group.
82+
5883
## Heatmap
5984

6085
The package offers two options for plotting the heatmap.
@@ -70,7 +95,7 @@ visualize.heatmap(dataImput, pkg = "pheatmap",
7095
show_colnames = TRUE, show_rownames = TRUE)
7196
```
7297

73-
![](visualization_files/figure-html/unnamed-chunk-4-1.png)
98+
![](visualization_files/figure-html/unnamed-chunk-5-1.png)
7499

75100
When protein names are excessively long, it is recommended to set
76101
`show_rownames = FALSE` to view the full heatmap.
@@ -85,7 +110,7 @@ visualize.heatmap(dataSet, pkg = "pheatmap",
85110
show_colnames = TRUE, show_rownames = TRUE)
86111
```
87112

88-
![](visualization_files/figure-html/unnamed-chunk-5-1.png)
113+
![](visualization_files/figure-html/unnamed-chunk-6-1.png)
89114

90115
- Option 2 use the source package `ggplot2` to generate a ggplot object
91116
but does not include the dendrogram.
@@ -95,7 +120,7 @@ visualize.heatmap(dataSet, pkg = "pheatmap",
95120
visualize.heatmap(dataImput, pkg = "ggplot2")
96121
```
97122

98-
![](visualization_files/figure-html/unnamed-chunk-6-1.png)
123+
![](visualization_files/figure-html/unnamed-chunk-7-1.png)
99124

100125
In a heatmap, similar colors within a row indicate relatively consistent
101126
values, suggesting similar protein expression levels across different
@@ -106,7 +131,7 @@ samples.
106131
visualize.heatmap(dataSet, pkg = "ggplot2")
107132
```
108133

109-
![](visualization_files/figure-html/unnamed-chunk-7-1.png)
134+
![](visualization_files/figure-html/unnamed-chunk-8-1.png)
110135

111136
## MA plot
112137

@@ -119,7 +144,7 @@ visualize.ma(anlys_ma$`100pmol-50pmol`, M.thres = 1)
119144
#> (`geom_text_repel()`).
120145
```
121146

122-
![](visualization_files/figure-html/unnamed-chunk-8-1.png)
147+
![](visualization_files/figure-html/unnamed-chunk-9-1.png)
123148

124149
where `M.thres = 1` means the M thresholds are set to -1 and 1. The
125150
scatters are split into three parts: up regulation (M \> 1), no
@@ -137,7 +162,7 @@ visualize.ma(anlys_ma, M.thres = 1)
137162
#> (`geom_text_repel()`).
138163
```
139164

140-
![](visualization_files/figure-html/unnamed-chunk-9-1.png)
165+
![](visualization_files/figure-html/unnamed-chunk-10-1.png)
141166

142167
### Details
143168

@@ -184,7 +209,7 @@ visualize.rank(dataImput, listName = "POLK_HUMAN",
184209
facet = c("Replicate", "Condition"))
185210
```
186211

187-
![](visualization_files/figure-html/unnamed-chunk-10-1.png)
212+
![](visualization_files/figure-html/unnamed-chunk-11-1.png)
188213

189214
## Histogram of fold changes and p-values for test
190215

@@ -195,7 +220,7 @@ visualize.rank(dataImput, listName = "POLK_HUMAN",
195220
visualize.test(anlys_modt$`100pmol-50pmol`)
196221
```
197222

198-
![](visualization_files/figure-html/unnamed-chunk-11-1.png)
223+
![](visualization_files/figure-html/unnamed-chunk-12-1.png)
199224

200225
If the input `dataSet` is the whole list `anlys_modt`, **msDiaLogue**
201226
will produce individual subplots corresponding to each comparison.
@@ -205,7 +230,7 @@ will produce individual subplots corresponding to each comparison.
205230
visualize.test(anlys_modt)
206231
```
207232

208-
![](visualization_files/figure-html/unnamed-chunk-12-1.png)
233+
![](visualization_files/figure-html/unnamed-chunk-13-1.png)
209234

210235
### Details
211236

@@ -230,7 +255,7 @@ combinations of sets.
230255
visualize.upset(dataSet)
231256
```
232257

233-
![](visualization_files/figure-html/unnamed-chunk-13-1.png)
258+
![](visualization_files/figure-html/unnamed-chunk-14-1.png)
234259

235260
This plot reveals that 42 proteins are shared by 50pmol, 100pmol, and
236261
200pmol, while only 3 proteins are shared by 100 pmol and 200pmol, but
@@ -249,7 +274,7 @@ visualize.venn(dataSet, show_percentage = TRUE,
249274
saveRes = TRUE)
250275
```
251276

252-
![](visualization_files/figure-html/unnamed-chunk-14-1.png)
277+
![](visualization_files/figure-html/unnamed-chunk-15-1.png)
253278

254279
where `saveRes = TRUE` refers to the data containing logical columns
255280
representing sets in Venn plot information will be saved as a .csv file
@@ -270,7 +295,7 @@ visualize.volcano(anlys_modt$`100pmol-50pmol`, P.thres = 0.05, F.thres = 1)
270295
#> (`geom_text_repel()`).
271296
```
272297

273-
![](visualization_files/figure-html/unnamed-chunk-15-1.png)
298+
![](visualization_files/figure-html/unnamed-chunk-16-1.png)
274299

275300
If the input `dataSet` is the whole list `anlys_modt`, **msDiaLogue**
276301
will produce individual subplots corresponding to each comparison.
@@ -282,7 +307,7 @@ visualize.volcano(anlys_modt, P.thres = 0.05, F.thres = 1)
282307
#> (`geom_text_repel()`).
283308
```
284309

285-
![](visualization_files/figure-html/unnamed-chunk-16-1.png)
310+
![](visualization_files/figure-html/unnamed-chunk-17-1.png)
286311

287312
### Details
288313

@@ -310,7 +335,7 @@ visualize.scree(anlys_pca, type = c("bar", "line"),
310335
label = TRUE, ncp = 10)
311336
```
312337

313-
![](visualization_files/figure-html/unnamed-chunk-17-1.png)
338+
![](visualization_files/figure-html/unnamed-chunk-18-1.png)
314339

315340
where `label = TRUE` adds information labels at the top of bars/points,
316341
and `ncp = 10` sets the number of dimension to be displayed.
@@ -324,7 +349,7 @@ and `ncp = 10` sets the number of dimension to be displayed.
324349
visualize.score(anlys_pca, ellipse = TRUE, ellipse.level = 0.95, label = TRUE)
325350
```
326351

327-
![](visualization_files/figure-html/unnamed-chunk-18-1.png)
352+
![](visualization_files/figure-html/unnamed-chunk-19-1.png)
328353

329354
### Details
330355

@@ -348,7 +373,7 @@ provided), for each groups (condition) provided.
348373
visualize.loading(anlys_pca, label = TRUE)
349374
```
350375

351-
![](visualization_files/figure-html/unnamed-chunk-19-1.png)
376+
![](visualization_files/figure-html/unnamed-chunk-20-1.png)
352377

353378
### Details
354379

@@ -372,7 +397,7 @@ number of proteins, this plot can be unwieldy.
372397
visualize.biplot(anlys_pca, ellipse = TRUE, ellipse.level = 0.95, label = "all")
373398
```
374399

375-
![](visualization_files/figure-html/unnamed-chunk-20-1.png)
400+
![](visualization_files/figure-html/unnamed-chunk-21-1.png)
376401

377402
## VIP score plot
378403

@@ -389,7 +414,7 @@ each condition.
389414
visualize.vip(anlys_plsda, comp = 1, num = 10, thres = 1)
390415
```
391416

392-
![](visualization_files/figure-html/unnamed-chunk-21-1.png)
417+
![](visualization_files/figure-html/unnamed-chunk-22-1.png)
393418

394419
[
395420
Previous](https://uconn-scs.github.io/msDiaLogue/articles/analysis.md)
-45.9 KB
Loading
114 KB
Loading
-30.8 KB
Loading
36 KB
Loading

0 commit comments

Comments
 (0)