how to remove the text of sample ids (e.g. Mock_0,Mock_1) in MDS plot from a ggplot2 object

54 views
Skip to first unread message

Quan Gu

unread,
Jun 29, 2016, 9:37:34 AM6/29/16
to ggplot2

Hi All

Anybody know how to remove the text of sample ids (e.g. Mock_0,Mock_1)  in MDS plot in CummeRbund?
My command is 
genes.MDS<-MDSplot(genes(cuff),replicates=T) +xlim(c(-0.1,0.1))

MDSplot in CummeRbund package generates a ggplot2 object. But I don't know how to remove the text of sample ids.


Thank you!
mock-poly.png

Mehmet Gültaş

unread,
Jun 29, 2016, 11:27:04 AM6/29/16
to ggplot2
Hi Gu,

I read the source code (here, https://github.com/Bioconductor-mirror/cummeRbund/blob/054b54b7931cfc9645a83f663787f15b203a5bd0/R/methods-CuffData.R)
Found that bit;

.MDSplot<-function(object,replicates=FALSE,logMode=TRUE,pseudocount=1.0){
 p
<- p + geom_point(aes(x=M1,y=M2,color=names)) + geom_text(aes(x=M1,y=M2,label=names,color=names)) + theme_bw()
 p
 
}


As far as I can see this function uses aes(label = ) attribute to give every point as name within the graph.
And I read a solution to this question from stackexchange.
http://stackoverflow.com/questions/15624656/label-points-in-geom-point

You may suppress the default behavior may be by that


genes.MDS<-MDSplot(genes(cuff),replicates=T) +xlim(c(-0.1,0.1)) + geom_point(aes(label = NULL))


I am not sure about the solution.

Best,
Mehmet

Mehmet Gültaş

unread,
Jun 29, 2016, 11:32:26 AM6/29/16
to ggplot2
Hi,

My previous solution attempt probably won't work. Try this one:

genes.MDS<-MDSplot(genes(cuff),replicates=T) + xlim(c(-0.1,0.1)) + geom_text(aes(label = NULL))


On Wednesday, June 29, 2016 at 4:37:34 PM UTC+3, Quan Gu wrote:

Quan Gu

unread,
Jun 29, 2016, 11:43:14 AM6/29/16
to ggplot2
Thank you! 
I have found that as well but I don't know how to revise the source code of Cummrbund.
And I have tried your code 
it still has the error
'Error: geom_text requires the following missing aesthetics: x, y, label'
How could I do then?

Mehmet Gültaş

unread,
Jun 29, 2016, 12:28:31 PM6/29/16
to ggplot2

These may work. I'm out of options

genes.MDS<-MDSplot(genes(cuff),replicates=T) + xlim(c(-0.1,0.1)) + geom_text(aes(x = M1, y = M2, label = element_blank()))

genes.MDS<-MDSplot(genes(cuff),replicates=T) + xlim(c(-0.1,0.1)) + geom_text(aes(x = M1, y = M2, label = NULL))

Gu

unread,
Jun 30, 2016, 7:21:16 AM6/30/16
to ggplot2
Sorry !
still error!
genes.MDS<-MDSplot(genes(cuff),replicates=T) + xlim(c(-0.1,0.1)) + geom_text(aes(x = M1, y = M2, label = NULL))
Error: geom_text requires the following missing aesthetics: label

if I change to genes.MDS<-MDSplot(genes(cuff),replicates=T) + xlim(c(-0.1,0.1)) + geom_text(aes(x = M1, y = M2, label = 'A'))
It is the figure attached.

Could I edit their source code and regenerated a CummeRbund_v2 package instead?
temp.png

Crump, Ron

unread,
Jun 30, 2016, 8:09:50 AM6/30/16
to Gu, ggplot2
Hi,

>Could I edit their source code and regenerated a CummeRbund_v2 package
>instead?

If you want to do this kind of plot a lot, then I would suggest copying
the code for their MDSplot function and making your own copy, either with
the geom_text bit removed or with it's use parameterised.

In the meantime, I had a quick play and this may help.

# Create a data.frame to play with:
DF <- data.frame(x=1:10,y=1:10,l=letters[1:10],stringsAsFactors=FALSE)

# Create a simple ggplot object with text labelling:
zz<-ggplot(DF)+geom_point(aes(x=x,y=y))+geom_text(aes(x=x,y=y,label=l),nudg
e_x=0.2)

Then I took a look at zz:

> length(zz)
[1] 9
> names(zz)
[1] "data" "layers" "scales" "mapping" "theme"
"coordinates"
[7] "facet" "plot_env" "labels"
> zz$layers
[[1]]
mapping: x = x, y = y
geom_point: na.rm = FALSE
stat_identity: na.rm = FALSE
position_identity

[[2]]
mapping: x = x, y = y, label = l
geom_text: parse = FALSE, check_overlap = FALSE, na.rm = FALSE
stat_identity: na.rm = FALSE
position_nudge




So zz$layers[2] appears to define the geom_text call (in my case, I guess
it may differ depending the order of creating layers in MDSplot).

#Then I created a copy of zz
zz2<-zz
# and removed that layer
zz2$layers[2] <- NULL

And zz2 now has my plot without labelled points.



I hope this is of some use in fixing up this plot. As you pointed out a
personalised MDSplot would be the better long term solution (but I
wouldn't go so far as creating a whole new cummeRbund_v2 package for it -
maybe you could maybe suggest additional options to control the plotting
to the package authors).

Regards,
Ron.

Reply all
Reply to author
Forward
0 new messages