Skip to content

Commit

Permalink
fix plotting of multiple factors
Browse files Browse the repository at this point in the history
  • Loading branch information
grlloyd committed Feb 6, 2023
1 parent 4cf91b0 commit 8c0d59a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions R/scatter_chart_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,19 @@ setMethod(f="chart_plot",
}

# build the plot
A <- data.frame (group=groups,x=x, y=y,slabels=slabels)
A <- data.frame (group=groups,x=x, y=y,slabels=slabels,shape=shapes)

out = ggplot()

# add invisible sample points for ellipse
out = out+geom_point(data=A,aes_string(x='x',y='y'),alpha=0,show.legend=FALSE)

if (length(shapes)>1) {
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group,shape=~shapes))
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group,shape=~shape))
} else {
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group),shape=shapes)
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group),shape=shapes)
}

out=out+

geom_point(na.rm=TRUE) +
Expand All @@ -227,16 +228,23 @@ setMethod(f="chart_plot",
}

if (obj$ellipse %in% c('all','group')) {
out = out +stat_ellipse(data=A, aes_(x=~x,y=~y,colour=~group),type=obj$ellipse_type,
if (is.factor(groups)) {
out = out +stat_ellipse(data=A, aes_(x=~x,y=~y,colour=~group,group=~group),type=obj$ellipse_type,
level=obj$ellipse_confidence) # ellipse for individual groups
} else {
if (is.factor(shapes)) {
out = out +stat_ellipse(data=A, aes_(x=~x,y=~y,group=~shape),color="#C0C0C0",type=obj$ellipse_type,
level=obj$ellipse_confidence) # ellipse for individual groups
}
}
}

if (is(groups,'factor')) { # if a factor then plot by group using the colours from pmp package
out=out+scale_colour_manual(values=plotClass$manual_colors,
name=obj$factor_name[[1]])
}else {# assume continuous and use the default colour gradient
} else {# assume continuous and use the default colour gradient
out=out+scale_colour_viridis_c(limits=quantile(groups,
c(0.05,0.95),na.rm = TRUE),oob=squish,name=obj$factor_name[[1]])
c(0.05,0.95),na.rm = TRUE),oob=scales::squish,name=obj$factor_name[[1]])
}
out=out+theme_Publication(base_size = 12)
# add ellipse for all samples (ignoring group)
Expand Down

0 comments on commit 8c0d59a

Please sign in to comment.