[R] Produce multiple line graphs

Jim Lemon drjimlemon at gmail.com
Mon Sep 26 04:05:47 CEST 2016


Hi John,
I know this is kind of dumb, but:

plot(0,xlim=range(xx$Nit,na.rm=TRUE),
 ylim=range(xx$CT,na.rm=TRUE),type="n",
 xlab="Nit",ylab="CT")
for(i in unique(xx$PID))
 points(xx$Nit[xx$PID==i],xx$CT[xx$PID==i],
 pch=i,col=i,type="b")

Jim


On Mon, Sep 26, 2016 at 11:43 AM, John Sorkin
<JSorkin at grecc.umaryland.edu> wrote:
> I have a data frame that contains data for multiple (seven) subjects. Each subject is represented by a new value of PID.
> I would like to plot the data for all seven subjects. For each subject I want to plot a line showing CT as a function of Nit, with the dots for each subject joined. I have tried to accomplish this using the by function. I get an error message,
> Error in match.fun(panel) :
>   'xx[, "CT"]' is not a function, character or symbol
> I have no idea what is causing the error, nor how to correct the error, nor how to get the dots for each point be connected by a line.
>
>
> Any help would be appreciated!
>
>
> PID <- c( 1 ,  1   ,  1   , 1   , 2, 2, 2, 2, 3   ,   3  ,  3   ,  3   ,  4   ,  4,  4, 4    , 5, 5, 5, 5, 6, 6, 6, 6, 7   ,  7   ,    7  , 7)
> Nit <- c(NA , -9.23,-11.61,-7.88,NA,NA,NA,NA,-5.59,  0.73,-10.55, -9.13,  3.67, NA, NA,-13.26,NA,NA,NA,NA,NA,NA,NA,NA,-9.36,  5.08,  -5.73, 2.02)
> CT  <- c(544,459   ,432   ,NA   ,NA,NA,NA,NA,1398 ,1287  ,1049  , NA   ,543   ,474,507,NA    ,NA,NA,NA,NA,NA,NA,NA,NA,992  ,992   ,1078   ,NA)
> xx  <- data.frame(PID=PID,Nit=Nit,CT=CT)
> xx
> by(xx,as.factor(xx[,"PID"]),plot,xx[,"Nit"],xx[,"CT"])
>
>
>
>
> John David Sorkin M.D., Ph.D.
> Professor of Medicine
> Chief, Biostatistics and Informatics
> University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine
> 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:12}}



More information about the R-help mailing list