[R] Connect lines in a dot plot on a subject-by-subject basis

John Sorkin jsorkin at grecc.umaryland.edu
Wed Mar 28 23:59:45 CEST 2012


Thank you Bert. I will try your suggestion.
You are ever gracious with your knowledge and expertise.
John

John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

>>> Bert Gunter <gunter.berton at gene.com> 3/28/2012 5:49 PM >>>
Oh ... you may need to specify a single color to avoid a rainbow:

xyplot( Value ~ Time, Group = SubjectID, data = dat, type = "b", col = "black")

-- Bert

On Wed, Mar 28, 2012 at 2:39 PM, John Sorkin
<jsorkin at grecc.umaryland.edu> wrote:
> I am trying to plot where data points from a give subject are connected by a line. Each subject is represented by a single row of data. Each subject can have
> up to five observations. The first five columns of mydata give the time of observation, columns 6-10 give the values at each time point. Some subjects have
> all data, some are missing values.
>
> The code I wrote to draw the plot is listed below. If you run the code you will see that (1) The few lines drawn are not drawn on a subject-by-subject basis, (2) not all lines are drawn.
>
> I hope someone can help me fix my code
>
> Thanks,
> John
>
> # Create a matrix to hold our data.
> mydata <- matrix(nrow=10,ncol=10)
> dimnames(mydata) <- list(NULL,c("time1", "time2", "time3", "time4", "time5",
>                                "clot1", "clot2", "clot3", "clot4", "clot5"))
> # load data into the matrix.
> # The first five columns represent time of measurement
> # Columns 6-10 have the measured values.
> mydata[1,]=c( 1, 3, NA,NA, NA, 22, 40, NA, NA, NA)
> mydata[2,]=c( 1, NA,NA,NA, NA, 39, NA, NA, NA, NA)
> mydata[3,]=c( 1, 6, NA,NA, NA, 47, 43, NA, NA, NA)
> mydata[4,]=c( 1, 3, 7, 21, NA, 34, 29, 33, 21, NA)
> mydata[5,]=c( NA,NA,NA,NA, NA, NA, NA, NA, NA, NA)
> mydata[6,]=c( 1, 3, 7, 19, 35, 42, 60, 86, 56, 39)
> mydata[7,]=c( 1, NA,NA,NA, NA, 57, NA, NA, NA, NA)
> mydata[8,]=c( 1, 3, 10,17, 25, 71, 55, 57, 62, 47)
> mydata[9,]=c( 1, NA,NA,NA, NA, 79, NA, NA, NA, NA)
> mydata[10,]=c( 1,3, 9, NA, NA, 60, 64, 68, NA, NA)
>
> # Dispaly data.
> mydata
>
> # Plot data.
> plot(mydata[,1:5],mydata[,6:10])
> # Attempt to connect points for each subject with lines.
> lines(mydata[,1:5],mydata[,6:10],type="b")
>
> John David Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> (Phone) 410-605-7119
> (Fax) 410-605-7913 (Please call phone number above prior to faxing)
>
> Confidentiality Statement:
> This email message, including any attachments, is for ...{{dropped:30}}



More information about the R-help mailing list