2

I have data from three doses of a treatment, with three replicates per each dose:

df <- data.frame(dose=c(rep(1,300),rep(3,300),rep(5,300)),
replicate=rep(c(rep("X1",100),rep("X2",100),rep("X3",100)),3),
value=c(rnorm(300,1,1),rnorm(300,3,1),rnorm(300,5,1)),stringsAsFactors=F)

df$dose <- factor(df$dose,levels=c(1,3,5))

I want to display it using an cdf plot. Per each replicate I can simply plot the cdfs of the three doses with:

for(r in c("X1","X2","X3")){
 ggplot(dplyr::filter(df,replicate==r),aes(x=value,color=dose))+
   stat_ecdf(geom="step")+ 
   theme_bw()+
   theme(panel.border=element_blank(),strip.background=element_blank())
}

But I'm looking for a way to display all replicates of each dose in one figure, with standard error shading around the mean value, similar to plots achieved with stat_smooth.

Can this be achieved?

Also, either for this or for a single replicate's plot:

r <- "X1"
ggplot(dplyr::filter(df,replicate==r),aes(x=value,color=dose))+
  stat_ecdf(geom="step")+ 
  theme_bw()+
  theme(panel.border=element_blank(),strip.background=element_blank())

enter image description here

Is there a way to compute the area under each of the ecdfs?

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
dan
  • 6,048
  • 10
  • 57
  • 125
  • you can get the area under curve; read this [thread](https://stackoverflow.com/questions/4954507/calculate-the-area-under-a-curve) – M-- Jun 27 '17 at 17:37

1 Answers1

1

You can use interaction to group the data (in ggplot) based on two columns;

ggplot(df,aes(x=value,color = interaction(replicate, dose)
            , group=interaction(replicate, dose)))+
stat_ecdf(geom="step")+ 
theme_bw()+
theme(panel.border=element_blank(),strip.background=element_blank())

This would be your plot; enter image description here

As it is a little bit vague:

if you want to have lines for dose then you can get rid of replicate in the interaction or use dose instead of replicate in your ddplyr::filter;

  ggplot(dplyr::filter(df,dose==1),aes(x=value,color = interaction(replicate, dose)
            , group=interaction(replicate, dose)))+
stat_ecdf(geom="step")+ 
theme_bw()+
theme(panel.border=element_blank(),strip.background=element_blank())

And you'd get:

enter image description here

M--
  • 25,431
  • 8
  • 61
  • 93