Re: [R] pairs: adjusting margins and labeling axes
Hi Michael, is this the direction you'd like to go (simplified)? ?pairs pairs(iris, log="xy", asp=1, gap=0.1) --Bill. On Tue, Jul 19, 2016 at 2:37 PM, Michael Youngwrote: > I want to make this as easy as possible. The extra space could just go > around the plot in the margin area. I could then use a cropping tool to > paste the plot into Excel or Word. > > I'm not opposed to using another package, but I'd need some kind of > pre-existing code to tinker with. > > On Tue, Jul 19, 2016 at 11:16 AM, Greg Snow <538...@gmail.com> wrote: > > > If you want square plots on a rectangular plotting region, then where > > do you want the extra space to go? > > > > One option would be to add outer margins to use up the extra space. > > The calculations to figure out exactly how much space to put in the > > outer margins will probably not be trivial. > > > > Another option would be to not use `pairs`, but use the `layout` > > function directly and loops to do your plots (and use the `respect` > > argument to `layout`). > > > > On Tue, Jul 19, 2016 at 11:29 AM, michael young > > wrote: > > > The default shape for this correlation scatterplot is rectangle. I > > changed > > > it to square, but then the x-axis spacing between squares are off. Is > > > there an easy way to change x-axis spacing between squares to that of > the > > > y-axis spacing size? > > > > > > I decided to hide the name values of the diagonal squares. I want them > > > along the x and y axis instead, outside of the fixed number scale I > have. > > > I haven't seen any online example of 'pairs' with this and all my > > searches > > > have yielded nothing. Any ideas? Thanks > > > > > > par(pty="s") > > > panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...) > > > { > > > usr <- par("usr"); on.exit(par(usr)) > > > par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE) > > > # correlation coefficient > > > r <- cor(x, y) > > > txt <- format(c(r, 0.123456789), digits = digits)[1] > > > txt <- paste("r= ", txt, sep = "") > > > if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) > > > text(0.5, 0.6, txt, cex=cex.cor * r) > > > > > > # p-value calculation > > > p <- cor.test(x, y)$p.value > > > txt2 <- format(c(p, 0.123456789), digits = digits)[1] > > > txt2 <- paste("p= ", txt2, sep = "") > > > if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "") > > > text(0.5, 0.4, txt2) > > > } > > > > > > pairs(iris, upper.panel = panel.cor,xlim=c(0.1,10), > > > ylim=c(0.1,10),log="xy",text.panel = NULL,pch=".") > > > > > > [[alternative HTML version deleted]] > > > > > > __ > > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > > 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. > > > > > > > > -- > > Gregory (Greg) L. Snow Ph.D. > > 538...@gmail.com > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] pairs: adjusting margins and labeling axes
I want to make this as easy as possible. The extra space could just go around the plot in the margin area. I could then use a cropping tool to paste the plot into Excel or Word. I'm not opposed to using another package, but I'd need some kind of pre-existing code to tinker with. On Tue, Jul 19, 2016 at 11:16 AM, Greg Snow <538...@gmail.com> wrote: > If you want square plots on a rectangular plotting region, then where > do you want the extra space to go? > > One option would be to add outer margins to use up the extra space. > The calculations to figure out exactly how much space to put in the > outer margins will probably not be trivial. > > Another option would be to not use `pairs`, but use the `layout` > function directly and loops to do your plots (and use the `respect` > argument to `layout`). > > On Tue, Jul 19, 2016 at 11:29 AM, michael young >wrote: > > The default shape for this correlation scatterplot is rectangle. I > changed > > it to square, but then the x-axis spacing between squares are off. Is > > there an easy way to change x-axis spacing between squares to that of the > > y-axis spacing size? > > > > I decided to hide the name values of the diagonal squares. I want them > > along the x and y axis instead, outside of the fixed number scale I have. > > I haven't seen any online example of 'pairs' with this and all my > searches > > have yielded nothing. Any ideas? Thanks > > > > par(pty="s") > > panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...) > > { > > usr <- par("usr"); on.exit(par(usr)) > > par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE) > > # correlation coefficient > > r <- cor(x, y) > > txt <- format(c(r, 0.123456789), digits = digits)[1] > > txt <- paste("r= ", txt, sep = "") > > if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) > > text(0.5, 0.6, txt, cex=cex.cor * r) > > > > # p-value calculation > > p <- cor.test(x, y)$p.value > > txt2 <- format(c(p, 0.123456789), digits = digits)[1] > > txt2 <- paste("p= ", txt2, sep = "") > > if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "") > > text(0.5, 0.4, txt2) > > } > > > > pairs(iris, upper.panel = panel.cor,xlim=c(0.1,10), > > ylim=c(0.1,10),log="xy",text.panel = NULL,pch=".") > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > > > > -- > Gregory (Greg) L. Snow Ph.D. > 538...@gmail.com > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] pairs: adjusting margins and labeling axes
Hi Will doing in lattice suite >From https://stat.ethz.ch/pipermail/r-help/2007-October/142116.html and https://stat.ethz.ch/pipermail/r-help/2007-October/142124.html] This is a direct cut and paste from the last url to give you an idea of Deepayan Sarkar's script library(lattice) panel.corval2 <- function(x, y, digits=2, prefix="", cex.cor, ...) { require(grid) r <- abs(cor(x, y, use = "complete.obs")) txt <- format(c(r, 0.123456789), digits=digits)[1] txt <- paste(prefix, txt, sep="") if (missing(cex.cor)) cex.cor <- 10 / nchar(txt) grid.text(txt, 0.5, 0.5, gp = gpar(cex = cex.cor)) } splom(iris[1:4], groups = iris$Species, pch = 16, lower.panel = function(...) { panel.xyplot(...) panel.loess(..., col = 1, lwd = 3) }, upper.panel = panel.corval2) Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of michael young Sent: Wednesday, 20 July 2016 03:30 To: r-help@r-project.org Subject: [R] pairs: adjusting margins and labeling axes The default shape for this correlation scatterplot is rectangle. I changed it to square, but then the x-axis spacing between squares are off. Is there an easy way to change x-axis spacing between squares to that of the y-axis spacing size? I decided to hide the name values of the diagonal squares. I want them along the x and y axis instead, outside of the fixed number scale I have. I haven't seen any online example of 'pairs' with this and all my searches have yielded nothing. Any ideas? Thanks par(pty="s") panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...) { usr <- par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE) # correlation coefficient r <- cor(x, y) txt <- format(c(r, 0.123456789), digits = digits)[1] txt <- paste("r= ", txt, sep = "") if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) text(0.5, 0.6, txt, cex=cex.cor * r) # p-value calculation p <- cor.test(x, y)$p.value txt2 <- format(c(p, 0.123456789), digits = digits)[1] txt2 <- paste("p= ", txt2, sep = "") if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "") text(0.5, 0.4, txt2) } pairs(iris, upper.panel = panel.cor,xlim=c(0.1,10), ylim=c(0.1,10),log="xy",text.panel = NULL,pch=".") [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
Re: [R] pairs: adjusting margins and labeling axes
If you want square plots on a rectangular plotting region, then where do you want the extra space to go? One option would be to add outer margins to use up the extra space. The calculations to figure out exactly how much space to put in the outer margins will probably not be trivial. Another option would be to not use `pairs`, but use the `layout` function directly and loops to do your plots (and use the `respect` argument to `layout`). On Tue, Jul 19, 2016 at 11:29 AM, michael youngwrote: > The default shape for this correlation scatterplot is rectangle. I changed > it to square, but then the x-axis spacing between squares are off. Is > there an easy way to change x-axis spacing between squares to that of the > y-axis spacing size? > > I decided to hide the name values of the diagonal squares. I want them > along the x and y axis instead, outside of the fixed number scale I have. > I haven't seen any online example of 'pairs' with this and all my searches > have yielded nothing. Any ideas? Thanks > > par(pty="s") > panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...) > { > usr <- par("usr"); on.exit(par(usr)) > par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE) > # correlation coefficient > r <- cor(x, y) > txt <- format(c(r, 0.123456789), digits = digits)[1] > txt <- paste("r= ", txt, sep = "") > if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) > text(0.5, 0.6, txt, cex=cex.cor * r) > > # p-value calculation > p <- cor.test(x, y)$p.value > txt2 <- format(c(p, 0.123456789), digits = digits)[1] > txt2 <- paste("p= ", txt2, sep = "") > if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "") > text(0.5, 0.4, txt2) > } > > pairs(iris, upper.panel = panel.cor,xlim=c(0.1,10), > ylim=c(0.1,10),log="xy",text.panel = NULL,pch=".") > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] pairs: adjusting margins and labeling axes
The default shape for this correlation scatterplot is rectangle. I changed it to square, but then the x-axis spacing between squares are off. Is there an easy way to change x-axis spacing between squares to that of the y-axis spacing size? I decided to hide the name values of the diagonal squares. I want them along the x and y axis instead, outside of the fixed number scale I have. I haven't seen any online example of 'pairs' with this and all my searches have yielded nothing. Any ideas? Thanks par(pty="s") panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...) { usr <- par("usr"); on.exit(par(usr)) par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE) # correlation coefficient r <- cor(x, y) txt <- format(c(r, 0.123456789), digits = digits)[1] txt <- paste("r= ", txt, sep = "") if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt) text(0.5, 0.6, txt, cex=cex.cor * r) # p-value calculation p <- cor.test(x, y)$p.value txt2 <- format(c(p, 0.123456789), digits = digits)[1] txt2 <- paste("p= ", txt2, sep = "") if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "") text(0.5, 0.4, txt2) } pairs(iris, upper.panel = panel.cor,xlim=c(0.1,10), ylim=c(0.1,10),log="xy",text.panel = NULL,pch=".") [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
[R] pairs plot
my data are matrix with 3 numeric columns. would like to have pairs plot with scatterplots in the upper with hist at the diag and with correlation at the lower. actually default pairs does almost what I want but looks semi awesome. Especially, i didn't find out how to remove the axes from the lower part where I do only want to display the numeric values correlations there and somehow axes don't fit. Hence I am looking at ggpairs from GGally and calling it without parameters looks almost perfect : but I cant find out how they got the Corr: in the upper, so I can't put it in the lower, and I do not know how to put the hist in the diag. please help -- Witold Eryk Wolski __ R-help@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.
Re: [R] pairs plot
On 10/11/2013 02:01 AM, Witold E Wolski wrote: my data are matrix with 3 numeric columns. would like to have pairs plot with scatterplots in the upper with hist at the diag and with correlation at the lower. actually default pairs does almost what I want but looks semi awesome. Especially, i didn't find out how to remove the axes from the lower part where I do only want to display the numeric values correlations there and somehow axes don't fit. Hence I am looking at ggpairs from GGally and calling it without parameters looks almost perfect : but I cant find out how they got the Corr: in the upper, so I can't put it in the lower, and I do not know how to put the hist in the diag. Hi Witold, The example below is roughly what you want, I think. This could be wrapped up in a function similar to pairs and I might do this in future if I get the time. wwdat-data.frame(a=seq(1,5,length.out=20)+rnorm(20), b=seq(1,4,length.out=20)+rnorm(20),c=rnorm(20)) require(plotrix) panes(matrix(1:9,nrow=3,byrow=TRUE),c(1.2,1,1.2),c(1.2,1,1.2)) # plot 1 par(mar=c(0,3,3,0)) hist(wwdat$a,xaxt=n,xlab=,ylab=,main=) box() # plot 2 par(mar=c(0,0,3,0)) plot(wwdat$a,wwdat$b,xaxt=n,yaxt=n,xlab=,ylab=) axis(3) # plot 3 par(mar=c(0,0,3,3)) plot(wwdat$a,wwdat$c,xaxt=n,yaxt=n,xlab=,ylab=) axis(3) axis(4) # plot 4 par(mar=c(0,3,0,0)) plot(0,0,xlim=c(-1,1),ylim=c(-1,1),xaxt=n,yaxt=n,xlab=,ylab=,type=n) text(0,0,round(cor(wwdat$a,wwdat$b),2),cex=2.5) # plot 5 par(mar=c(0,0,0,0)) hist(wwdat$b,xaxt=n,yaxt=n,xlab=,ylab=,main=) # plot 6 par(mar=c(0,0,0,3)) plot(wwdat$b,wwdat$c,xaxt=n,yaxt=n,xlab=,ylab=) axis(4) # plot 7 par(mar=c(3,3,0,0)) plot(0,0,xlim=c(-1,1),ylim=c(-1,1),xaxt=n,yaxt=n,xlab=,ylab=,type=n) text(0,0,round(cor(wwdat$c,wwdat$a),2),cex=2.5) # plot 8 par(mar=c(3,0,0,0)) plot(0,0,xlim=c(-1,1),ylim=c(-1,1),xaxt=n,yaxt=n,xlab=,ylab=,type=n) text(0,0,round(cor(wwdat$c,wwdat$b),2),cex=2.5) # plot 9 par(mar=c(3,0,0,3)) hist(wwdat$c,xaxt=n,yaxt=n,xlab=,ylab=,main=) axis(4) box() Jim __ R-help@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.
[R] pairs(X,Y) analog of cor(X,Y)?
With a data frame containing some X Y variables I can get the between set correlations with cor(X,Y): cor(NLSY[,1:2], NLSY[3:6]) antisochyperact income educ math 0.043381307 -0.07581733 0.25487753 0.2876875 read -0.003735785 -0.07555683 0.09114299 0.1884101 Is there somewhere an analog of pairs(X,Y) that will produce the pairwise plots of each X against each Y? The formula method for pairs() is for a one-sided formula. As a formula, I'm looking for something like pairs(math + read ~ antisoc +hyperact + income + educ, data=NLSY) lattice::xyplot has an extended formula interface, but interprets '+' to mean superposition. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __ R-help@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.
Re: [R] pairs(X,Y) analog of cor(X,Y)?
There is the pairs2 function in the TeachingDemos package that works like cor(x,y) where you give it 2 matricies/data frames and it gives the pairwise plots between the 2 groups. There is currently not a formula interface. On Fri, Mar 29, 2013 at 12:16 PM, Michael Friendly frien...@yorku.cawrote: With a data frame containing some X Y variables I can get the between set correlations with cor(X,Y): cor(NLSY[,1:2], NLSY[3:6]) antisochyperact income educ math 0.043381307 -0.07581733 0.25487753 0.2876875 read -0.003735785 -0.07555683 0.09114299 0.1884101 Is there somewhere an analog of pairs(X,Y) that will produce the pairwise plots of each X against each Y? The formula method for pairs() is for a one-sided formula. As a formula, I'm looking for something like pairs(math + read ~ antisoc +hyperact + income + educ, data=NLSY) lattice::xyplot has an extended formula interface, but interprets '+' to mean superposition. -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele StreetWeb: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs(), expression in label and color in text.panel
On 24.11.2011 15:59, Johannes Radinger wrote: Hello, I'd like to add custom labels to my pair() plot. These labels include math expression but they aren't correctly displayed... Looks fine for me in R-2.14.0 on the windows() device (alpha, text, beta). (Both version and device you used are unspecified) Further, I want that the boxes for the text.panel (diagonal) have an other background color (grey80). Is that generally possible? If yes how do I have to set it? What I've so far is: panel.cor- function(x, y, digits=2, prefix=, cex.cor) { usr- par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r- abs(cor(x, y)) txt- format(c(r, 0.123456789), digits=digits)[1] txt- paste(prefix, txt, sep=) if(missing(cex.cor)) cex- 0.5/strwidth(txt) test- cor.test(x,y) # borrowed from printCoefmat Signif- symnum(test$p.value, corr = FALSE, na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c(***, **, *, ., )) text(0.5, 0.5, paste(txt,Signif), cex = 2) } #correlation pair plot pairs(df, labels=c(expression(alpha),text,expression(beta)), lower.panel=panel.smooth, upper.panel=panel.cor) Not easily without changing the original code, I think, but you can cheat: pairs(iris, labels = expression(alpha, text, beta), lower.panel=panel.smooth, upper.panel=panel.cor, diag.panel = function(...) rect(par(usr)[1], par(usr)[3], par(usr)[2], par(usr)[4], col=grey80) ) Best, Uwe Ligges Maybe someone knows how to do that and can give some hints... /Johannes -- __ R-help@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. __ R-help@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.
[R] pairs(), expression in label and color in text.panel
Hello, I'd like to add custom labels to my pair() plot. These labels include math expression but they aren't correctly displayed... Further, I want that the boxes for the text.panel (diagonal) have an other background color (grey80). Is that generally possible? If yes how do I have to set it? What I've so far is: panel.cor - function(x, y, digits=2, prefix=, cex.cor) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r - abs(cor(x, y)) txt - format(c(r, 0.123456789), digits=digits)[1] txt - paste(prefix, txt, sep=) if(missing(cex.cor)) cex - 0.5/strwidth(txt) test - cor.test(x,y) # borrowed from printCoefmat Signif - symnum(test$p.value, corr = FALSE, na = FALSE, cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1), symbols = c(***, **, *, ., )) text(0.5, 0.5, paste(txt,Signif), cex = 2) } #correlation pair plot pairs(df, labels=c(expression(alpha),text,expression(beta)), lower.panel=panel.smooth, upper.panel=panel.cor) Maybe someone knows how to do that and can give some hints... /Johannes -- __ R-help@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.
Re: [R] pairs(), no axis labels/values for upper panel?
Steffen, Did you ever have luck getting rid of the tick marks?... I like your idea and have modified it, but yes, the tick marks need to go. Steffen Fleischer wrote: Dear all, I want to draw a graph that contains the scatterplot matrix in the lower panel and coefficients in the upper panel. I used and adapted the example for the function pairs but cannot figure out how to get no values and ticks in the upper panel (the values should only be in the lower panel). The upper panel looks odd to me this way. Any hints? Thanks in advance Steffen Here is an example what the graph looks like: # data(mtcars) panel.cor - function(a, b, digits=2, ...) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) x-cbind(a,b) x-na.omit(x) n - nrow(x) pp - c(0.025, 0.975) corx - cor(x,method=s)[1, 2] CI-c(tanh(atanh(corx) + qnorm(pp)/sqrt((n - 3)/1.06))) txt1 - paste(rho =,format(c(corx, 0.123456789), digits=digits)[1]) txt2-paste((,format(c(CI,0.123456789)[1],digits=digits),; ,format(c(CI,0.123456789)[2],digits=digits),),sep=) txt3-paste(N =,round(n,0)) txt - paste(txt1,\n,95%KI ,txt2,\n,txt3, sep=) text(0.5, 0.5, txt,cex=.8) } diag.cor-function(a,b, ...) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0,1)) rect(0,0,1,1,col=grey) } pairs(mtcars[1:4],upper.panel=panel.cor,diag.panel=diag.cor,label.pos=0.5) # __ R-help@ 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. -- View this message in context: http://r.789695.n4.nabble.com/pairs-no-axis-labels-values-for-upper-panel-tp3234437p4075283.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
[R] pairs(), no axis labels/values for upper panel?
Dear all, I want to draw a graph that contains the scatterplot matrix in the lower panel and coefficients in the upper panel. I used and adapted the example for the function pairs but cannot figure out how to get no values and ticks in the upper panel (the values should only be in the lower panel). The upper panel looks odd to me this way. Any hints? Thanks in advance Steffen Here is an example what the graph looks like: # data(mtcars) panel.cor - function(a, b, digits=2, ...) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) x-cbind(a,b) x-na.omit(x) n - nrow(x) pp - c(0.025, 0.975) corx - cor(x,method=s)[1, 2] CI-c(tanh(atanh(corx) + qnorm(pp)/sqrt((n - 3)/1.06))) txt1 - paste(rho =,format(c(corx, 0.123456789), digits=digits)[1]) txt2-paste((,format(c(CI,0.123456789)[1],digits=digits),; ,format(c(CI,0.123456789)[2],digits=digits),),sep=) txt3-paste(N =,round(n,0)) txt - paste(txt1,\n,95%KI ,txt2,\n,txt3, sep=) text(0.5, 0.5, txt,cex=.8) } diag.cor-function(a,b, ...) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0,1)) rect(0,0,1,1,col=grey) } pairs(mtcars[1:4],upper.panel=panel.cor,diag.panel=diag.cor,label.pos=0.5) # __ R-help@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.
[R] pairs and mfrow
Is there an alternative to par(mfrow=c(2,1)) to get stacked scatterplot matrixes generated with pairs? I am using version 2.11.1 on Windows XP. The logic I am using follows, and the second pairs plot replaces the first plot in the current graphics device, which is not what I expected (or desired). par(mfrow=c(2,1)) pairs(b2007, main=6/2000 - 12/2006) pairs(a2007, main=1/2007 - 06/2009) Thanks in advance! Mike [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs and mfrow
Why do you want 2 pairs plots on the same device? There may be a better approach to what you want to do. You could use splom from the lattice package along with the print.trellis function to put 2 on the same page. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Mike Harwood Sent: Monday, September 27, 2010 6:51 AM To: r-help@r-project.org Subject: [R] pairs and mfrow Is there an alternative to par(mfrow=c(2,1)) to get stacked scatterplot matrixes generated with pairs? I am using version 2.11.1 on Windows XP. The logic I am using follows, and the second pairs plot replaces the first plot in the current graphics device, which is not what I expected (or desired). par(mfrow=c(2,1)) pairs(b2007, main=6/2000 - 12/2006) pairs(a2007, main=1/2007 - 06/2009) Thanks in advance! Mike [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
[R] pairs and panel.smooth for two groups
Hi, I have modified the USJudgeRatings data (available in R) to illustrate my question. # Use the first 4 variables of USJudgeRatings and add a group variable with two levels USJudgeRatings - USJudgeRatings[,1:4] USJudgeRatings$group - factor(c(rep(1, 22), rep(0, 21))) # I can draw a pairs graph where members of each group are drawn in different colors: pairs(USJudgeRatings[,1:4], col = c(2,3)[USJudgeRatings$group], pch = c(21,3)[USJudgeRatings$group]) # I would also like to add a smooth line to each subplot like pairs(USJudgeRatings[,1:4], panel=panel.smooth) # but I want the smooth to be done for each of the group, i.e. I want two smooths per subplot. # this creates only one smooth pairs(USJudgeRatings[,1:4], col = c(2,3)[USJudgeRatings$group], pch = c(21,3)[USJudgeRatings$group], panel = panel.smooth) # I understand that panel.smooth is a function that is called for each subplot. I don't know how to tell it to do a smooth for each of my group in each of the subplot. Any help would be appreciated! Best, Marie-Pierre __ R-help@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.
Re: [R] pairs and panel.smooth for two groups
This is fairly simple using lattice graphics: USJudgeRatings - USJudgeRatings[,1:4] USJudgeRatings$group - factor(c(rep(1, 22), rep(0, 21))) library(lattice) splom( ~USJudgeRatings[,1:4], groups=group, data=USJudgeRatings, type=c('p','smooth')) The ggplot2 package probably makes this easy as well (but I am still learning that). If you really need to use the pairs function then you will need to create your own panel function (which could call panel.smooth). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Marie-Pierre Sylvestre Sent: Wednesday, September 08, 2010 8:03 AM To: r-help@r-project.org Subject: [R] pairs and panel.smooth for two groups Hi, I have modified the USJudgeRatings data (available in R) to illustrate my question. # Use the first 4 variables of USJudgeRatings and add a group variable with two levels USJudgeRatings - USJudgeRatings[,1:4] USJudgeRatings$group - factor(c(rep(1, 22), rep(0, 21))) # I can draw a pairs graph where members of each group are drawn in different colors: pairs(USJudgeRatings[,1:4], col = c(2,3)[USJudgeRatings$group], pch = c(21,3)[USJudgeRatings$group]) # I would also like to add a smooth line to each subplot like pairs(USJudgeRatings[,1:4], panel=panel.smooth) # but I want the smooth to be done for each of the group, i.e. I want two smooths per subplot. # this creates only one smooth pairs(USJudgeRatings[,1:4], col = c(2,3)[USJudgeRatings$group], pch = c(21,3)[USJudgeRatings$group], panel = panel.smooth) # I understand that panel.smooth is a function that is called for each subplot. I don't know how to tell it to do a smooth for each of my group in each of the subplot. Any help would be appreciated! Best, Marie-Pierre __ R-help@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. __ R-help@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.
Re: [R] pairs with same xlim and ylim scale
Well done! I was totally misled and trapped by the error message. Acturally the absence of 1.00 in the upper panel is an implicit indication that error occurred there. On 2010-9-3 13:02, Shi, Tao wrote: Hi Dejian, Thanks for the reply! I finally found the problem. It is actually in the panel.cor function. Adding ... in the function and text call fixed everything. Best, ...Tao - Original Message From: Dejian Zhaodejian.z...@gmail.com To: r-help@r-project.org Sent: Thu, September 2, 2010 7:57:55 PM Subject: Re: [R] pairs with same xlim and ylim scale When pairs draws plots, lower.panel invokes f.xy. Maybe there is something in f.xy incompatible with pairs. You can read the code of pairs to see what happens. pairs has two methods, as you can see in the help message (?pairs). According to your code, pairs is supposed to invoke Default S3 method. methods(pairs) [1] pairs.default pairs.formula* Non-visible functions are asterisked Therefore, you should check the code of the function pairs.default to see how error occurs. Just type pairs.default at the R command prompt and enter, you can get the source code of pairs.default. On 2010-9-2 15:15, Shi, Tao wrote: Hi Dejian, You're right on this! Do you know how to pass those two argument into lower.panel? Thanks! ...Tao From: Dejian Zhaozha...@ioz.ac.cn To:r-help@r-project.org Sent: Tue, August 31, 2010 6:10:16 PM Subject: Re: [R] pairs with same xlim and ylim scale I think you have successfully passed the xlim and ylim into the function pairs1. Compare the two graphs produced by the codes you provided, you can find the xlim and ylim in the second graph have been reset to the assigned value. It seems that the program halted in producing the second plot after adding xlim and ylim. According to the error message, the two added parameters were not used in lower.panel, or the customized function f.xy. On 2010-9-1 2:26, Shi, Tao wrote: Hi list, I have a function which basically is a wrapper of pairs with some useful panel functions. However, I'm having trouble to pass the xlim and ylim into the function so the x and y axes are in the same scale and 45 degree lines are exactly diagonal. I've looked at some old posts, they didn't help much. I [[elided Yahoo spam]] Thanks! ...Tao pairs1- function(x, ...) { f.xy- function(x, y, ...) { points(x, y, ...) abline(0, 1, col = 2) } panel.cor- function(x, y, digits=2, prefix=, cex.cor) { usr- par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r- abs(cor(x, y, method=p, use=pairwise.complete.obs)) txt- format(c(r, 0.123456789), digits=digits)[1] txt- paste(prefix, txt, sep=) if(missing(cex.cor)) cex- 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex * r) } panel.hist- function(x, ...) { usr- par(usr); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h- hist(x, plot = FALSE) breaks- h$breaks; nB- length(breaks) y- h$counts; y- y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col=cyan, ...) } pairs(x, lower.panel=f.xy, upper.panel=panel.cor, diag.panel=panel.hist, ...) } x- rnorm(100, sd=0.2) x- cbind(x=x-0.1, y=x+0.1) pairs1(x) pairs1(x, xlim=c(-1,1), ylim=c(-1,1)) Error in lower.panel(...) : unused argument(s) (xlim = c(-1, 1), ylim = c(-1, 1)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@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. __ R-help@r-project.org mailing list https
Re: [R] pairs with same xlim and ylim scale
Hi Dejian, You're right on this! Do you know how to pass those two argument into lower.panel? Thanks! ...Tao From: Dejian Zhao zha...@ioz.ac.cn To: r-help@r-project.org Sent: Tue, August 31, 2010 6:10:16 PM Subject: Re: [R] pairs with same xlim and ylim scale I think you have successfully passed the xlim and ylim into the function pairs1. Compare the two graphs produced by the codes you provided, you can find the xlim and ylim in the second graph have been reset to the assigned value. It seems that the program halted in producing the second plot after adding xlim and ylim. According to the error message, the two added parameters were not used in lower.panel, or the customized function f.xy. On 2010-9-1 2:26, Shi, Tao wrote: Hi list, I have a function which basically is a wrapper of pairs with some useful panel functions. However, I'm having trouble to pass the xlim and ylim into the function so the x and y axes are in the same scale and 45 degree lines are exactly diagonal. I've looked at some old posts, they didn't help much. I [[elided Yahoo spam]] Thanks! ...Tao pairs1- function(x, ...) { f.xy- function(x, y, ...) { points(x, y, ...) abline(0, 1, col = 2) } panel.cor- function(x, y, digits=2, prefix=, cex.cor) { usr- par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r- abs(cor(x, y, method=p, use=pairwise.complete.obs)) txt- format(c(r, 0.123456789), digits=digits)[1] txt- paste(prefix, txt, sep=) if(missing(cex.cor)) cex- 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex * r) } panel.hist- function(x, ...) { usr- par(usr); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h- hist(x, plot = FALSE) breaks- h$breaks; nB- length(breaks) y- h$counts; y- y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col=cyan, ...) } pairs(x, lower.panel=f.xy, upper.panel=panel.cor, diag.panel=panel.hist, ...) } x- rnorm(100, sd=0.2) x- cbind(x=x-0.1, y=x+0.1) pairs1(x) pairs1(x, xlim=c(-1,1), ylim=c(-1,1)) Error in lower.panel(...) : unused argument(s) (xlim = c(-1, 1), ylim = c(-1, 1)) [[alternative HTML version deleted]] __ R-help@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. __ R-help@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. __ R-help@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.
Re: [R] pairs with same xlim and ylim scale
When pairs draws plots, lower.panel invokes f.xy. Maybe there is something in f.xy incompatible with pairs. You can read the code of pairs to see what happens. pairs has two methods, as you can see in the help message (?pairs). According to your code, pairs is supposed to invoke Default S3 method. methods(pairs) [1] pairs.default pairs.formula* Non-visible functions are asterisked Therefore, you should check the code of the function pairs.default to see how error occurs. Just type pairs.default at the R command prompt and enter, you can get the source code of pairs.default. On 2010-9-2 15:15, Shi, Tao wrote: Hi Dejian, You're right on this! Do you know how to pass those two argument into lower.panel? Thanks! ...Tao From: Dejian Zhaozha...@ioz.ac.cn To:r-help@r-project.org Sent: Tue, August 31, 2010 6:10:16 PM Subject: Re: [R] pairs with same xlim and ylim scale I think you have successfully passed the xlim and ylim into the function pairs1. Compare the two graphs produced by the codes you provided, you can find the xlim and ylim in the second graph have been reset to the assigned value. It seems that the program halted in producing the second plot after adding xlim and ylim. According to the error message, the two added parameters were not used in lower.panel, or the customized function f.xy. On 2010-9-1 2:26, Shi, Tao wrote: Hi list, I have a function which basically is a wrapper of pairs with some useful panel functions. However, I'm having trouble to pass the xlim and ylim into the function so the x and y axes are in the same scale and 45 degree lines are exactly diagonal. I've looked at some old posts, they didn't help much. I [[elided Yahoo spam]] Thanks! ...Tao pairs1- function(x, ...) { f.xy- function(x, y, ...) { points(x, y, ...) abline(0, 1, col = 2) } panel.cor- function(x, y, digits=2, prefix=, cex.cor) { usr- par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r- abs(cor(x, y, method=p, use=pairwise.complete.obs)) txt- format(c(r, 0.123456789), digits=digits)[1] txt- paste(prefix, txt, sep=) if(missing(cex.cor)) cex- 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex * r) } panel.hist- function(x, ...) { usr- par(usr); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h- hist(x, plot = FALSE) breaks- h$breaks; nB- length(breaks) y- h$counts; y- y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col=cyan, ...) } pairs(x, lower.panel=f.xy, upper.panel=panel.cor, diag.panel=panel.hist, ...) } x- rnorm(100, sd=0.2) x- cbind(x=x-0.1, y=x+0.1) pairs1(x) pairs1(x, xlim=c(-1,1), ylim=c(-1,1)) Error in lower.panel(...) : unused argument(s) (xlim = c(-1, 1), ylim = c(-1, 1)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@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.
[R] pairs with same xlim and ylim scale
Hi list, I have a function which basically is a wrapper of pairs with some useful panel functions. However, I'm having trouble to pass the xlim and ylim into the function so the x and y axes are in the same scale and 45 degree lines are exactly diagonal. I've looked at some old posts, they didn't help much. I think this is b/c I have multiple panel functions. Help! Thanks! ...Tao pairs1 - function(x, ...) { f.xy - function(x, y, ...) { points(x, y, ...) abline(0, 1, col = 2) } panel.cor - function(x, y, digits=2, prefix=, cex.cor) { usr - par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r - abs(cor(x, y, method=p, use=pairwise.complete.obs)) txt - format(c(r, 0.123456789), digits=digits)[1] txt - paste(prefix, txt, sep=) if(missing(cex.cor)) cex - 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex * r) } panel.hist - function(x, ...) { usr - par(usr); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h - hist(x, plot = FALSE) breaks - h$breaks; nB - length(breaks) y - h$counts; y - y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col=cyan, ...) } pairs(x, lower.panel=f.xy, upper.panel=panel.cor, diag.panel=panel.hist, ...) } x - rnorm(100, sd=0.2) x - cbind(x=x-0.1, y=x+0.1) pairs1(x) pairs1(x, xlim=c(-1,1), ylim=c(-1,1)) Error in lower.panel(...) : unused argument(s) (xlim = c(-1, 1), ylim = c(-1, 1)) [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs with same xlim and ylim scale
I think you have successfully passed the xlim and ylim into the function pairs1. Compare the two graphs produced by the codes you provided, you can find the xlim and ylim in the second graph have been reset to the assigned value. It seems that the program halted in producing the second plot after adding xlim and ylim. According to the error message, the two added parameters were not used in lower.panel, or the customized function f.xy. On 2010-9-1 2:26, Shi, Tao wrote: Hi list, I have a function which basically is a wrapper of pairs with some useful panel functions. However, I'm having trouble to pass the xlim and ylim into the function so the x and y axes are in the same scale and 45 degree lines are exactly diagonal. I've looked at some old posts, they didn't help much. I think this is b/c I have multiple panel functions. Help! Thanks! ...Tao pairs1- function(x, ...) { f.xy- function(x, y, ...) { points(x, y, ...) abline(0, 1, col = 2) } panel.cor- function(x, y, digits=2, prefix=, cex.cor) { usr- par(usr); on.exit(par(usr)) par(usr = c(0, 1, 0, 1)) r- abs(cor(x, y, method=p, use=pairwise.complete.obs)) txt- format(c(r, 0.123456789), digits=digits)[1] txt- paste(prefix, txt, sep=) if(missing(cex.cor)) cex- 0.8/strwidth(txt) text(0.5, 0.5, txt, cex = cex * r) } panel.hist- function(x, ...) { usr- par(usr); on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) h- hist(x, plot = FALSE) breaks- h$breaks; nB- length(breaks) y- h$counts; y- y/max(y) rect(breaks[-nB], 0, breaks[-1], y, col=cyan, ...) } pairs(x, lower.panel=f.xy, upper.panel=panel.cor, diag.panel=panel.hist, ...) } x- rnorm(100, sd=0.2) x- cbind(x=x-0.1, y=x+0.1) pairs1(x) pairs1(x, xlim=c(-1,1), ylim=c(-1,1)) Error in lower.panel(...) : unused argument(s) (xlim = c(-1, 1), ylim = c(-1, 1)) [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] pairs
I'm not convinced it's right. In fact, I'm pretty sure the last step taking only the first half of the list is wrong. I also do not know if you have considered how you want to count situations like: 3 2 7 4 5 7 ... 7 3 8 6 1 2 9 2 .. How many pairs of 2-7/7-2 would that represent? -- David On Nov 15, 2009, at 11:06 PM, cindy Guo wrote: Hi, David, The matrix has 20 columns. Thank you very much for your help. I think it's right, but it seems I need some time to figure it out. I am a green hand. There are so many functions here I never used before. :) Cindy On Sun, Nov 15, 2009 at 5:19 PM, David Winsemius dwinsem...@comcast.net wrote: Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.
Re: [R] pairs
I stuck in another 7 in one of the lines with a 2 and reasoned that we could deal with the desire for non-ordered pair counting by pasting min(x,y) to max(x,y); dput(prmtx) structure(c(2, 1, 3, 9, 5, 7, 7, 8, 1, 7, 6, 5, 6, 2, 2, 7), .Dim = c(4L, 4L)) prmtx [,1] [,2] [,3] [,4] [1,]2516 [2,]1772 [3,]3762 [4,]9857 pair.str - sapply(1:nrow(prmtx), function(z) apply(combn(prmtx[z,], 2), 2,function(x) paste(min(x[2],x[1]), max(x[2],x[1]), sep=.))) The logic: sapply(1:nrow(prmtx), ... just loops over the rows of the matrix. combn(prmtx[z,], 2) ... returns a two row matrix of combination in a single row. apply(combn(prmtx[z,], 2), 2 ... since combn( , 2) returns a matrix that has two _rows_ I needed to loop over the columns. paste(min(x[2],x[1]), max(x[2],x[1]), sep=.) ... stick the minimum of a pair in front of the max and separates them with a period to prevent two+ digits from being non-unique Then using table() and logical tests in an index for the desired multiple pairs: tpair -table(pair.str) tpair pair.str 1.2 1.5 1.6 1.7 2.3 2.5 2.6 2.7 3.6 3.7 5.6 5.7 5.8 5.9 6.7 7.7 7.8 7.9 8.9 2 1 1 2 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 tpair[tpair1] pair.str 1.2 1.7 2.6 2.7 2 2 2 3 -- David. On Nov 16, 2009, at 7:02 AM, David Winsemius wrote: I'm not convinced it's right. In fact, I'm pretty sure the last step taking only the first half of the list is wrong. I also do not know if you have considered how you want to count situations like: 3 2 7 4 5 7 ... 7 3 8 6 1 2 9 2 .. How many pairs of 2-7/7-2 would that represent? -- David On Nov 15, 2009, at 11:06 PM, cindy Guo wrote: Hi, David, The matrix has 20 columns. Thank you very much for your help. I think it's right, but it seems I need some time to figure it out. I am a green hand. There are so many functions here I never used before. :) Cindy On Sun, Nov 15, 2009 at 5:19 PM, David Winsemius dwinsem...@comcast.net wrote: Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.
Re: [R] pairs
I forgot to say that there are no ties in each row. So any number can occur only once in each row. Also as I mentioned earlier, actually I only need the top 50 most frequent pairs, is there a more efficient way to do it? Because I have 15000 numbers, output of all the pairs would be too long. Thank you, Cindy On Mon, Nov 16, 2009 at 7:02 AM, David Winsemius dwinsem...@comcast.netwrote: I stuck in another 7 in one of the lines with a 2 and reasoned that we could deal with the desire for non-ordered pair counting by pasting min(x,y) to max(x,y); dput(prmtx) structure(c(2, 1, 3, 9, 5, 7, 7, 8, 1, 7, 6, 5, 6, 2, 2, 7), .Dim = c(4L, 4L)) prmtx [,1] [,2] [,3] [,4] [1,]2516 [2,]1772 [3,]3762 [4,]9857 pair.str - sapply(1:nrow(prmtx), function(z) apply(combn(prmtx[z,], 2), 2,function(x) paste(min(x[2],x[1]), max(x[2],x[1]), sep=.))) The logic: sapply(1:nrow(prmtx), ... just loops over the rows of the matrix. combn(prmtx[z,], 2) ... returns a two row matrix of combination in a single row. apply(combn(prmtx[z,], 2), 2 ... since combn( , 2) returns a matrix that has two _rows_ I needed to loop over the columns. paste(min(x[2],x[1]), max(x[2],x[1]), sep=.) ... stick the minimum of a pair in front of the max and separates them with a period to prevent two+ digits from being non-unique Then using table() and logical tests in an index for the desired multiple pairs: tpair -table(pair.str) tpair pair.str 1.2 1.5 1.6 1.7 2.3 2.5 2.6 2.7 3.6 3.7 5.6 5.7 5.8 5.9 6.7 7.7 7.8 7.9 8.9 2 1 1 2 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 tpair[tpair1] pair.str 1.2 1.7 2.6 2.7 2 2 2 3 -- David. On Nov 16, 2009, at 7:02 AM, David Winsemius wrote: I'm not convinced it's right. In fact, I'm pretty sure the last step taking only the first half of the list is wrong. I also do not know if you have considered how you want to count situations like: 3 2 7 4 5 7 ... 7 3 8 6 1 2 9 2 .. How many pairs of 2-7/7-2 would that represent? -- David On Nov 15, 2009, at 11:06 PM, cindy Guo wrote: Hi, David, The matrix has 20 columns. Thank you very much for your help. I think it's right, but it seems I need some time to figure it out. I am a green hand. There are so many functions here I never used before. :) Cindy On Sun, Nov 15, 2009 at 5:19 PM, David Winsemius dwinsem...@comcast.net wrote: Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list
Re: [R] pairs
On Nov 16, 2009, at 2:32 PM, cindy Guo wrote: I forgot to say that there are no ties in each row. So any number can occur only once in each row. Also as I mentioned earlier, actually I only need the top 50 most frequent pairs, is there a more efficient way to do it? Because I have 15000 numbers, output of all the pairs would be too long. ?order Thank you, Cindy On Mon, Nov 16, 2009 at 7:02 AM, David Winsemius dwinsem...@comcast.net wrote: I stuck in another 7 in one of the lines with a 2 and reasoned that we could deal with the desire for non-ordered pair counting by pasting min(x,y) to max(x,y); dput(prmtx) structure(c(2, 1, 3, 9, 5, 7, 7, 8, 1, 7, 6, 5, 6, 2, 2, 7), .Dim = c(4L, 4L)) prmtx [,1] [,2] [,3] [,4] [1,]2516 [2,]1772 [3,]3762 [4,]9857 pair.str - sapply(1:nrow(prmtx), function(z) apply(combn(prmtx[z,], 2), 2,function(x) paste(min(x[2],x[1]), max(x[2],x[1]), sep=.))) The logic: sapply(1:nrow(prmtx), ... just loops over the rows of the matrix. combn(prmtx[z,], 2) ... returns a two row matrix of combination in a single row. apply(combn(prmtx[z,], 2), 2 ... since combn( , 2) returns a matrix that has two _rows_ I needed to loop over the columns. paste(min(x[2],x[1]), max(x[2],x[1]), sep=.) ... stick the minimum of a pair in front of the max and separates them with a period to prevent two+ digits from being non-unique Then using table() and logical tests in an index for the desired multiple pairs: tpair -table(pair.str) tpair pair.str 1.2 1.5 1.6 1.7 2.3 2.5 2.6 2.7 3.6 3.7 5.6 5.7 5.8 5.9 6.7 7.7 7.8 7.9 8.9 2 1 1 2 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 tpair[tpair1] pair.str 1.2 1.7 2.6 2.7 2 2 2 3 -- David. On Nov 16, 2009, at 7:02 AM, David Winsemius wrote: I'm not convinced it's right. In fact, I'm pretty sure the last step taking only the first half of the list is wrong. I also do not know if you have considered how you want to count situations like: 3 2 7 4 5 7 ... 7 3 8 6 1 2 9 2 .. How many pairs of 2-7/7-2 would that represent? -- David On Nov 15, 2009, at 11:06 PM, cindy Guo wrote: Hi, David, The matrix has 20 columns. Thank you very much for your help. I think it's right, but it seems I need some time to figure it out. I am a green hand. There are so many functions here I never used before. :) Cindy On Sun, Nov 15, 2009 at 5:19 PM, David Winsemius dwinsem...@comcast.net wrote: Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML
Re: [R] pairs
Do you mean if the numbers in each row are ordered? They are not, but if it's needed, we can order them. The matrix only has 5000 rows. On Mon, Nov 16, 2009 at 1:34 PM, David Winsemius dwinsem...@comcast.netwrote: On Nov 16, 2009, at 2:32 PM, cindy Guo wrote: I forgot to say that there are no ties in each row. So any number can occur only once in each row. Also as I mentioned earlier, actually I only need the top 50 most frequent pairs, is there a more efficient way to do it? Because I have 15000 numbers, output of all the pairs would be too long. ?order Thank you, Cindy On Mon, Nov 16, 2009 at 7:02 AM, David Winsemius dwinsem...@comcast.netwrote: I stuck in another 7 in one of the lines with a 2 and reasoned that we could deal with the desire for non-ordered pair counting by pasting min(x,y) to max(x,y); dput(prmtx) structure(c(2, 1, 3, 9, 5, 7, 7, 8, 1, 7, 6, 5, 6, 2, 2, 7), .Dim = c(4L, 4L)) prmtx [,1] [,2] [,3] [,4] [1,]2516 [2,]1772 [3,]3762 [4,]9857 pair.str - sapply(1:nrow(prmtx), function(z) apply(combn(prmtx[z,], 2), 2,function(x) paste(min(x[2],x[1]), max(x[2],x[1]), sep=.))) The logic: sapply(1:nrow(prmtx), ... just loops over the rows of the matrix. combn(prmtx[z,], 2) ... returns a two row matrix of combination in a single row. apply(combn(prmtx[z,], 2), 2 ... since combn( , 2) returns a matrix that has two _rows_ I needed to loop over the columns. paste(min(x[2],x[1]), max(x[2],x[1]), sep=.) ... stick the minimum of a pair in front of the max and separates them with a period to prevent two+ digits from being non-unique Then using table() and logical tests in an index for the desired multiple pairs: tpair -table(pair.str) tpair pair.str 1.2 1.5 1.6 1.7 2.3 2.5 2.6 2.7 3.6 3.7 5.6 5.7 5.8 5.9 6.7 7.7 7.8 7.9 8.9 2 1 1 2 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 tpair[tpair1] pair.str 1.2 1.7 2.6 2.7 2 2 2 3 -- David. On Nov 16, 2009, at 7:02 AM, David Winsemius wrote: I'm not convinced it's right. In fact, I'm pretty sure the last step taking only the first half of the list is wrong. I also do not know if you have considered how you want to count situations like: 3 2 7 4 5 7 ... 7 3 8 6 1 2 9 2 .. How many pairs of 2-7/7-2 would that represent? -- David On Nov 15, 2009, at 11:06 PM, cindy Guo wrote: Hi, David, The matrix has 20 columns. Thank you very much for your help. I think it's right, but it seems I need some time to figure it out. I am a green hand. There are so many functions here I never used before. :) Cindy On Sun, Nov 15, 2009 at 5:19 PM, David Winsemius dwinsem...@comcast.net wrote: Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] pairs
David Winsemius wrote: ?order cindy Guo wrote: Do you mean if the numbers in each row are ordered? They are not, but if it's needed, we can order them. The matrix only has 5000 rows. No, he's suggesting you check out the order() function by calling it's help page: ?order order() will sort your results into ascending or descending order. You could then pick off the top 50 by using head(). Hope that helps! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://old.nabble.com/pairs-tp26364801p26378236.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] pairs
On Nov 16, 2009, at 2:41 PM, cindy Guo wrote: Do you mean if the numbers in each row are ordered? They are not, but if it's needed, we can order them. The matrix only has 5000 rows. No, I mean type ?order at the R command line and read the help page. On Mon, Nov 16, 2009 at 1:34 PM, David Winsemius dwinsem...@comcast.net wrote: On Nov 16, 2009, at 2:32 PM, cindy Guo wrote: I forgot to say that there are no ties in each row. So any number can occur only once in each row. Also as I mentioned earlier, actually I only need the top 50 most frequent pairs, is there a more efficient way to do it? Because I have 15000 numbers, output of all the pairs would be too long. ?order Thank you, Cindy On Mon, Nov 16, 2009 at 7:02 AM, David Winsemius dwinsem...@comcast.net wrote: I stuck in another 7 in one of the lines with a 2 and reasoned that we could deal with the desire for non-ordered pair counting by pasting min(x,y) to max(x,y); dput(prmtx) structure(c(2, 1, 3, 9, 5, 7, 7, 8, 1, 7, 6, 5, 6, 2, 2, 7), .Dim = c(4L, 4L)) prmtx [,1] [,2] [,3] [,4] [1,]2516 [2,]1772 [3,]3762 [4,]9857 pair.str - sapply(1:nrow(prmtx), function(z) apply(combn(prmtx[z,], 2), 2,function(x) paste(min(x[2],x[1]), max(x[2],x[1]), sep=.))) The logic: sapply(1:nrow(prmtx), ... just loops over the rows of the matrix. combn(prmtx[z,], 2) ... returns a two row matrix of combination in a single row. apply(combn(prmtx[z,], 2), 2 ... since combn( , 2) returns a matrix that has two _rows_ I needed to loop over the columns. paste(min(x[2],x[1]), max(x[2],x[1]), sep=.) ... stick the minimum of a pair in front of the max and separates them with a period to prevent two+ digits from being non-unique Then using table() and logical tests in an index for the desired multiple pairs: tpair -table(pair.str) tpair pair.str 1.2 1.5 1.6 1.7 2.3 2.5 2.6 2.7 3.6 3.7 5.6 5.7 5.8 5.9 6.7 7.7 7.8 7.9 8.9 2 1 1 2 1 1 2 3 1 1 1 1 1 1 1 1 1 1 1 tpair[tpair1] pair.str 1.2 1.7 2.6 2.7 2 2 2 3 -- David. On Nov 16, 2009, at 7:02 AM, David Winsemius wrote: I'm not convinced it's right. In fact, I'm pretty sure the last step taking only the first half of the list is wrong. I also do not know if you have considered how you want to count situations like: 3 2 7 4 5 7 ... 7 3 8 6 1 2 9 2 .. How many pairs of 2-7/7-2 would that represent? -- David On Nov 15, 2009, at 11:06 PM, cindy Guo wrote: Hi, David, The matrix has 20 columns. Thank you very much for your help. I think it's right, but it seems I need some time to figure it out. I am a green hand. There are so many functions here I never used before. :) Cindy On Sun, Nov 15, 2009 at 5:19 PM, David Winsemius dwinsem...@comcast.net wrote: Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list
Re: [R] pairs
Thank you. I will check that. Cindy On Mon, Nov 16, 2009 at 1:45 PM, cls59 ch...@sharpsteen.net wrote: David Winsemius wrote: ?order cindy Guo wrote: Do you mean if the numbers in each row are ordered? They are not, but if it's needed, we can order them. The matrix only has 5000 rows. No, he's suggesting you check out the order() function by calling it's help page: ?order order() will sort your results into ascending or descending order. You could then pick off the top 50 by using head(). Hope that helps! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://old.nabble.com/pairs-tp26364801p26378236.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@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.
[R] pairs
Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. Thank you, Cindy [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs
cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. Thank you, Cindy Use %in% to check for the presence of the numbers in a row and apply() to efficiently execute the test for each row: tstMatrix - matrix( c(2,5,1,6, 1,7,8,2, 3,7,6,2, 9,8,5,7), nrow=4, byrow=T ) matches - apply( tstMatrix, 1, function( row ){ if( 2 %in% row 6 %in% row ){ return( 2 ) } else { return( 0 ) } }) matches [1] 2 0 2 0 If you have more than one pair, it gets a little tricky. Say you are also looking for the pair (7,8). Store them as a list: pairList - list( c(2,6), c(7,8) ) Then use sapply() to efficiently iterate over the pair list and execute the apply() test: matchMatrix - sapply( pairList, function( pair ){ matches - apply( tstMatrix, 1, function( row ){ if( pair[1] %in% row pair[2] %in% row ){ return( pair[1] ) } else { return( 0 ) } }) return( matches ) }) matchMatrix [,1] [,2] [1,]20 [2,]07 [3,]20 [4,]07 If you're looking to apply the above method to every possible permutation of 2 numbers that may be generated from the range of numbers 1:15000... that's 225,000,000 pairs. expand.grid() can generate the required pair list-- but that step alone causes a memory allocation of ~6 GB on my machine. If you don't have a pile of CPU cores and RAM at your disposal, you can probably: 1. Restrict the upper end of your range to the maximal entry present in your matrix since all other combinations have zero occurrences. 2. Break the list of pairs up into several sublists, run the tests, and aggregate the results. Either way, the analysis will take some time despite the efficiencies of the apply family of functions due to the shear size of the problem. If you have more than one CPU, I would recommend taking a look at parallelized apply functions, perhaps using a package like snowfall, as the testing of the pairs is an embarrassingly parallel problem. Hopefully I'm misunderstanding the scope of your problem. Good luck! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://old.nabble.com/pairs-tp26364801p26365206.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] pairs
Hope this help: m - matrix(c(2,1,3,9,5,7,7,8,1,8,6,5,6,2,2,7),4,4) p - c(2, 6) apply(m == p[1], 1, any) apply(m == p[2], 1, any) [1] TRUE FALSE TRUE FALSE If you want the number of rows which contain the pair, sum() could be used: sum(apply(m == p[1], 1, any) apply(m == p[2], 1, any)) [1] 2 On Mon, Nov 16, 2009 at 6:26 AM, cindy Guo cindy.g...@gmail.com wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. Thank you, Cindy [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] pairs
Hi, Charlie, Thank you for the reply. Maybe I don't need the frequency of each pair. I only need the top, say 50, pairs with the highest frequency. Is there anyway which can avoid calculating for all the pairs? Thanks, Cindy On Sun, Nov 15, 2009 at 4:18 PM, cls59 ch...@sharpsteen.net wrote: cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. Thank you, Cindy Use %in% to check for the presence of the numbers in a row and apply() to efficiently execute the test for each row: tstMatrix - matrix( c(2,5,1,6, 1,7,8,2, 3,7,6,2, 9,8,5,7), nrow=4, byrow=T ) matches - apply( tstMatrix, 1, function( row ){ if( 2 %in% row 6 %in% row ){ return( 2 ) } else { return( 0 ) } }) matches [1] 2 0 2 0 If you have more than one pair, it gets a little tricky. Say you are also looking for the pair (7,8). Store them as a list: pairList - list( c(2,6), c(7,8) ) Then use sapply() to efficiently iterate over the pair list and execute the apply() test: matchMatrix - sapply( pairList, function( pair ){ matches - apply( tstMatrix, 1, function( row ){ if( pair[1] %in% row pair[2] %in% row ){ return( pair[1] ) } else { return( 0 ) } }) return( matches ) }) matchMatrix [,1] [,2] [1,]20 [2,]07 [3,]20 [4,]07 If you're looking to apply the above method to every possible permutation of 2 numbers that may be generated from the range of numbers 1:15000... that's 225,000,000 pairs. expand.grid() can generate the required pair list-- but that step alone causes a memory allocation of ~6 GB on my machine. If you don't have a pile of CPU cores and RAM at your disposal, you can probably: 1. Restrict the upper end of your range to the maximal entry present in your matrix since all other combinations have zero occurrences. 2. Break the list of pairs up into several sublists, run the tests, and aggregate the results. Either way, the analysis will take some time despite the efficiencies of the apply family of functions due to the shear size of the problem. If you have more than one CPU, I would recommend taking a look at parallelized apply functions, perhaps using a package like snowfall, as the testing of the pairs is an embarrassingly parallel problem. Hopefully I'm misunderstanding the scope of your problem. Good luck! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://old.nabble.com/pairs-tp26364801p26365206.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs
I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.
Re: [R] pairs
Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.
Re: [R] pairs
Hi, David, The matrix has 20 columns. Thank you very much for your help. I think it's right, but it seems I need some time to figure it out. I am a green hand. There are so many functions here I never used before. :) Cindy On Sun, Nov 15, 2009 at 5:19 PM, David Winsemius dwinsem...@comcast.netwrote: Assuming that the number of columns is 4, then consider this approach: prs -scan() 1: 2 5 1 6 5: 1 7 8 2 9: 3 7 6 2 13: 9 8 5 7 17: Read 16 items prmtx - matrix(prs, 4,4, byrow=T) #Now make copus of x.y and y.x pair.str - sapply(1:nrow(prmtx), function(z) c(apply(combn(prmtx[z,], 2), 2,function(x) paste(x[1],x[2], sep=.)) , apply(combn(prmtx[z,], 2), 2,function(x) paste(x[2],x[1], sep=.))) ) tpair -table(pair.str) # This then gives you a duplicated list tpair[tpair1] pair.str 1.2 2.1 2.6 2.7 6.2 7.2 7.8 8.7 2 2 2 2 2 2 2 2 # So only take the first half of the pairs: head(tpair[tpair1], sum(tpair1)/2) pair.str 1.2 2.1 2.6 2.7 2 2 2 2 -- David. On Nov 15, 2009, at 8:06 PM, David Winsemius wrote: I could of course be wrong but have you yet specified the number of columns for this pairing exercise? On Nov 15, 2009, at 5:26 PM, cindy Guo wrote: Hi, All, I have an n by m matrix with each entry between 1 and 15000. I want to know the frequency of each pair in 1:15000 that occur together in rows. So for example, if the matrix is 2 5 1 6 1 7 8 2 3 7 6 2 9 8 5 7 Pair (2,6) (un-ordered) occurs together in rows 1 and 3. I want to return the value 2 for this pair as well as that for all pairs. Is there a fast way to do this avoiding loops? Loops take too long. and provide commented, minimal, self-contained, reproducible code. ^^ David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] __ R-help@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.
[R] pairs
Dear all, I have two sets of data (say set1 and set2) as follow: set1 x1 x2 x3 0.30 0.43 3.88 0.38 0.59 3.53 0.30 0.42 2.12 0.33 0.53 2.12 0.30 0.47 3.76 set2 y1 y2 y3 0.32 0.47 5.18 0.23 0.26 1.06 0.42 0.65 3.88 0.28 0.38 3.76 0.35 0.47 1.41 The pairs function (such as pairs(~x1+x2+x3 data=set1, main=Simple Scatterplot Matrix) ) is producing scatterplot matrix where lower and upper diagonals have scatter plots of set1 variables. I want to produce a scatterplot matrix where in upper panel (diagonal) I should have plots from set1 variables and in lower panel (diagonal) I should have plots from set2 variables. Is there a way that I can do this? Any help is deeply appreciated. Kind Regards Seyit Ali -- Dr. Seyit Ali KAYIS Selcuk University Faculty of Agriculture Kampus, Konya, TURKEY s_a_ka...@yahoo.com,s_a_ka...@hotmail.com Tell: +90 332 223 2830 Mobile: +90 535 587 1139 Fax: +90 332 241 0108 Greetings from Konya, TURKEY http://www.ziraat.selcuk.edu.tr/skayis/ -- _ Facebook. k-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-nz:SI_SB_2:092010 [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs
Does the pairs2 function in the TeachingDemos package do what you want? -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Seyit Ali Kayis Sent: Wednesday, October 14, 2009 6:35 AM To: r-help@r-project.org Subject: [R] pairs Dear all, I have two sets of data (say set1 and set2) as follow: set1 x1 x2 x3 0.30 0.43 3.88 0.38 0.59 3.53 0.30 0.42 2.12 0.33 0.53 2.12 0.30 0.47 3.76 set2 y1 y2 y3 0.32 0.47 5.18 0.23 0.26 1.06 0.42 0.65 3.88 0.28 0.38 3.76 0.35 0.47 1.41 The pairs function (such as pairs(~x1+x2+x3 data=set1, main=Simple Scatterplot Matrix) ) is producing scatterplot matrix where lower and upper diagonals have scatter plots of set1 variables. I want to produce a scatterplot matrix where in upper panel (diagonal) I should have plots from set1 variables and in lower panel (diagonal) I should have plots from set2 variables. Is there a way that I can do this? Any help is deeply appreciated. Kind Regards Seyit Ali --- --- Dr. Seyit Ali KAYIS Selcuk University Faculty of Agriculture Kampus, Konya, TURKEY s_a_ka...@yahoo.com,s_a_ka...@hotmail.com Tell: +90 332 223 2830 Mobile: +90 535 587 1139 Fax: +90 332 241 0108 Greetings from Konya, TURKEY http://www.ziraat.selcuk.edu.tr/skayis/ --- --- _ Facebook. k-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-nz:SI_SB_2:092010 [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] pairs
Looking at the question again, I don't think pairs2 is the answer. I think it will be easier to do this by hand than to get pairs to do it for you (though you could make your own function as a modification of pairs). Does this do what you want? xx - matrix(scan(), ncol=3, byrow=TRUE) 0.30 0.43 3.88 0.38 0.59 3.53 0.30 0.42 2.12 0.33 0.53 2.12 0.30 0.47 3.76 yy - matrix(scan(), ncol=3, byrow=TRUE) 0.32 0.47 5.18 0.23 0.26 1.06 0.42 0.65 3.88 0.28 0.38 3.76 0.35 0.47 1.41 par(mfrow=c(3,3), oma=c(4,4,4,4)+0.1, mar=c(0,0,0,0)+0.1) for(i in 1:3) { for( j in 1:3 ) { if(i==j) plot(1,1, pch=as.character(i), ann=FALSE, axes=FALSE, cex=5) if(i j ) plot( xx[,j], xx[,i], ann=FALSE, axes=FALSE ) if(i j ) plot( yy[,j], yy[,i], ann=FALSE, axes=FALSE ) box() if( i j ){ axis(4, outer=TRUE); axis(3, outer=TRUE) } if( i j ){ axis(1, outer=TRUE); axis(2, outer=TRUE) } } } -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Greg Snow Sent: Wednesday, October 14, 2009 11:13 AM To: Seyit Ali Kayis; r-help@r-project.org Subject: Re: [R] pairs Does the pairs2 function in the TeachingDemos package do what you want? -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Seyit Ali Kayis Sent: Wednesday, October 14, 2009 6:35 AM To: r-help@r-project.org Subject: [R] pairs Dear all, I have two sets of data (say set1 and set2) as follow: set1 x1 x2 x3 0.30 0.43 3.88 0.38 0.59 3.53 0.30 0.42 2.12 0.33 0.53 2.12 0.30 0.47 3.76 set2 y1 y2 y3 0.32 0.47 5.18 0.23 0.26 1.06 0.42 0.65 3.88 0.28 0.38 3.76 0.35 0.47 1.41 The pairs function (such as pairs(~x1+x2+x3 data=set1, main=Simple Scatterplot Matrix) ) is producing scatterplot matrix where lower and upper diagonals have scatter plots of set1 variables. I want to produce a scatterplot matrix where in upper panel (diagonal) I should have plots from set1 variables and in lower panel (diagonal) I should have plots from set2 variables. Is there a way that I can do this? Any help is deeply appreciated. Kind Regards Seyit Ali - -- --- Dr. Seyit Ali KAYIS Selcuk University Faculty of Agriculture Kampus, Konya, TURKEY s_a_ka...@yahoo.com,s_a_ka...@hotmail.com Tell: +90 332 223 2830 Mobile: +90 535 587 1139 Fax: +90 332 241 0108 Greetings from Konya, TURKEY http://www.ziraat.selcuk.edu.tr/skayis/ - -- --- _ Facebook. k-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-nz:SI_SB_2:092010 [[alternative HTML version deleted]] __ R-help@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. __ R-help@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. __ R-help@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.
Re: [R] pairs plot
Hi Greg I saw, read, the TeachingDemos you suggesttef but when run pairs2 function on my R module says Can´t find function pairs2 How can I load the module or function pairs2? Thanks in advance for your help. You are the best. 2009/7/27, Greg Snow greg.s...@imail.org: Look at the pairs2 function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jose Narillos de Santos Sent: Monday, July 27, 2009 9:02 AM To: r-help@r-project.org Subject: [R] pairs plot Hi all, I want to plot trough pairs() plot a matrix with 4 columns. I want to make a trhee plot in a graph. Plotting pairs colum 2,3,4 on y axis and 1 on X axis. You mean (a plot with three graphs) ommitting the first pair with itself. And only the pairs with colum 1 with the other not all pairs. I. e. this matrix 4177 289390 8740 17220 3907 301510 8530 17550 3975 316970 8640 17650 3651 364220 9360 21420 3031 387390 9960 23410 2912 430180 11040 25820 3018 499930 12240 27620 2685 595010 13800 31670 2884 661870 14760 37170 Thanks in advance. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs plot
Hi r-help-boun...@r-project.org napsal dne 28.07.2009 09:55:11: Hi Greg I saw, read, the TeachingDemos you suggesttef but when run pairs2 function on my R module says Can´t find function pairs2 How can I load the module or function pairs2? Did you do library(TeachingDemos)? Regards Petr Thanks in advance for your help. You are the best. 2009/7/27, Greg Snow greg.s...@imail.org: Look at the pairs2 function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jose Narillos de Santos Sent: Monday, July 27, 2009 9:02 AM To: r-help@r-project.org Subject: [R] pairs plot Hi all, I want to plot trough pairs() plot a matrix with 4 columns. I want to make a trhee plot in a graph. Plotting pairs colum 2,3,4 on y axis and 1 on X axis. You mean (a plot with three graphs) ommitting the first pair with itself. And only the pairs with colum 1 with the other not all pairs. I. e. this matrix 4177 289390 8740 17220 3907 301510 8530 17550 3975 316970 8640 17650 3651 364220 9360 21420 3031 387390 9960 23410 2912 430180 11040 25820 3018 499930 12240 27620 2685 595010 13800 31670 2884 661870 14760 37170 Thanks in advance. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] pairs plot
Hi, I tried to load typing library(TeachingDemos) But the message can´t find package TeachingDemos) occurs. I use versión R 2.9 on windows. Can you please guide me? Sorry¡¡¡ 2009/7/28, Petr PIKAL petr.pi...@precheza.cz: Hi r-help-boun...@r-project.org napsal dne 28.07.2009 09:55:11: Hi Greg I saw, read, the TeachingDemos you suggesttef but when run pairs2 function on my R module says Can´t find function pairs2 How can I load the module or function pairs2? Did you do library(TeachingDemos)? Regards Petr Thanks in advance for your help. You are the best. 2009/7/27, Greg Snow greg.s...@imail.org: Look at the pairs2 function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jose Narillos de Santos Sent: Monday, July 27, 2009 9:02 AM To: r-help@r-project.org Subject: [R] pairs plot Hi all, I want to plot trough pairs() plot a matrix with 4 columns. I want to make a trhee plot in a graph. Plotting pairs colum 2,3,4 on y axis and 1 on X axis. You mean (a plot with three graphs) ommitting the first pair with itself. And only the pairs with colum 1 with the other not all pairs. I. e. this matrix 4177 289390 8740 17220 3907 301510 8530 17550 3975 316970 8640 17650 3651 364220 9360 21420 3031 387390 9960 23410 2912 430180 11040 25820 3018 499930 12240 27620 2685 595010 13800 31670 2884 661870 14760 37170 Thanks in advance. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs plot
Have you installed it first? First: install.packages(TeachingDemos) Then: library(TeachingDemos) --- On Tue, 7/28/09, Jose Narillos de Santos narillosdesan...@gmail.com wrote: From: Jose Narillos de Santos narillosdesan...@gmail.com Subject: Re: [R] pairs plot To: Petr PIKAL petr.pi...@precheza.cz, r-help@r-project.org, greg.s...@imail.org Received: Tuesday, July 28, 2009, 8:24 AM Hi, I tried to load typing library(TeachingDemos) But the message can´t find package TeachingDemos) occurs. I use versión R 2.9 on windows. Can you please guide me? Sorry¡¡¡ 2009/7/28, Petr PIKAL petr.pi...@precheza.cz: Hi r-help-boun...@r-project.org napsal dne 28.07.2009 09:55:11: Hi Greg I saw, read, the TeachingDemos you suggesttef but when run pairs2 function on my R module says Can´t find function pairs2 How can I load the module or function pairs2? Did you do library(TeachingDemos)? Regards Petr Thanks in advance for your help. You are the best. 2009/7/27, Greg Snow greg.s...@imail.org: Look at the pairs2 function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jose Narillos de Santos Sent: Monday, July 27, 2009 9:02 AM To: r-help@r-project.org Subject: [R] pairs plot Hi all, I want to plot trough pairs() plot a matrix with 4 columns. I want to make a trhee plot in a graph. Plotting pairs colum 2,3,4 on y axis and 1 on X axis. You mean (a plot with three graphs) ommitting the first pair with itself. And only the pairs with colum 1 with the other not all pairs. I. e. this matrix 4177 289390 8740 17220 3907 301510 8530 17550 3975 316970 8640 17650 3651 364220 9360 21420 3031 387390 9960 23410 2912 430180 11040 25820 3018 499930 12240 27620 2685 595010 13800 31670 2884 661870 14760 37170 Thanks in advance. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] -Inline Attachment Follows- __ R-help@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. __ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com. __ R-help@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.
Re: [R] pairs plot
r-help-boun...@r-project.org napsal dne 28.07.2009 15:39:03: Have you installed it first? First: install.packages(TeachingDemos) Or if you have problems with correct setting through corporate network rules (like myself) you can download a zip (for Windows) version and unzip it to library subdirectory. Then: library(TeachingDemos) shall be executed without problem Regards Petr --- On Tue, 7/28/09, Jose Narillos de Santos narillosdesan...@gmail.com wrote: From: Jose Narillos de Santos narillosdesan...@gmail.com Subject: Re: [R] pairs plot To: Petr PIKAL petr.pi...@precheza.cz, r-help@r-project.org, greg.s...@imail.org Received: Tuesday, July 28, 2009, 8:24 AM Hi, I tried to load typing library(TeachingDemos) But the message can´t find package TeachingDemos) occurs. I use versión R 2.9 on windows. Can you please guide me? Sorry¡¡¡ 2009/7/28, Petr PIKAL petr.pi...@precheza.cz: Hi r-help-boun...@r-project.org napsal dne 28.07.2009 09:55:11: Hi Greg I saw, read, the TeachingDemos you suggesttef but when run pairs2 function on my R module says Can´t find function pairs2 How can I load the module or function pairs2? Did you do library(TeachingDemos)? Regards Petr Thanks in advance for your help. You are the best. 2009/7/27, Greg Snow greg.s...@imail.org: Look at the pairs2 function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jose Narillos de Santos Sent: Monday, July 27, 2009 9:02 AM To: r-help@r-project.org Subject: [R] pairs plot Hi all, I want to plot trough pairs() plot a matrix with 4 columns. I want to make a trhee plot in a graph. Plotting pairs colum 2,3,4 on y axis and 1 on X axis. You mean (a plot with three graphs) ommitting the first pair with itself. And only the pairs with colum 1 with the other not all pairs. I. e. this matrix 4177 289390 8740 17220 3907 301510 8530 17550 3975 316970 8640 17650 3651 364220 9360 21420 3031 387390 9960 23410 2912 430180 11040 25820 3018 499930 12240 27620 2685 595010 13800 31670 2884 661870 14760 37170 Thanks in advance. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] -Inline Attachment Follows- __ R-help@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. __ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now http://ca.toolbar.yahoo.com. __ R-help@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. __ R-help@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.
[R] pairs plot
Hi all, I want to plot trough pairs() plot a matrix with 4 columns. I want to make a trhee plot in a graph. Plotting pairs colum 2,3,4 on y axis and 1 on X axis. You mean (a plot with three graphs) ommitting the first pair with itself. And only the pairs with colum 1 with the other not all pairs. I. e. this matrix 4177 289390 8740 17220 3907 301510 8530 17550 3975 316970 8640 17650 3651 364220 9360 21420 3031 387390 9960 23410 2912 430180 11040 25820 3018 499930 12240 27620 2685 595010 13800 31670 2884 661870 14760 37170 Thanks in advance. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs plot
Look at the pairs2 function in the TeachingDemos package. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jose Narillos de Santos Sent: Monday, July 27, 2009 9:02 AM To: r-help@r-project.org Subject: [R] pairs plot Hi all, I want to plot trough pairs() plot a matrix with 4 columns. I want to make a trhee plot in a graph. Plotting pairs colum 2,3,4 on y axis and 1 on X axis. You mean (a plot with three graphs) ommitting the first pair with itself. And only the pairs with colum 1 with the other not all pairs. I. e. this matrix 4177 289390 8740 17220 3907 301510 8530 17550 3975 316970 8640 17650 3651 364220 9360 21420 3031 387390 9960 23410 2912 430180 11040 25820 3018 499930 12240 27620 2685 595010 13800 31670 2884 661870 14760 37170 Thanks in advance. [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
[R] pairs of numbers
Hi, I have two lists of numbers which are both 1,2,3,4. I would like to combine pairs so that I have: 1,2 1,3 1,4 2,3 2,4 3,4. I know that expand.grid() can give me all combinations of pairs. Any suggestions would be much appreciated. Emma -- View this message in context: http://www.nabble.com/pairs-of-numbers-tp22494116p22494116.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] pairs of numbers
I have solved my problem using: x-1:4 x [1] 1 2 3 4 combn(x,2) [,1] [,2] [,3] [,4] [,5] [,6] [1,]111223 [2,]234344 Thanks Emma emj83 wrote: Hi, I have two lists of numbers which are both 1,2,3,4. I would like to combine pairs so that I have: 1,2 1,3 1,4 2,3 2,4 3,4. I know that expand.grid() can give me all combinations of pairs. Any suggestions would be much appreciated. Emma -- View this message in context: http://www.nabble.com/pairs-of-numbers-tp22494116p22494346.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] pairs() help - colour histograms on diagonal
Nathan S. Watson-Haigh wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'd like to be able to colour histograms along the diagonal using the colours stored in colnames(d): d blackbluebrowncyan 1 0.96405751 -0.02964390 -0.060147424 -0.06460070 2 -0.03614607 0.95475444 -0.152382053 -0.07767974 3 -0.07095613 -0.05884884 -0.061289399 -0.06445973 4 -0.03708223 -0.05997624 -0.054044275 -0.08291373 5 -0.08877190 -0.07193658 -0.078598617 -0.08892916 6 -0.09294377 -0.05563854 -0.051405213 -0.08442332 7 -0.08431200 -0.01657793 -0.119773022 -0.07364633 8 -0.06105875 -0.05311773 -0.062928495 -0.06982507 9 -0.05757523 -0.02589045 -0.102312333 -0.05616588 10 -0.05092343 -0.03935830 -0.062069716 -0.05402492 11 -0.08057353 -0.12690058 -0.004248301 -0.06850326 12 -0.08052613 -0.04962747 -0.098955086 -0.06496541 13 -0.07901151 -0.07587651 -0.077401999 0.96525294 14 -0.07187448 -0.15431262 0.952982852 -0.06471004 15 -0.07230232 -0.13704876 0.032573081 -0.05040565 So I'd like the top-left histogram on the diagonal to be coloured black, then the next one on the diagonal to be coloured blue etc. Is this possible? Normally information about what is being plotted isn't passed to the panel function, and attributes of the columns are stripped off before passing, so this isn't easy. If you want to do some ugly programming, you can look up the variable i in the sys.frame(2) environment; that will be the column number. While you're at it, you might as well get the data too: it's called x there. For example, d - data.frame(black=rnorm(100), blue=rnorm(100), brown=rnorm(100), cyan=rnorm(100)) panel.hist - function(x, ...) { # get some graphical parameter settings, and reset them on exit usr - par(usr) on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) # get a histogram of the data, but don't plot it - we just need to get some info from the histogram h - hist(x, plot = FALSE) breaks - h$breaks nB - length(breaks) y - h$counts; y - y/max(y) colnum - parent.frame(2)$i x - parent.frame(2)$x colour - colnames(x)[colnum] rect(breaks[-nB], 0, breaks[-1], y, col=colour, ...) } pairs(d, upper.panel=panel.smooth, diag.panel=panel.hist) Duncan Murdoch Cheers, Nathan - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkmHovYACgkQ9gTv6QYzVL5bUgCgw3EHQKS9WjO2AmtEks6x0Bh9 FLgAoIFpikJ903quFBaxQe5UVXAAbrnq =XRan -END PGP SIGNATURE- __ R-help@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. __ R-help@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.
[R] pairs() help - colour histograms on diagonal
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 I'd like to be able to colour histograms along the diagonal using the colours stored in colnames(d): d blackbluebrowncyan 1 0.96405751 -0.02964390 -0.060147424 -0.06460070 2 -0.03614607 0.95475444 -0.152382053 -0.07767974 3 -0.07095613 -0.05884884 -0.061289399 -0.06445973 4 -0.03708223 -0.05997624 -0.054044275 -0.08291373 5 -0.08877190 -0.07193658 -0.078598617 -0.08892916 6 -0.09294377 -0.05563854 -0.051405213 -0.08442332 7 -0.08431200 -0.01657793 -0.119773022 -0.07364633 8 -0.06105875 -0.05311773 -0.062928495 -0.06982507 9 -0.05757523 -0.02589045 -0.102312333 -0.05616588 10 -0.05092343 -0.03935830 -0.062069716 -0.05402492 11 -0.08057353 -0.12690058 -0.004248301 -0.06850326 12 -0.08052613 -0.04962747 -0.098955086 -0.06496541 13 -0.07901151 -0.07587651 -0.077401999 0.96525294 14 -0.07187448 -0.15431262 0.952982852 -0.06471004 15 -0.07230232 -0.13704876 0.032573081 -0.05040565 panel.hist - function(x, ...) { # get some graphical parameter settings, and reset them on exit usr - par(usr) on.exit(par(usr)) par(usr = c(usr[1:2], 0, 1.5) ) # get a histogram of the data, but don't plot it - we just need to get some info from the histogram h - hist(x, plot = FALSE) breaks - h$breaks nB - length(breaks) y - h$counts; y - y/max(y) rect(breaks[-nB], 0, breaks[-1], y, ...) } pairs(d, upper.panel=panel.smooth, diag.panel=panel.hist) So I'd like the top-left histogram on the diagonal to be coloured black, then the next one on the diagonal to be coloured blue etc. Is this possible? Cheers, Nathan - -- - Dr. Nathan S. Watson-Haigh OCE Post Doctoral Fellow CSIRO Livestock Industries Queensland Bioscience Precinct St Lucia, QLD 4067 Australia Tel: +61 (0)7 3214 2922 Fax: +61 (0)7 3214 2900 Web: http://www.csiro.au/people/Nathan.Watson-Haigh.html - -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkmHovYACgkQ9gTv6QYzVL5bUgCgw3EHQKS9WjO2AmtEks6x0Bh9 FLgAoIFpikJ903quFBaxQe5UVXAAbrnq =XRan -END PGP SIGNATURE- __ R-help@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.
Re: [R] pairs plots in R
If you want to do efficient exploratory data analysis on this kind of dataset, then interactive graphics with parallel coordinate plots (ipcp in iplots) should help. Of course, it depends what you mean by large. It might be worth looking at the book Graphics of Large Datasets for some ideas. Antony Unwin Professor of Computer-Oriented Statistics and Data Analysis, Mathematics Institute, University of Augsburg, 86135 Augsburg, Germany Tel: + 49 821 5982218 From: Sharma, Dhruv [EMAIL PROTECTED] Date: 19 October 2008 10:58:53 pm GMT+02:00 To: r-help@r-project.org Subject: [R] pairs plots in R Hi, is there a way to take a data frame with 100+ columns and large data set to do efficient exploratory analysis in R with pairs? I find using pairs on the whole matrix is slow and the resulting matrix is tiny. Also the variable of interest for me is a binary var Y or N . Is there an efficient way to graphically view many variable relationships that does not look teeny ? I could do pairs 10 at a time but this seems too brute force. thanks Dhruv [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs plots in R
Thanks Felix. Regards, Dhruv -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Felix Andrews Sent: Sunday, October 19, 2008 11:37 PM To: Sharma, Dhruv Cc: r-help@r-project.org Subject: Re: [R] pairs plots in R One idea: if the primary variable of interest is a categorical (binary), I would rather look at univariate plots for each of your 100 variables, grouped by the primary one. e.g. library(latticeExtra) marginal.plot(~ myBigDat, data = myBigData, groups = myBinaryVar, auto.key = TRUE, layout = c(4, 4)) (This is a convenient interface to lattice::densityplot and lattice::dotplot) If you view 16 such densityplots per page, that still gives you 7 pages. You could use playwith() (from playwith package) to scroll through the pages. -Felix 2008/10/20 Sharma, Dhruv [EMAIL PROTECTED]: Hi, is there a way to take a data frame with 100+ columns and large data set to do efficient exploratory analysis in R with pairs? I find using pairs on the whole matrix is slow and the resulting matrix is tiny. Also the variable of interest for me is a binary var Y or N . Is there an efficient way to graphically view many variable relationships that does not look teeny ? I could do pairs 10 at a time but this seems too brute force. thanks Dhruv [[alternative HTML version deleted]] __ R-help@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. -- Felix Andrews / 安福立 http://www.neurofractal.org/felix/ 3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8 __ R-help@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.
Re: [R] pairs plots in R
thanks Antony. regards, Dhruv From: Antony Unwin [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2008 7:00 AM To: r-help@r-project.org Cc: Sharma, Dhruv Subject: Re: [R] pairs plots in R If you want to do efficient exploratory data analysis on this kind of dataset, then interactive graphics with parallel coordinate plots (ipcp in iplots) should help. Of course, it depends what you mean by large. It might be worth looking at the book Graphics of Large Datasets for some ideas. Antony Unwin Professor of Computer-Oriented Statistics and Data Analysis, Mathematics Institute, University of Augsburg, 86135 Augsburg, Germany Tel: + 49 821 5982218 From: Sharma, Dhruv [EMAIL PROTECTED] Date: 19 October 2008 10:58:53 pm GMT+02:00 To: r-help@r-project.org Subject: [R] pairs plots in R Hi, is there a way to take a data frame with 100+ columns and large data set to do efficient exploratory analysis in R with pairs? I find using pairs on the whole matrix is slow and the resulting matrix is tiny. Also the variable of interest for me is a binary var Y or N . Is there an efficient way to graphically view many variable relationships that does not look teeny ? I could do pairs 10 at a time but this seems too brute force. thanks Dhruv [[alternative HTML version deleted]] __ R-help@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.
Re: [R] pairs plots in R
One idea: if the primary variable of interest is a categorical (binary), I would rather look at univariate plots for each of your 100 variables, grouped by the primary one. e.g. library(latticeExtra) marginal.plot(~ myBigDat, data = myBigData, groups = myBinaryVar, auto.key = TRUE, layout = c(4, 4)) (This is a convenient interface to lattice::densityplot and lattice::dotplot) If you view 16 such densityplots per page, that still gives you 7 pages. You could use playwith() (from playwith package) to scroll through the pages. -Felix 2008/10/20 Sharma, Dhruv [EMAIL PROTECTED]: Hi, is there a way to take a data frame with 100+ columns and large data set to do efficient exploratory analysis in R with pairs? I find using pairs on the whole matrix is slow and the resulting matrix is tiny. Also the variable of interest for me is a binary var Y or N . Is there an efficient way to graphically view many variable relationships that does not look teeny ? I could do pairs 10 at a time but this seems too brute force. thanks Dhruv [[alternative HTML version deleted]] __ R-help@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. -- Felix Andrews / 安福立 http://www.neurofractal.org/felix/ 3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8 __ R-help@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.
[R] Pairs() function: selective changing of ylim; use of key
All, Two questions RE scatterplot matrices produced via pairs() function: 1) Is it possible to selectively change the ylim of one of the subplots? 2) Is a key allowed? I don't seem to be able to insert a manual key. Code below: dat = data.frame(Hour= rep(c(0:3), 4), Y1 = rnorm(16,1), Y2 = rnorm(16,4),Drug = rep(c(P, D), each=4, 2) ) ## this works: pairs(dat, pch = 21, bg = c(red, green3)[unclass(dat$Drug)]) ## this produces several warnings: pairs(dat, pch = 21, bg = c(red, green3)[unclass(dat$Drug)], key = list(space = top, text = levels(dat$Drug), lines = list(col=c(red, green3)), columns=2) ) Cheers, David __ R-help@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.
[R] pairs diagram of qq plots?
Hello everyone, for some exploratory analysis I would like to compare the distribution of an observable WERT pairwise between several samples identified by STICHPROBE (which differ in size). str(stichproben_o1o4_20080327ff[c(STICHPROBE, WERT)]) 'data.frame': 6087 obs. of 2 variables: $ STICHPROBE: num 9 9 2 2 7 3 2 3 8 6 ... $ WERT : num 165 184 110 131 87 111 210 88 159 198 ... A good way to compare two distributions is a Q-Q or Tukey mean-difference (tmd) plot. I would like to arrange these qq or tmd plots in a matrix as the pairs() function does. Can pairs() be made to immediately produce tmd plots instead of plain scatter plots, or will I have to do the tmd processing in a separate step and only pass the such preprocessed xy data to pairs()? Another problem is the representation of the data with respect to pairs(). My data.frame identifies the sample of each measurement in column STICHPROBE. It does not have one column for each sample (note again that the samples differ in size). From what I understand about pairs() it requires a separate column for each variable. The reshape() function should be able to change the representation but the best I can achieve is a wide dataframe with multiple columns (as desired) but no rows: reshape(stichproben_o1o4_20080327ff[c(STICHPROBE, WERT)], timevar=STICHPROBE, direction=wide) [1] WERT.9 WERT.2 WERT.7 WERT.3 WERT.8 WERT.6 WERT.1 WERT.4 WERT.0 WERT.5 0 rows (or 0-length row.names) Best regards Stefan [[alternative HTML version deleted]] __ R-help@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.
[R] pairs, par(plt)
I'm having some confusion over the coordinate system after using pairs. I'm not interested in the content of the actual pairs plot, although the number of pairs seems to matter a bit. I'm purely interested in knowing where my points will be plotted on the device. However, after using pairs, the par information (omd, fig, plt, and usr) don't reflect what points does. For example: pairs(iris[1:5]) par(xpd = NA) points(0 - 0.01 * 1:100, 0 - 0.01 * 1:100) points(0 - 0.01 * 1:100, 1 + 0.01 * 1:100) points(1 + 0.01 * 1:100, 0 - 0.01 * 1:100) points(1 + 0.01 * 1:100, 1 + 0.01 * 1:100) par(c(omd, fig, plt, usr)) The resulting plot shows that the corners of the are approximately 0.05 user coordinate units from the boundaries of the plot region. According to par, though, there is a margin around the plotting region that is clearly not symmetric and does not correspond to around 0.05 units. If we use pairs(iris[1:2]) and repeat the rest, the corners are now 0.02 user coordinate units. par provides the same information as before. So: 1. How do I figure out where coordinates I give to points will display on the figure? 2. More generally (for my own understanding), why does the par information not do what I expect? Do I have some fundamental misunderstanding of the arrangement of plotting, figure, display, and margin regions within the device? I'm using R 2.5.1, and this behavior occurs on a fresh R console. Thanks! Oliver -- Oliver Soong Donald Bren School of Environmental Science Management University of California, Santa Barbara Santa Barbara, CA 93106-5131 805-893-7044 (office) 610-291-9706 (cell) __ R-help@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.