@@ -249,18 +249,26 @@ setMethod(f="chart_plot",
249
249
}
250
250
251
251
if (is(opt $ groups ,' factor' ) | is(opt $ groups ,' character' )) {
252
- plotClass = createClassAndColors(opt $ groups )
252
+ plotClass = structToolbox ::: createClassAndColors(opt $ groups )
253
253
opt $ groups = plotClass $ class
254
254
}
255
255
256
256
# 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
+
258
264
259
265
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 ))
261
267
} 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 ))
263
269
}
270
+
271
+
264
272
out = out +
265
273
266
274
geom_point(na.rm = TRUE ) +
@@ -282,12 +290,11 @@ setMethod(f="chart_plot",
282
290
if (is(opt $ groups ,' factor' )) { # if a factor then plot by group using the colours from pmp package
283
291
out = out + scale_colour_manual(values = plotClass $ manual_colors ,
284
292
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
287
294
out = out + scale_colour_viridis_c(limits = quantile(opt $ groups ,
288
295
c(0.05 ,0.95 ),na.rm = TRUE ),oob = squish ,name = opt $ factor_name )
289
296
}
290
- out = out + theme_Publication(base_size = 12 )
297
+ out = out + structToolbox ::: theme_Publication(base_size = 12 )
291
298
# add ellipse for all samples (ignoring group)
292
299
if (obj $ ellipse %in% c(' all' ,' sample' )) {
293
300
out = out + stat_ellipse(type = obj $ ellipse_type ,mapping = aes(x = x ,y = y ),
@@ -310,7 +317,8 @@ setMethod(f="chart_plot",
310
317
{
311
318
temp = subset(points ,! points $ in .ell )
312
319
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 )
314
322
315
323
}
316
324
}
@@ -319,9 +327,8 @@ setMethod(f="chart_plot",
319
327
}
320
328
321
329
# 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 )
325
332
}
326
333
327
334
return (out )
0 commit comments