In this case you need probably a melted dataframe (have
a look at the melt function (in package reshape or reshape2).
Then your dataframe should look like:
ID time variable concentration
so all concentrations in one column and the column
variable states if it is the drug concentration or
the metabolite concentration.
Then you can use
ggplot(DTM1, aes(Time, DT), colour=variable)
So that the points for the drug concentration have a
different color then these for the metabolite conc.
But maybe you want something totally different and I
misunderstood you completely.
cheers
/j
-------- Original-Nachricht --------
> Datum: Thu, 10 Nov 2011 09:24:37 -0500
> Von: Robert Strother <rstr...@gmail.com>
> An: ggp...@googlegroups.com
> Betreff: plotting 2 dependent variables on same scatterplot
> --
> You received this message because you are subscribed to the ggplot2
> mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone
Here's a small reproducible example to illustrate Johannes' point.
# Vars: subject, time, two response variables
df <- data.frame(subj = rep(1:4, each = 30),
time = rep(1:15, 8),
DT = rnorm(120),
DTM = 3 + rnorm(120))
library('ggplot2')
# melt() stacks the two response variables into a
# factor (variable) and its values (value): this makes it
# easier to plot in ggplot2 (and lattice, for that matter)
dfm <- melt(df, id = c('subj', 'time'))
# Use the new factor as the variable defining the color
# aesthetic and use the value variable as the response
ggplot(dfm, aes(x = time, y = value, colour = variable)) +
geom_point() +
labs(x = 'Time', y = 'Value', colour = 'Conc') +
scale_colour_manual(breaks = levels(dfm$variable),
values = c('blue', 'orange')) +
facet_wrap(~ subj, nrow = 2)
# Add fitted lines with SE envelopes to the graph:
ggplot(dfm, aes(x = time, y = value, colour = variable)) +
geom_point() +
geom_smooth(method = 'lm') +
labs(x = 'Time', y = 'Value', colour = 'Compound') +
scale_colour_manual(breaks = levels(dfm$variable),
values = c('blue', 'orange')) +
facet_wrap(~ subj, nrow = 2)
HTH,
Dennis