q <- ggplot(myData)
q + geom_pointrange(aes(x= factor(time), y=mean, ymin=lci, ymax=uci,
colour=factor(treatment)), width = 1.2, size = 1.2) +
geom_line(aes(x = factor(time), y = mean, group=1), colour = 'blue') +
facet_grid(. ~ treatment) +
scale_colour_discrete('Treatment')
On Wednesday, January 26, 2011 at 10:23 AM, Sean wrote:
+ geom_line(aes(group =1))
dfm$D <- "D1"
dfm$D[grep("D2", dfm$variable)] <- "D2"
ggplot(dfm, aes(variable, value)) + geom_point() + facet_grid(Sex
~Drug) + stat_summary(fun.y = mean, geom="line", aes(group=D))
Best,
Ista
> --
> 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
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
df <- data.frame(rep(c("male", "female"), 5), rep(c("Drug1", "Drug2"),
5), pre_D1=c(10:1), post_D1=c(1:10), pre_D2=c(25:16),
post_D2=c(16:25))
colnames(df)[1:2] <- c("Sex", "Drug")
df$ID <- factor(1:10)
dfm <- melt(df, id=c(1:2, 7))
dfm$d <- "D1"
dfm$d[grep("D2", dfm$variable)] <- "D2"
dfm$code <- paste(dfm$ID, dfm$d, sep="_")
ggplot(dfm, aes(variable, value)) + geom_point() +
facet_grid(Sex~Drug) + geom_line(aes(group=code))
Best,
Ista
I'm not sure your clarification made it to the whole group (didn't see
it just now), but Ista's (second) solution does do what you want. Here
is a slightly different approach that gives the exact same plot that
Ista's solution does.
df <- data.frame(ID=factor(1:10),
Sex=rep(c("male", "female"), 5),
Drug=rep(c("Drug1", "Drug2"), 5),
pre_D1=c(10:1),
post_D1=c(1:10),
pre_D2=c(25:16),
post_D2=c(16:25))
dfm <- melt(df, id=c("ID", "Sex", "Drug"))
dfm <- cbind(dfm,
colsplit(dfm$variable, "_", names=c("timing","D")))
ggplot(dfm, aes(variable, value)) +
geom_point() +
geom_line(aes(group=interaction(ID, D))) +
facet_grid(Sex ~ Drug)
The only real difference between our solutions (aside from trivial
indenting/formatting) is how the D1/D2 information is extracted into its
own column (assignments with grep versus using colsplit) and how the
ultimate line grouping is specified (a separate variable combining ID
and D versus using interaction in the group specification avoiding
creating a new variable)
> Sean T. Ma
> Univ of Michigan
>
>
> On Wed, Jan 26, 2011 at 2:36 PM, Brian
> Diggs<dig...@ohsu.edu<mailto:dig...@ohsu.edu>> wrote:
>
>
> On Jan 26, 8:23 am,
--
d <- ddply(w, .(id), function(df) {
r <- df[df$time==2, "p"] - df[df$time==1, "p"]
d <- data.frame(id = unique(df$id), diff=r)
return(d)})
w <- merge(w, d)
ggplot(w, aes(time, p, size=trials)) + geom_point() +
geom_line(size=0.25, aes(group=id, color=diff))
Best,
Ista
subj<-c(1:50)
trials1<-floor(runif(50,1,13))
p1<-rbinom(50,trials1,.30)/trials1
trials2<-floor(runif(50,1,13))
p2<-rbinom(50,trials2,.70)/trials2
id<-rep(subj,2)
time<-c(rep(1,50),rep(2,50))
trials<-c(trials1,trials2)
p<-c(p1,p2)
w<-data.frame(id,time,trials,p)
library(ggplot2)
d <- ddply(w, .(id), function(df) {
r <- df[df$time==2, "p"] - df[df$time==1, "p"]
d <- data.frame(id = unique(df$id), diff=r)
return(d)})
w <- merge(w, d)
ggplot(w2, aes(time, p, size=trials)) + geom_point() +
geom_line(size=0.25, aes(group=id, color=diff))
dim(w)
[1] 100 5
Best,
Ista