Skip to content

Commit 954f5ca

Browse files
committed
fix #16
1 parent fc755cd commit 954f5ca

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

R/PCA_plotfcns.R

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,26 @@ setMethod(f="chart_plot",
249249
}
250250

251251
if (is(opt$groups,'factor') | is(opt$groups,'character')) {
252-
plotClass= createClassAndColors(opt$groups)
252+
plotClass= structToolbox:::createClassAndColors(opt$groups)
253253
opt$groups=plotClass$class
254254
}
255255

256256
# build the plot
257-
A <- data.frame (group=opt$groups,x=x, y=y)
257+
A <- data.frame (group=opt$groups,x=x, y=y,slabels=slabels)
258+
259+
out = ggplot()
260+
261+
# add invisible sample points for ellipse
262+
out = out+geom_point(data=A,aes_string(x='x',y='y'),alpha=0,show.legend=FALSE)
263+
258264

259265
if (length(obj$factor_name)==2) {
260-
out=ggplot (data=A, aes_(x=~x,y=~y,colour=~group,label=~slabels,shape=~shapes))
266+
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group,shape=~shapes))
261267
} else {
262-
out=ggplot (data=A, aes_(x=~x,y=~y,colour=~group,label=~slabels))
268+
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group))
263269
}
270+
271+
264272
out=out+
265273

266274
geom_point(na.rm=TRUE) +
@@ -282,12 +290,11 @@ setMethod(f="chart_plot",
282290
if (is(opt$groups,'factor')) { # if a factor then plot by group using the colours from pmp package
283291
out=out+scale_colour_manual(values=plotClass$manual_colors,
284292
name=opt$factor_name)
285-
}
286-
else {# assume continuous and use the default colour gradient
293+
}else {# assume continuous and use the default colour gradient
287294
out=out+scale_colour_viridis_c(limits=quantile(opt$groups,
288295
c(0.05,0.95),na.rm = TRUE),oob=squish,name=opt$factor_name)
289296
}
290-
out=out+theme_Publication(base_size = 12)
297+
out=out+structToolbox:::theme_Publication(base_size = 12)
291298
# add ellipse for all samples (ignoring group)
292299
if (obj$ellipse %in% c('all','sample')) {
293300
out=out+stat_ellipse(type=obj$ellipse_type,mapping=aes(x=x,y=y),
@@ -310,7 +317,8 @@ setMethod(f="chart_plot",
310317
{
311318
temp=subset(points,!points$in.ell)
312319
temp$group=opt$groups[!points$in.ell]
313-
out=out+geom_text(data=temp,aes_(x=~x,y=~y,label=~label,colour=~group),size=obj$label_size,vjust="inward",hjust="inward")
320+
temp$label=slabels[!points$in.ell]
321+
out=out+geom_text(data=temp,aes_(x=~x,y=~y,label=~label,colour=~group),size=obj$label_size,vjust="inward",hjust="inward",show.legend=FALSE)
314322

315323
}
316324
}
@@ -319,9 +327,8 @@ setMethod(f="chart_plot",
319327
}
320328

321329
# label all points if requested
322-
if (opt$points_to_label=='all')
323-
{
324-
out=out+geom_text(vjust="inward",hjust="inward")
330+
if (opt$points_to_label=='all') {
331+
out=out+geom_text(data=A,aes_string(x='x',y='y',colour='group',label='slabels'),vjust="inward",hjust="inward",show.legend=FALSE)
325332
}
326333

327334
return(out)

0 commit comments

Comments
 (0)