2017-06-09 4 views
2

とggplot2のstat_ecdfプロットを作成します。私は、各用量当たり3回反復して治療を3回投与からのデータを、持っている標準エラーシェーディング

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)) 

私はCDFプロットを使用して、それを表示したいです。 、

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()) 
} 

しかし、私は、平均値の周りの標準誤差シェーディングと、1つの図に各用量のすべての複製物を表示する方法を探しています:各パー私は単純に3回のCDFSをプロットすることができ複製stat_smoothで達成されたプロットと同様である。

これを達成できますか? 、このいずれかのために、または単一の複製のプロットについても

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

ecdfsの各下の面積を計算する方法はありますか?

+0

あなたは曲線下面積を得ることができます。この[スレッド](https://stackoverflow.com/questions/4954507/calculate-the-area-under-a-curve)を読んでください – Masoud

答えて

0

インタラクションを使用して、2つの列に基づいてデータをグループ化できます。

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()) 

これはプロットです。 enter image description here

それは少し漠然としたようにグループにしたい場合は、唯一の線量に基づいたデータは、その後、あなたは相互作用にreplicateを取り除くか、あなたのddplyr::filterdose代わりのreplicateを使用し得ることができます。

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()) 

そして、あなたが取得したい:

enter image description here

関連する問題