[R] problem tick marker and text

Peter Ehlers ehlers at ucalgary.ca
Fri Nov 27 17:16:57 CET 2009


Duijvesteijn, Naomi wrote:
>    Hi R-ers,
> 
> 
>    I am struggling with my x-axis in a association plot. What I would like is
>    to place the labels of the x-axis between the tick markers and normally the
>    labels are printed at the place where the tick marker is placed. I don’t
>    want to move the tick marker (it gives the switch between one chromosome and
>    the next) but I just want to put the chromosome number in between the two
>    tick markers.
> 
> 
>    This example from mhtplot has the chromosome number at the place of the
>    tickmarker. How can I change this to ‘in between’?
> 
> 
>    Thanks!,
> 
> 
>    Naomi
>  
Kudos for including reproducible code, BUT
1. do you really consider a dataframe of
    dimension ~500K by 3 to be "minimal"?
2. there are over 2000 R-packages on CRAN;
    wouldn't it be polite to say which one contains mhtplot()?

> # fake example with Affy500k data
> affy <-c(40220, 41400, 33801, 32334, 32056, 31470, 25835, 27457, 22864, 28501, 
> 26273, 
>          24954, 19188, 15721, 14356, 15309, 11281, 14881, 6399, 12400, 7125, 62
> 07)
> CM <- cumsum(affy)

is CM used anywhere?

> n.markers <- sum(affy)
> n.chr <- length(affy)
> test <- data.frame(chr=rep(1:n.chr,affy),pos=1:n.markers,p=runif(n.markers))
>  
> oldpar <- par()
> par(las="1",cex=0.6)
> colors <- rep(c("blue","green"),11)
> par(cex.axis=1.3)
> mhtplot(test,usepos=TRUE,colors=colors,gap=10000,pch=19,bg=colors)
> box()
> par(oldpar)
> 
Here is one way, using about half the data.
I use mtext() to place the labels, since axis= seems
to be hard-coded in mhtplot.

# make a vector of labels to place between ticks
textvec <- letters[1:5]

# plot
mhtplot(test[1:2e5,],usepos=TRUE,colors=colors,gap=10000,pch=19,bg=colors)

# now figure out where to put the labels. This would be
# easy with seq() if the scale were uniform but it's not.
# So we use the locator() function.

xat <- locator()$x
xat <- round(xat)
xat
#[1]  34316  85096 132458 173961 216929

# place the labels; adjust line= if you wish
mtext(textvec, side=1, line=0, at=xat)

If I had to do this frequently, I would hack the
mhtplot() function.

  -Peter Ehlers

>    
>    
>    
>    Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
>    vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
>    Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet te
>    gebruiken, de afzender direct te informeren en het bericht te vernietigen.
>    Aan dit bericht kunnen geen rechten of plichten worden ontleend.
> 
>    ----------------------------------------------------------------------------
>    ----------------------------
> 
>    Disclaimer: The information contained in this message may be confidential
>    and is intended to be exclusively for the addressee. Should you receive this
>    message unintentionally, you are expected not to use the contents herein, to
>    notify the sender immediately and to destroy the message. No rights can be
>    derived from this message.
> 
>    
>    P Please consider the environment before printing this email
> 
> 
> ------------------------------------------------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list