Skip to content

Commit 98292b2

Browse files
committed
add ellipse plotting options
- allow norm or t distributed ellipses - allow changing confidence level
1 parent 6fffcc4 commit 98292b2

File tree

5 files changed

+57
-18
lines changed

5 files changed

+57
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: structToolbox
22
Type: Package
33
Title: Data processing & analysis tools for Metabolomics and other omics
4-
Version: 1.3.4
4+
Version: 1.3.5
55
Authors@R: c(
66
person(
77
c("Gavin","Rhys"),

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Changes 1.3.5
2+
+ add ellipse plotting options to pca_scores_plot
3+
14
Changes 1.3.4
25
+ mv_sample_filter can be used in train/predict mode
36

R/PCA_plotfcns.R

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ pca_scores_plot = function(
7878
points_to_label='none',
7979
factor_name,
8080
ellipse='all',
81+
ellipse_type='norm',
82+
ellipse_confidence=0.95,
8183
label_filter=character(0),
8284
label_factor='rownames',
8385
label_size=3.88,
@@ -90,6 +92,8 @@ pca_scores_plot = function(
9092
label_filter=label_filter,
9193
label_factor=label_factor,
9294
label_size=label_size,
95+
ellipse_type=ellipse_type,
96+
ellipse_confidence=ellipse_confidence,
9397
...)
9498
return(out)
9599
}
@@ -104,6 +108,8 @@ pca_scores_plot = function(
104108
points_to_label='enum',
105109
factor_name='entity',
106110
ellipse='enum',
111+
ellipse_type='enum',
112+
ellipse_confidence='entity',
107113
label_filter='entity',
108114
label_factor='entity',
109115
label_size='entity'
@@ -112,7 +118,9 @@ pca_scores_plot = function(
112118
prototype = list(name='PCA scores plot',
113119
description='Plots a 2d scatter plot of the selected components',
114120
type="scatter",
115-
.params=c('components','points_to_label','factor_name','ellipse','label_filter','label_factor','label_size'),
121+
.params=c('components','points_to_label','factor_name','ellipse',
122+
'label_filter','label_factor','label_size','ellipse_type',
123+
'ellipse_confidence'),
116124

117125
components=entity(name='Components to plot',
118126
value=c(1,2),
@@ -135,13 +143,34 @@ pca_scores_plot = function(
135143
ellipse=enum(
136144
name = 'Plot ellipses',
137145
description=c(
138-
"all" = paste0('Hotelling T2 95\\% ellipses are plotted for all groups and all samples.'),
139-
"group" = 'Hotelling T2 95\\% ellipses are plotted for all groups.',
146+
"all" = paste0('Ellipses are plotted for all groups and all samples.'),
147+
"group" = 'Ellipses are plotted for all groups.',
140148
"none" = 'Ellipses are not included on the plot.',
141-
"sample" = 'A Hotelling T2 95\\% ellipse is plotted for all samples (ignoring group)'),
149+
"sample" = 'An ellipse is plotted for all samples (ignoring group)'),
142150
allowed=c('all','group','none','sample'),
143151
value='all'
144152
),
153+
154+
ellipse_type=enum(
155+
name='Type of ellipse',
156+
description=c(
157+
'norm' = paste0('Multivariate normal (p = 0.95)'),
158+
't' = paste0('Multivariate t (p = 0.95)')
159+
),
160+
value='norm',
161+
type='character',
162+
max_length = 1,
163+
allowed=c('norm','t')
164+
),
165+
166+
ellipse_confidence=entity(
167+
name='Ellipse confidence level',
168+
description='The confidence level for plotting ellipses.',
169+
value=0.95,
170+
type='numeric',
171+
max_length = 1
172+
),
173+
145174
label_filter=entity(
146175
name='Label filter',
147176
value=character(0),
@@ -246,19 +275,24 @@ setMethod(f="chart_plot",
246275
}
247276

248277
if (obj$ellipse %in% c('all','group')) {
249-
out = out +stat_ellipse(type='norm') # ellipse for individual groups
278+
out = out +stat_ellipse(type=obj$ellipse_type,
279+
level=obj$ellipse_confidence) # ellipse for individual groups
250280
}
251281

252282
if (is(opt$groups,'factor')) { # if a factor then plot by group using the colours from pmp package
253-
out=out+scale_colour_manual(values=plotClass$manual_colors,name=opt$factor_name)
283+
out=out+scale_colour_manual(values=plotClass$manual_colors,
284+
name=opt$factor_name)
254285
}
255286
else {# assume continuous and use the default colour gradient
256-
out=out+scale_colour_viridis_c(limits=quantile(opt$groups,c(0.05,0.95),na.rm = TRUE),oob=squish,name=opt$factor_name)
287+
out=out+scale_colour_viridis_c(limits=quantile(opt$groups,
288+
c(0.05,0.95),na.rm = TRUE),oob=squish,name=opt$factor_name)
257289
}
258290
out=out+theme_Publication(base_size = 12)
259291
# add ellipse for all samples (ignoring group)
260292
if (obj$ellipse %in% c('all','sample')) {
261-
out=out+stat_ellipse(type='norm',mapping=aes(x=x,y=y),colour="#C0C0C0",linetype='dashed',data=A)
293+
out=out+stat_ellipse(type=obj$ellipse_type,mapping=aes(x=x,y=y),
294+
colour="#C0C0C0",linetype='dashed',data=A,
295+
level=obj$ellipse_confidence)
262296
}
263297

264298
if (obj$ellipse %in% c('all','sample')) { # only do this if we plotted the sample ellipse

man/model_apply.Rd

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

man/pca_scores_plot.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)