Skip to content

Commit 4cf91b0

Browse files
committed
fix plotting of shapes for second factor
1 parent ecc3d34 commit 4cf91b0

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

R/scatter_chart_class.R

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,14 @@ setMethod(f="chart_plot",
176176
} else {
177177
slabels = dobj$sample_meta[[obj$label_factor]]
178178
}
179-
obj$factor_name=obj$factor_name[[1]] # only use the first factor from now on
180-
179+
181180
x=dobj$data[,obj$xcol]
182181
y=dobj$data[,obj$ycol]
183182
xlabel=obj$xcol
184183
ylabel=obj$ycol
185184

186185
# get the factor from meta data
187-
groups=dobj$sample_meta[[obj$factor_name]]
186+
groups=dobj$sample_meta[[obj$factor_name[[1]]]]
188187

189188
# add a space to the front of the labels to offset them from the points, because nudge_x is in data units
190189
for (i in 1:length(slabels)) {
@@ -210,24 +209,21 @@ setMethod(f="chart_plot",
210209
# add invisible sample points for ellipse
211210
out = out+geom_point(data=A,aes_string(x='x',y='y'),alpha=0,show.legend=FALSE)
212211

213-
214-
if (length(obj$factor_name)==2) {
212+
if (length(shapes)>1) {
215213
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group,shape=~shapes))
216-
} else {
217-
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group))
214+
} else {
215+
out=out+geom_point(data=A, aes_(x=~x,y=~y,colour=~group),shape=shapes)
218216
}
219-
220-
221217
out=out+
222218

223219
geom_point(na.rm=TRUE) +
224220
xlab(xlabel) +
225221
ylab(ylabel)
226222

227-
if (length(obj$factor_name)==2) {
223+
if (length(shapes)>1) {
228224
out=out+labs(shape=obj$factor_name[[2]],colour=obj$factor_name[[1]])
229225
} else {
230-
out=out+labs(shape=obj$factor_name[[1]])
226+
out=out+labs(color=obj$factor_name[[1]])
231227
}
232228

233229
if (obj$ellipse %in% c('all','group')) {
@@ -237,10 +233,10 @@ setMethod(f="chart_plot",
237233

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

0 commit comments

Comments
 (0)