How to plot two aggregate frequencies

I have data that looks like this:

#val  Freq1 Freq2
0.000 178 202
0.001 4611 5300
0.002 99 112
0.003 26 30
0.004 17 20
0.005 15 20
0.006 11 14
0.007 11 13
0.008 13 13
...many more lines..

Full details can be found here: http://dpaste.com/173536/plain/

What I intend to do is to have a cumulative graph with "val" as the x axis with "Freq1" and "Freq2" as the y axis, group together in 1 graph.

I have this code. But he creates two graphs instead of 1.

dat <- read.table("stat.txt",header=F);
val<-dat$V1
freq1<-dat$V2
freq2<-dat$V3

valf1<-rep(val,freq1)
valf2<-rep(val,freq2)

valfreq1table<- table(valf1)
valfreq2table<- table(valf2)
cumfreq1=c(0,cumsum(valfreq1table))
cumfreq2=c(0,cumsum(valfreq2table))

plot(cumfreq1, ylab="CumFreq",xlab="Loglik Ratio")
lines(cumfreq1)
plot(cumfreq2, ylab="CumFreq",xlab="Loglik Ratio")
lines(cumfreq2)

How to approach this?

+1
source share
3 answers
data <- read.table("http://dpaste.com/173536/plain/", header = FALSE)

sample1 <- unlist(apply(as.matrix(data),1,function(x) rep(x[1],x[2])))
sample2 <- unlist(apply(as.matrix(data),1,function(x) rep(x[1],x[3])))

plot(ecdf(sample1), verticals=TRUE, do.p=FALSE,
main="ECDF plot for both samples", xlab="Scores", 
ylab="Cumulative Percent",lty="dashed")

lines(ecdf(sample2), verticals=TRUE, do.p=FALSE,
col.h="red", col.v="red",lty="dotted")

legend(100,.8,c("Sample 1","Sample 2"),
col=c("black","red"),lty=c("dashed","dotted"))
+6
source

ecdf() R ---, plot.stepfun(), - ecdf() Hmisc . help(Ecdf), , ecdfs :

 # Example showing how to draw multiple ECDFs from paired data
 pre.test <- rnorm(100,50,10)
 post.test <- rnorm(100,55,10)
 x <- c(pre.test, post.test)
 g <- c(rep('Pre',length(pre.test)),rep('Post',length(post.test)))
 Ecdf(x, group=g, xlab='Test Results', label.curves=list(keys=1:2))
+3

Just for the record, here's how you get multiple lines in the same storyline “manually”:

plot(cumfreq1, ylab="CumFreq",xlab="Loglik Ratio", type="l") 
          # or type="b" for lines and points
lines(cumfreq2, col="red") 
+1
source

Source: https://habr.com/ru/post/1737650/


All Articles