[R] Dose Profile

Jim Lemon jim at bitwrit.com.au
Wed Oct 29 09:46:14 CET 2008


Laura Bonnett wrote:
> Hi Everyone,
>
> I have data in a long format e.g. there is one row per patient but each
> follow-up appointment is included in the row.  So, a snippet of the data
> looks like this:
>       TrialNo Drug Sex Rand Adate1 Date1 Dose1 Time1 Adate2 Date2 Dose2
> Time2  B1001029 LTG M 15719 30/04/2003 15825 150 106 29/08/2003 15946 200
> 227  B1117003 LTG M 15734 30/04/2003 15825 200 91 03/09/2003 15951 250 217
> B138015 LTG M 14923 06/02/2001 15012 225 89 08/05/2001 15103 300 180
> B112003 TPM F 14914 15/01/2001 14990 60 76 05/03/2001 15039 100 125
> Of course, not everyone has the same number of follow-up appointments and so
> there may be some column entries that are NAs.
>
> What I'd like to do is a dose profile i.e. a plot of time on the x-axis
> agaisnt dose on the y-axis for each patient ideally colouring lines
> according to drug.  Does anyone know how I can do this?  Someone at work has
> suggested that I use plot and then loess.smooth but I don't really know what
> to do.
>
>   
Hi Laura,
You can get a basic plot like this:

matplot(rbind(lbonnett$Time1,lbonnett$Time2),
 rbind(lbonnett$Dose1,lbonnett$Dose2),type="l",
 col=lbonnett$Drug,lty=1)

As you can see by running this, you will get a line for each patient, 
with the color of each line determined by the drug (you can select 
different colors, I was just being lazy). The problem you are likely to 
face is that there will be gaps in the lines if you have NAs. You can 
rejig matplot or write a similar function to get around this so that the 
lines are just drawn across the gaps if that is what you want.

Jim



More information about the R-help mailing list