From: Jack Luo <jluo.rhelp_at_gmail.com>

Date: Fri, 7 Dec 2007 13:27:11 -0500

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. Received on Fri 07 Dec 2007 - 18:32:36 GMT

Date: Fri, 7 Dec 2007 13:27:11 -0500

Hi, Roland

Thanks a lot for your help, I think it is very helpful. Actually the function I am using in pamr is pamr.plotsurvival, which plots the Kaplan-Meier plot, but I guess your suggestion should work for any type of function, it's really a smart and simple idea, thanks!

Jack

On Dec 7, 2007 12:33 PM, Roland Rau <roland.rproject_at_gmail.com> wrote:

> Hi Jack,

*>
**> Jack Luo wrote:
**> > Dear List,
**> >
**> > I am trying to modify the xlab and ylab for a current figure that was
**> > plotted by a package, I searched through the low level plotting command
**> and
**> > they do not seem to contain how to do this (the only way is to use xlab,
**> > ylab as arguments in "plot" command, which I can not do since the plot
**> is
**> > plotted using some other package, not by my own script). Is there any
**> > command for doing this? In addition, the package is from CRAN (named
**> Pamr),
**> > is there any way that I can modify the function used in the package?
**>
**> I think it would be useful if you are a bit more specific by telling us
**> which function you were using.
**> I assume now that you used
**> library(pamr)
**> pamr.geneplot(...)
**>
**> Is this correct?
**> If you check the package description, you will see that you are allowed
**> to make changes to the software (GPL 2.0).
**> Now, have a look at
**> pamr.geneplot
**>
**> Pretty much in the end, you will find the plotting command. What I did
**> now was to basically slightly modify the function by adding two
**> arguments for the labels of the x-axis and the y-axis to the function
**> definition. As you will see with the provided example, you can make your
**> own labels for the x-axis and y-axis now.
**>
**> I hope this helps,
**> Roland
**>
**>
**> pamr.geneplot.modif <- function(fit, data, threshold, xlabel="new xlab",
**> ylabel="new ylab") {
**> # Slightly modified function of pamr.geneplot from package pamr by
**> # Trevor Hastie, Robert Tibshirani, Balasubramanian Narasimhan,
**> # and Gilbert Chu
**> require(pamr)
**> par(pch = 1, col = 1)
**> geneid <- data$geneid
**> if (is.null(geneid)) {
**> geneid <- as.character(1:nrow(data$x))
**> }
**> if (is.null(fit$newy)) {
**> y <- factor(data$y[fit$sample.subset])
**> }
**> else {
**> y <- factor(fit$newy[fit$sample.subset])
**> }
**> x <- data$x[fit$gene.subset, fit$sample.subset]
**> geneid <- geneid[fit$gene.subset]
**> nc <- length(unique(y))
**> aa <- pamr.predict(fit, x, threshold = threshold, type = "nonzero")
**> cen <- pamr.predict(fit, x, threshold = threshold, type = "cen")
**> d <- (cen - fit$centroid.overall)[aa, ]/fit$sd[aa]
**> oo <- order(-apply(abs(d), 1, max))
**> aa <- aa[oo]
**> ngenes <- length(aa)
**> o <- order(y)
**> xx <- x[aa, o]
**> geneid <- geneid[aa]
**> nc <- length(unique(y))
**> nn <- c(0, cumsum(table(y)))
**> nrow <- trunc(sqrt(ngenes)) + 1
**> ncol <- trunc(sqrt(ngenes)) + 1
**> if (nrow * (ncol - 1) >= ngenes) {
**> ncol <- ncol - 1
**> }
**> par(mfrow = c(nrow, ncol))
**> for (i in 1:ngenes) {
**> plot(1:ncol(xx), xx[i, ], type = "n", xlab = xlabel,
**> ylab = ylabel, axes = FALSE)
**> box()
**> axis(2)
**> for (j in 1:nc) {
**> j1 <- nn[j] + 1
**> j2 <- nn[j] + table(y)[j]
**> points(j1:j2, xx[i, j1:j2], col = j + 1)
**> }
**> title(main = as.character(geneid[i]))
**> for (j in 1:(nc - 1)) {
**> abline(v = cumsum(table(y))[j] + 0.5, lty = 2)
**> }
**> if (i == 1) {
**> h <- c(0, table(y))
**> for (j in 2:(nc + 1)) {
**> text(sum(h[1:(j - 1)]) + 0.5 * h[j], max(xx[i,
**> ]), label =
**> levels(y)[j - 1], col = j)
**> }
**> }
**> }
**> par(mfrow = c(1, 1))
**> }
**>
**> library(pamr)
**> set.seed(120)
**> x <- matrix(rnorm(1000*20),ncol=20)
**> y <- sample(c(1:4),size=20,replace=TRUE)
**> mydata <- list(x=x,y=y)
**> mytrain <- pamr.train(mydata)
**> pamr.geneplot.modif(mytrain, mydata, threshold=1.6, xlabel="Hello",
**> ylabel="World")
**>
**>
*

[[alternative HTML version deleted]]

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. Received on Fri 07 Dec 2007 - 18:32:36 GMT

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Fri 07 Dec 2007 - 19:30:20 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*