Thank you to Jean Adams, Julia Reid and Joseph Verducci for their
answers to my question. Joseph's did not address my question of using
the entries in the matrix as plotting symbols, but with Jean's and
Julia's suggestions that was easy to implement. I ended up using a
modification of Jean's. Thank you all.
Your answers are listed below
Carlos Alzola
calzola@cox.net
(703) 242-6747
-----Original Message-----
From: Jean V Adams [mailto:jvadams@usgs.gov]
Sent: Tuesday, July 27, 2004 7:50 AM
To: Carlos Alzola
Subject: Re: [S] Plotting values of vectors as symbols
Try this:
score1 <- dimnames(shft.a.i)[[1]][row(shft.a.i)]
score2 <- dimnames(shft.a.i)[[2]][col(shft.a.i)]
plot(score1, score2, type="n")
text(score1, score2, shft.a.i)
JVA
"Carlos Alzola"
<calzola@cox.net> To:
<s-news@lists.biostat.wustl.edu>
Sent by: cc:
s-news-owner@lists.biosta Subject: [S]
Plotting values of vectors as symbols
t.wustl.edu
07/26/2004 02:05 PM
-----Original Message-----
From: Julia Reid [mailto:jreid@myriad.com]
Sent: Monday, July 26, 2004 3:20 PM
To: Carlos Alzola
Subject: Re: [S] Plotting values of vectors as symbols
This is how I would do it. First, spin out your data so that there is
one row for each patient. The first column is the original score, the
second column is after the intervention. (I am using x for your original
matrix shft.a.i.)
x<-shft.a.i
xlong<-data.frame(cbind(rep(as.numeric(dimnames(x)[[1]]),rowSums(x)),rep
(rep(as.numeric(dimnames(x)[[2]]),rep(nrow(x),ncol(x))),as.vector(x))))
dimnames(xlong)[[2]]<-c("score1","score2")
plot(xlong$score1, xlong$score2, xlab="Initial score", ylab="Score after
intervention", xlim=c(0,12), ylim=c(0,12), type="n") text(xlong$score1,
xlong$score2, pch="*", labels=as.vector(x[x!=0]))
Hope this helps.
Julia
Joe's answer:
Carlos,
x.scores <- as.numeric(dimnames(shft.a.i)[[1]]))
y.scores <- as.numeric(dimnames(shft.a.i)[[2]]))
x <- xscores[rep(row(shft.a.i),shft.a.i)]
y <- yscores[rep(col(shft.a.i),shft.a.i)]
plot(x,y)
Joe
Original question:
Good morning,
I have a matrix like the following
> shft.a.i
0 3 4 6 7 8 9 10 11 12
3 0 0 0 1 0 0 0 0 0 0
6 0 1 1 1 0 0 1 0 0 0
7 0 0 1 0 0 0 0 0 0 0
8 2 0 1 0 1 0 1 1 0 0
9 0 0 1 2 0 0 1 2 0 0
10 0 0 1 2 1 0 0 0 1 1
11 0 0 0 0 0 1 1 0 0 0
12 0 1 0 1 0 0 1 2 3 1
The row names are scores and the column names are scores after an
intervention. That is, of all patients whith an initial score of 12, 1
went down to 4, 1 went down to 9, 2 went down to 10, 3 went down to 11
and 1 remained at 12.
I'd like to present this graphically with the initial scores in the
x-axis and in the y-axis the scores after the intervention. I also would
want to use the number of patients in a group in the y-axis as a symbol.
Thus for x = 12 I would have a '1' plotted at y = 3, a '2' plotted at y
=10, etc. I also would want the x-axis to be complete: i.e. even though
4 and 5 are not initial scores they should appear in the plot.
Can anybody suggest a simple way of doing this?
Thanks
Carlos Alzola
calzola@cox.net
(703) 242-6747
|