Back to the Top
This is the sample data, and i am new to R and trying to plot a graph in the following way
individual ID Vs IPRE,DV, PRED is there a way could someone help me on this
ID TIME TAD AMT BL WARD IPRE DV PRED RES WRES
1 1 0.00 0.00 0 0 0 0.00 0.01 0.00 0.00 0.95
2 1 0.01 0.00 20 0 0 0.00 0.00 0.00 0.00 0.00
3 1 1.00 0.99 0 0 0 0.11 0.13 0.02 0.11 3.85
4 1 2.00 1.99 0 0 0 0.11 0.12 0.02 0.10 4.00
5 1 4.00 3.99 0 0 0 0.10 0.07 0.02 0.05 -0.48
6 1 6.00 5.99 0 0 0 0.09 0.03 0.02 0.02 -3.07
7 1 8.00 7.99 0 0 0 0.08 0.04 0.02 0.03 -2.04
8 1 24.00 24.00 0 0 0 0.04 0.03 0.01 0.02 -0.32
16 2 0.00 0.00 20 0 0 0.00 0.00 0.00 0.00 0.00
17 2 1.00 1.00 0 0 0 0.01 0.00 0.02 -0.02 -1.09
18 2 2.00 2.00 0 0 0 0.01 0.01 0.02 -0.01 -0.55
19 2 4.00 4.00 0 0 0 0.01 0.01 0.02 -0.01 -0.58
20 2 6.00 6.00 0 0 0 0.01 0.00 0.01 -0.01 -0.71
21 2 8.00 8.00 0 0 0 0.01 0.00 0.01 -0.01 -0.63
22 2 24.00 24.00 0 0 0 0.01 0.00 0.01 0.00 -0.44
Thanks in advance - this is the one i am expecting an output (did this graph using EXCEL), this is for one subject i have 33 subject and looking to plot them individually
Back to the Top
The following message was posted to: PharmPK
You may also find help with R problems on the R-Help mailing list https://stat.ethz.ch/mailman/listinfo/r-help
or at Stackoverflow http://stackoverflow.com/questions/tagged/r
Here's some pseudo code that might solve your problem (not extensively
tested)
To Plot values of IPRE, DV, and Pred against Subject ID I would use the
excellent ggplot2 package, If I haven't graphed what you actualy wanted
check our Hadleys ggplot2 site
http://had.co.nz/ggplot2/
to work out how to tweak it
> dput(pkdata)
structure(list(Row = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 16L, 17L,
18L, 19L, 20L, 21L, 22L), ID = structure(c(1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class "factor"),
TIME = c(0, 0.01, 1, 2, 4, 6, 8, 24, 0, 1, 2, 4, 6, 8, 24
), TAD = c(0, 0, 0.99, 1.99, 3.99, 5.99, 7.99, 24, 0, 1,
2, 4, 6, 8, 24), AMT = c(0L, 20L, 0L, 0L, 0L, 0L, 0L, 0L,
20L, 0L, 0L, 0L, 0L, 0L, 0L), BL = c(0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), WARD = c(0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), IPRE = c(0,
0, 0.11, 0.11, 0.1, 0.09, 0.08, 0.04, 0, 0.01, 0.01, 0.01,
0.01, 0.01, 0.01), DV = c(0.01, 0, 0.13, 0.12, 0.07, 0.03,
0.04, 0.03, 0, 0, 0.01, 0.01, 0, 0, 0), PRED = c(0, 0, 0.02,
0.02, 0.02, 0.02, 0.02, 0.01, 0, 0.02, 0.02, 0.02, 0.01,
0.01, 0.01), RES = c(0, 0, 0.11, 0.1, 0.05, 0.02, 0.03, 0.02,
0, -0.02, -0.01, -0.01, -0.01, -0.01, 0), WRES = c(0.95,
0, 3.85, 4, -0.48, -3.07, -2.04, -0.32, 0, -1.09, -0.55,
-0.58, -0.71, -0.63, -0.44)), .Names = c("Row", "ID", "TIME",
"TAD", "AMT", "BL", "WARD", "IPRE", "DV", "PRED", "RES", "WRES"
), row.names = c(NA, -15L), class = "data.frame")
> library(ggplot2)
> #Do individual plots
> pkplot1<-qplot(data=pkdata, x=TIME, y=IPRE, colour=ID)
> print(pkplot1)
> # use reshape to reform data into narrow format
>
> pkmelt<-melt(data=pkdata, id.vars=c("Row","ID","TIME"))
> # Now can do one plot with each variable pulled into a single panel
> pkplot2<-ggplot(pkmelt, aes(TIME, value)) +
+ geom_point(aes(shape = ID)) +
+ scale_shape(solid = FALSE) +
+ facet_wrap( ~ variable)
>
> print(pkplot2)
--
Paul Hurley
Back to the Top
The following message was posted to: PharmPK
Chandramouli,
One way is as follows.
Assume your data is d
library(lattice)
d2 <- stack(d[,c("IPRE","PRED","DV")])
d2$ID <- d$ID
xyplot(values~ID|ind,data=d2);
or
xyplot(ID~values|ind,data=d2);
Incidentally, If you want to plot each of these variables against time (what I usually do), I would do something slightly different:
xyplot(DV+PRED+IPRE ~ TIME | paste("ID:",ID),data=d,col=c("black","red","blue"),lty=c(0,1,1),pch= c(1,NA,NA),type="o",scales=list(y=list(log=10)),ylab="Concentrat ion",xlab="Time",key=list(lines=list(lty=c(0,1,1),pch=c(1,NA,NA) ,col=c("black","red","blue"),type="o"),text=list(c("Obs.","Pop.","In d.")),columns=3))
Want to post a follow-up message on this topic?
If this link does not work with your browser send a follow-up message to PharmPK@boomer.org with "Graphing with R" as the subject | Support PharmPK by using the |
Copyright 1995-2011 David W. A. Bourne (david@boomer.org)