Skip to content

Commit d3722c3

Browse files
committed
update visualize.heatmap() to show missing data pattern (fixes #6)
1 parent 4a944b7 commit d3722c3

25 files changed

Lines changed: 127 additions & 61 deletions

R/visualizations.R

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,18 @@ visualize.heatmap <- function(dataSet, pkg = "pheatmap",
9595
plotData <- t(select(dataSet, -c(R.Condition, R.Replicate)))
9696
colnames(plotData) <- paste0(dataSet$R.Condition, "_", dataSet$R.Replicate)
9797

98-
pheatmap(mat = plotData,
99-
cluster_cols = cluster_cols, cluster_rows = cluster_rows,
100-
show_colnames = show_colnames, show_rownames = show_rownames)
98+
if (anyNA(plotData)) {
99+
plotData <- ifelse(is.na(plotData), 0, 1)
100+
pheatmap(mat = plotData,
101+
color = c("white", "black"), legend_breaks = c(0, 1),
102+
legend_labels = c("Missing value", "Valid value"),
103+
cluster_cols = cluster_cols, cluster_rows = cluster_rows,
104+
show_colnames = show_colnames, show_rownames = show_rownames)
105+
} else {
106+
pheatmap(mat = plotData,
107+
cluster_cols = cluster_cols, cluster_rows = cluster_rows,
108+
show_colnames = show_colnames, show_rownames = show_rownames)
109+
}
101110

102111
} else if (pkg == "ggplot2") {
103112

@@ -107,15 +116,27 @@ visualize.heatmap <- function(dataSet, pkg = "pheatmap",
107116
select(-c(R.Condition, R.Replicate)) %>%
108117
pivot_longer(-R.ConRep)
109118

110-
ggplot(plotData, aes(x = R.ConRep, y = name, fill = value)) +
111-
geom_tile() +
112-
guides(fill = guide_colourbar(title = NULL)) +
113-
scale_y_discrete(limits = rev) +
114-
scale_fill_distiller(palette = "RdYlBu") +
115-
theme(axis.text.x = element_text(angle = -90, vjust = .5)) +
116-
xlab(NULL) +
117-
ylab(NULL)
118-
119+
if (anyNA(plotData$value)) {
120+
ggplot(plotData, aes(x = R.ConRep, y = name, fill = factor(!is.na(value)))) +
121+
geom_tile(color = "grey60") +
122+
guides(fill = guide_legend(title = NULL)) +
123+
scale_fill_manual(values = c("TRUE" = "black", "FALSE" = "white"),
124+
labels = c("FALSE" = "Missing value", "TRUE" = "Valid value"),
125+
drop = FALSE) +
126+
scale_y_discrete(limits = rev) +
127+
theme(axis.text.x = element_text(angle = -90, vjust = .5)) +
128+
xlab(NULL) +
129+
ylab(NULL)
130+
} else {
131+
ggplot(plotData, aes(x = R.ConRep, y = name, fill = value)) +
132+
geom_tile(color = "grey60") +
133+
guides(fill = guide_colourbar(title = NULL)) +
134+
scale_y_discrete(limits = rev) +
135+
scale_fill_distiller(palette = "RdYlBu") +
136+
theme(axis.text.x = element_text(angle = -90, vjust = .5)) +
137+
xlab(NULL) +
138+
ylab(NULL)
139+
}
119140
}
120141
}
121142

docs/articles/visualization.html

Lines changed: 42 additions & 31 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: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ visualize.heatmap(dataImput, pkg = "pheatmap",
7575
When protein names are excessively long, it is recommended to set
7676
`show_rownames = FALSE` to view the full heatmap.
7777

78+
If the input data contains an NA value, the heatmap will be binary for
79+
missing data patterns, i.e., whether values are present or absent.
80+
81+
``` r
82+
83+
visualize.heatmap(dataSet, pkg = "pheatmap",
84+
cluster_cols = TRUE, cluster_rows = TRUE,
85+
show_colnames = TRUE, show_rownames = TRUE)
86+
```
87+
88+
![](visualization_files/figure-html/unnamed-chunk-5-1.png)
89+
7890
- Option 2 use the source package `ggplot2` to generate a ggplot object
7991
but does not include the dendrogram.
8092

@@ -83,12 +95,19 @@ When protein names are excessively long, it is recommended to set
8395
visualize.heatmap(dataImput, pkg = "ggplot2")
8496
```
8597

86-
![](visualization_files/figure-html/unnamed-chunk-5-1.png)
98+
![](visualization_files/figure-html/unnamed-chunk-6-1.png)
8799

88100
In a heatmap, similar colors within a row indicate relatively consistent
89101
values, suggesting similar protein expression levels across different
90102
samples.
91103

104+
``` r
105+
106+
visualize.heatmap(dataSet, pkg = "ggplot2")
107+
```
108+
109+
![](visualization_files/figure-html/unnamed-chunk-7-1.png)
110+
92111
## MA plot
93112

94113
### Examples
@@ -100,7 +119,7 @@ visualize.ma(anlys_ma$`100pmol-50pmol`, M.thres = 1)
100119
#> (`geom_text_repel()`).
101120
```
102121

103-
![](visualization_files/figure-html/unnamed-chunk-6-1.png)
122+
![](visualization_files/figure-html/unnamed-chunk-8-1.png)
104123

105124
where `M.thres = 1` means the M thresholds are set to -1 and 1. The
106125
scatters are split into three parts: up regulation (M \> 1), no
@@ -118,7 +137,7 @@ visualize.ma(anlys_ma, M.thres = 1)
118137
#> (`geom_text_repel()`).
119138
```
120139

121-
![](visualization_files/figure-html/unnamed-chunk-7-1.png)
140+
![](visualization_files/figure-html/unnamed-chunk-9-1.png)
122141

123142
### Details
124143

@@ -165,7 +184,7 @@ visualize.rank(dataImput, listName = "POLK_HUMAN",
165184
facet = c("Replicate", "Condition"))
166185
```
167186

168-
![](visualization_files/figure-html/unnamed-chunk-8-1.png)
187+
![](visualization_files/figure-html/unnamed-chunk-10-1.png)
169188

170189
## Histogram of fold changes and p-values for test
171190

@@ -176,7 +195,7 @@ visualize.rank(dataImput, listName = "POLK_HUMAN",
176195
visualize.test(anlys_modt$`100pmol-50pmol`)
177196
```
178197

179-
![](visualization_files/figure-html/unnamed-chunk-9-1.png)
198+
![](visualization_files/figure-html/unnamed-chunk-11-1.png)
180199

181200
If the input `dataSet` is the whole list `anlys_modt`, **msDiaLogue**
182201
will produce individual subplots corresponding to each comparison.
@@ -186,7 +205,7 @@ will produce individual subplots corresponding to each comparison.
186205
visualize.test(anlys_modt)
187206
```
188207

189-
![](visualization_files/figure-html/unnamed-chunk-10-1.png)
208+
![](visualization_files/figure-html/unnamed-chunk-12-1.png)
190209

191210
### Details
192211

@@ -211,7 +230,7 @@ combinations of sets.
211230
visualize.upset(dataSet)
212231
```
213232

214-
![](visualization_files/figure-html/unnamed-chunk-11-1.png)
233+
![](visualization_files/figure-html/unnamed-chunk-13-1.png)
215234

216235
This plot reveals that 42 proteins are shared by 50pmol, 100pmol, and
217236
200pmol, while only 3 proteins are shared by 100 pmol and 200pmol, but
@@ -230,7 +249,7 @@ visualize.venn(dataSet, show_percentage = TRUE,
230249
saveRes = TRUE)
231250
```
232251

233-
![](visualization_files/figure-html/unnamed-chunk-12-1.png)
252+
![](visualization_files/figure-html/unnamed-chunk-14-1.png)
234253

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

254-
![](visualization_files/figure-html/unnamed-chunk-13-1.png)
273+
![](visualization_files/figure-html/unnamed-chunk-15-1.png)
255274

256275
If the input `dataSet` is the whole list `anlys_modt`, **msDiaLogue**
257276
will produce individual subplots corresponding to each comparison.
@@ -263,7 +282,7 @@ visualize.volcano(anlys_modt, P.thres = 0.05, F.thres = 1)
263282
#> (`geom_text_repel()`).
264283
```
265284

266-
![](visualization_files/figure-html/unnamed-chunk-14-1.png)
285+
![](visualization_files/figure-html/unnamed-chunk-16-1.png)
267286

268287
### Details
269288

@@ -291,7 +310,7 @@ visualize.scree(anlys_pca, type = c("bar", "line"),
291310
label = TRUE, ncp = 10)
292311
```
293312

294-
![](visualization_files/figure-html/unnamed-chunk-15-1.png)
313+
![](visualization_files/figure-html/unnamed-chunk-17-1.png)
295314

296315
where `label = TRUE` adds information labels at the top of bars/points,
297316
and `ncp = 10` sets the number of dimension to be displayed.
@@ -305,7 +324,7 @@ and `ncp = 10` sets the number of dimension to be displayed.
305324
visualize.score(anlys_pca, ellipse = TRUE, ellipse.level = 0.95, label = TRUE)
306325
```
307326

308-
![](visualization_files/figure-html/unnamed-chunk-16-1.png)
327+
![](visualization_files/figure-html/unnamed-chunk-18-1.png)
309328

310329
### Details
311330

@@ -329,7 +348,7 @@ provided), for each groups (condition) provided.
329348
visualize.loading(anlys_pca, label = TRUE)
330349
```
331350

332-
![](visualization_files/figure-html/unnamed-chunk-17-1.png)
351+
![](visualization_files/figure-html/unnamed-chunk-19-1.png)
333352

334353
### Details
335354

@@ -353,7 +372,7 @@ number of proteins, this plot can be unwieldy.
353372
visualize.biplot(anlys_pca, ellipse = TRUE, ellipse.level = 0.95, label = "all")
354373
```
355374

356-
![](visualization_files/figure-html/unnamed-chunk-18-1.png)
375+
![](visualization_files/figure-html/unnamed-chunk-20-1.png)
357376

358377
## VIP score plot
359378

@@ -370,7 +389,7 @@ each condition.
370389
visualize.vip(anlys_plsda, comp = 1, num = 10, thres = 1)
371390
```
372391

373-
![](visualization_files/figure-html/unnamed-chunk-19-1.png)
392+
![](visualization_files/figure-html/unnamed-chunk-21-1.png)
374393

375394
[
376395
Previous](https://uconn-scs.github.io/msDiaLogue/articles/analysis.md)
83.3 KB
Loading
5.14 KB
Loading
-17.8 KB
Loading
-37.7 KB
Loading
-17.2 KB
Loading
-12 KB
Loading
6.72 KB
Loading

0 commit comments

Comments
 (0)