0

I am desiring to plot two levels of data (high, low) for two days (day o, day 1) for both male and female subjects. I have been success in faceting by day and by level. However I am unsuccessful of combining and identifying the genders. I would like to show the male/female together on day 0 and day 1. Below is specific code I have been trying to create. Thanks in advance

data <- function(ids,time_vec) {
obs.data <-  
data.frame(expand.grid(ids,time_vec),DOSE=0,Conc=rnorm(13,10,2),Day=0) 
names(obs.data) <- c("ID","TIME","DOSE","Conc","Day")
obs.data<-obs.data[order(obs.data$ID),]
return(obs.data)
}

test<-data(ids=1:4, time_vec= seq(0,120,10))
test$Gender<-ifelse(test$ID==1|test$ID ==3,"Male","Female")
test$Day<-ifelse(test$ID==1|test$ID==2,"Day 1","Day 2")
test$DoseLevel<-ifelse(test$ID==1|test$ID==2,"Low","High")

gf1<-ggplot(test,aes(x=TIME, y=(Conc), group=interaction(DoseLevel,Day, 
   Gender)))+
  geom_line(size=1.25)+
  facet_grid(DoseLevel~.,as.table=FALSE)
gf1

gf2<-gf1+  geom_point(aes(shape=factor(Day), fill=factor(Day), 
colour=factor(Day)),size=4,show_guide=TRUE)+
  scale_shape_manual(values=c(21, 21))+
  scale_fill_manual(values=c("black","white"))+
  scale_colour_manual(values=c("black","black"))
gf2
tcek
  • 51
  • 4

1 Answers1

0

This link will help you: Plotting continuous and discrete series in ggplot with facet Just take care the using melt function.

Community
  • 1
  • 1
user3789396
  • 112
  • 2
  • 9
  • I am not sure whether this link helps. I see no example of combining plots one variable while faceting on another. Am I missing something? – tcek Jan 18 '15 at 14:41