Re: [R] plot the number of replicates at the same point
You can do the following (don't know it this is the most efficient way but it works) temp<-read.table("your file to read the data", header=T) temp1<-table(temp) plot(temp$x, temp$y, cex=0) text(as.numeric(rownames(temp1)), as.numeric(colnames(temp1)), temp1) HTH On Wed, 13 Jul 2005, Kerry Bush wrote: > Dear R-helper, > I want to plot the following-like data: > > x y > 1 1 > 1 1 > 1 2 > 1 3 > 1 3 > 1 4 > .. > > In the plot that produced, I don't want to show the > usual circles or points. Instead, I want to show the > number of replicates at that point. e.g. at the > position of (1,1), there are 2 obsevations, so a > number '2' will be displayed in the plot. > Is my narrative clear? Is there a way to make the plot > in R? > > __ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot the number of replicates at the same point
Thank you for thinking about the problem for me. However, I have found that your method doesn't work at all. You may test the following example: x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) x1=rep(x1,4) x2=rep(x2,4) temp=data.frame(x1,x2) temp1=table(temp) plot(temp$x1,temp$x2,cex=0) text(as.numeric(rownames(temp1)), as.numeric(colnames(temp1)), temp1) what I got here is not what I wanted. You may compare with plot(x1,x2) I actually want some plots similar to what SAS proc plot produced. Does anybody have a clue of how to do this easily in R? --- Jean Eid <[EMAIL PROTECTED]> wrote: > You can do the following (don't know it this is the > most efficient way but > it works) > > temp<-read.table("your file to read the data", > header=T) > temp1<-table(temp) > plot(temp$x, temp$y, cex=0) > text(as.numeric(rownames(temp1)), > as.numeric(colnames(temp1)), temp1) > > HTH > > > On Wed, 13 Jul 2005, Kerry Bush wrote: > > > Dear R-helper, > > I want to plot the following-like data: > > > > x y > > 1 1 > > 1 1 > > 1 2 > > 1 3 > > 1 3 > > 1 4 > > .. > > > > In the plot that produced, I don't want to show > the > > usual circles or points. Instead, I want to show > the > > number of replicates at that point. e.g. at the > > position of (1,1), there are 2 obsevations, so a > > number '2' will be displayed in the plot. > > Is my narrative clear? Is there a way to make the > plot > > in R? > > > > __ > > R-help@stat.math.ethz.ch mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > > > __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot the number of replicates at the same point
On 7/14/05, Kerry Bush <[EMAIL PROTECTED]> wrote: > Thank you for thinking about the problem for me. > However, I have found that your method doesn't work at > all. > > You may test the following example: > > x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) > x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) > x1=rep(x1,4) > x2=rep(x2,4) > temp=data.frame(x1,x2) > temp1=table(temp) > plot(temp$x1,temp$x2,cex=0) > text(as.numeric(rownames(temp1)), > as.numeric(colnames(temp1)), temp1) > > what I got here is not what I wanted. You may compare > with > plot(x1,x2) > > I actually want some plots similar to what SAS proc > plot produced. > > Does anybody have a clue of how to do this easily in > R? Try this: x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) x1=rep(x1,4) x2=rep(x2,4) temp=data.frame(x1,x2) foo <- subset(as.data.frame(table(temp)), Freq > 0) foo$x1 <- as.numeric(as.character(foo$x1)) foo$x2 <- as.numeric(as.character(foo$x2)) with(foo, plot(x1, x2, type = "n")) with(foo, text(x1, x2, lab = Freq)) -Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot the number of replicates at the same point
On Thu, 2005-07-14 at 12:30 -0500, Deepayan Sarkar wrote: > On 7/14/05, Kerry Bush <[EMAIL PROTECTED]> wrote: > > Thank you for thinking about the problem for me. > > However, I have found that your method doesn't work at > > all. > > > > You may test the following example: > > > > x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) > > x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) > > x1=rep(x1,4) > > x2=rep(x2,4) > > temp=data.frame(x1,x2) > > temp1=table(temp) > > plot(temp$x1,temp$x2,cex=0) > > text(as.numeric(rownames(temp1)), > > as.numeric(colnames(temp1)), temp1) > > > > what I got here is not what I wanted. You may compare > > with > > plot(x1,x2) > > > > I actually want some plots similar to what SAS proc > > plot produced. > > > > Does anybody have a clue of how to do this easily in > > R? > > Try this: > > > x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) > x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) > x1=rep(x1,4) > x2=rep(x2,4) > temp=data.frame(x1,x2) > > foo <- subset(as.data.frame(table(temp)), Freq > 0) > foo$x1 <- as.numeric(as.character(foo$x1)) > foo$x2 <- as.numeric(as.character(foo$x2)) > > with(foo, plot(x1, x2, type = "n")) > with(foo, text(x1, x2, lab = Freq)) > > > -Deepayan Great solution Deepayan. I was just in the process of working on something similar. One quick modification is that the two plot()/text() functions can be combined into: with(foo, plot(x1, x2, pch = as.character(Freq))) Best regards, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot the number of replicates at the same point
On 7/14/05, Marc Schwartz (via MN) <[EMAIL PROTECTED]> wrote: > On Thu, 2005-07-14 at 12:30 -0500, Deepayan Sarkar wrote: > > On 7/14/05, Kerry Bush <[EMAIL PROTECTED]> wrote: > > > Thank you for thinking about the problem for me. > > > However, I have found that your method doesn't work at > > > all. > > > > > > You may test the following example: > > > > > > x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) > > > x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) > > > x1=rep(x1,4) > > > x2=rep(x2,4) > > > temp=data.frame(x1,x2) > > > temp1=table(temp) > > > plot(temp$x1,temp$x2,cex=0) > > > text(as.numeric(rownames(temp1)), > > > as.numeric(colnames(temp1)), temp1) > > > > > > what I got here is not what I wanted. You may compare > > > with > > > plot(x1,x2) > > > > > > I actually want some plots similar to what SAS proc > > > plot produced. > > > > > > Does anybody have a clue of how to do this easily in > > > R? > > > > Try this: > > > > > > x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) > > x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) > > x1=rep(x1,4) > > x2=rep(x2,4) > > temp=data.frame(x1,x2) > > > > foo <- subset(as.data.frame(table(temp)), Freq > 0) > > foo$x1 <- as.numeric(as.character(foo$x1)) > > foo$x2 <- as.numeric(as.character(foo$x2)) > > > > with(foo, plot(x1, x2, type = "n")) > > with(foo, text(x1, x2, lab = Freq)) > > > > > > -Deepayan > > > Great solution Deepayan. I was just in the process of working on > something similar. > > One quick modification is that the two plot()/text() functions can be > combined into: > > with(foo, plot(x1, x2, pch = as.character(Freq))) Only as long as all(Freq < 10) (I've been bitten by this before. :-) ). Deepayan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot the number of replicates at the same point
On Thu, 2005-07-14 at 15:08 -0500, Deepayan Sarkar wrote: > On 7/14/05, Marc Schwartz (via MN) <[EMAIL PROTECTED]> wrote: > > On Thu, 2005-07-14 at 12:30 -0500, Deepayan Sarkar wrote: > > > On 7/14/05, Kerry Bush <[EMAIL PROTECTED]> wrote: > > > > Thank you for thinking about the problem for me. > > > > However, I have found that your method doesn't work at > > > > all. > > > > > > > > You may test the following example: > > > > > > > > x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) > > > > x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) > > > > x1=rep(x1,4) > > > > x2=rep(x2,4) > > > > temp=data.frame(x1,x2) > > > > temp1=table(temp) > > > > plot(temp$x1,temp$x2,cex=0) > > > > text(as.numeric(rownames(temp1)), > > > > as.numeric(colnames(temp1)), temp1) > > > > > > > > what I got here is not what I wanted. You may compare > > > > with > > > > plot(x1,x2) > > > > > > > > I actually want some plots similar to what SAS proc > > > > plot produced. > > > > > > > > Does anybody have a clue of how to do this easily in > > > > R? > > > > > > Try this: > > > > > > > > > x1=c(0.6,0.4,.4,.4,.2,.2,.2,0,0) > > > x2=c(0.4,.2,.4,.6,0,.2,.4,0,.2) > > > x1=rep(x1,4) > > > x2=rep(x2,4) > > > temp=data.frame(x1,x2) > > > > > > foo <- subset(as.data.frame(table(temp)), Freq > 0) > > > foo$x1 <- as.numeric(as.character(foo$x1)) > > > foo$x2 <- as.numeric(as.character(foo$x2)) > > > > > > with(foo, plot(x1, x2, type = "n")) > > > with(foo, text(x1, x2, lab = Freq)) > > > > > > > > > -Deepayan > > > > > > Great solution Deepayan. I was just in the process of working on > > something similar. > > > > One quick modification is that the two plot()/text() functions can be > > combined into: > > > > with(foo, plot(x1, x2, pch = as.character(Freq))) > > Only as long as all(Freq < 10) (I've been bitten by this before. :-) ). > > Deepayan D'oh! Indeed you are correct, since 'pch' is a single character: plot(1:20, pch = as.character(1:20)) as opposed to: plot(1:20, type = "n") text(1:20, lab = 1:20) Thanks for the correction. Marc __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot the number of replicates at the same point
Hi all, This is nowhere near as elegant as Deepayan's solution, but I read the spec as plotting symbols except where there were overlays. You are welcome to improve the following... Jim count.overplot<-function(x,y,tol=NULL,...) { if(missing(x)) stop("Usage: count.overplot(x,y,tol=NULL,...)") dimx<-dim(x) # if x is a data frame or matrix with at least two columns, split it if(missing(y) && !is.null(dimx)) { y<-x[,2] x<-x[,1] } xlen<-length(x) if(xlen != length(y)) stop("x and y must be the same length.") if(is.null(tol)) tol<-c((max(x)-min(x))/1000,(max(y)-min(y))/1000) flags<-1:xlen xsep<-ysep<-xdup<-ydup<-xydup<-rep(0,xlen) nsep<-ndup<-0 for(i in 1:xlen) { if(!is.na(flags[i])) { dups<-abs(x - x[i]) <= tol[1] & abs(y - y[i]) <= tol[2] ndups<-sum(dups) if(ndups > 1) { ndup<-ndup+1 xydup<-ndups xdup[ndup]<-x[i] ydup[ndup]<-y[i] } else { nsep<-nsep+1 xsep[nsep]<-x[i] ysep[nsep]<-y[i] } } flags[dups]<-NA } plot(xsep[1:nsep],ysep[1:nsep],...) text(xdup[1:ndup],ydup[1:ndup],xydup[1:ndup]) } __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] plot the number of replicates at the same point
See ?sunflowerplot for a graphic indication of the number of replications at each point. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html