如何将两个累积频率图绘制在一起
我的数据如下所示:
#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..
完整数据可以在这里找到: http://dpaste.com/173536/plain/
我想做的是有一个累积图 以“val”作为 x 轴,以“Freq1”和“Freq1”作为 x 轴。 “频率2”为 y 轴,一起绘制在一张图中。
我有这个代码。但它创建了两个图而不是 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)
处理这个问题的正确方法是什么?
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 data can be found here:
http://dpaste.com/173536/plain/
What I intend to do is to have a cumulative graph
with "val" as x-axis with "Freq1" & "Freq2" as
y-axis, plot together in 1 graph.
I have this code. But it creates two plots 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)
What's the right way to approach this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试基本 R 中的
ecdf()
函数 --- 如果内存充足的话,它会使用plot.stepfun()
--- 或Ecdf()
> Frank Harrell 的 Hmisc 中的函数。以下是来自help(Ecdf)
的示例,它使用分组变量在一个图中显示两个 ecdf:Try the
ecdf()
function in base R --- which usesplot.stepfun()
if memory serves --- or theEcdf()
function in Hmisc by Frank Harrell. Here is an example fromhelp(Ecdf)
that uses a grouping variable to show two ecdfs in one plot:仅供记录,以下是如何“手动”在同一图中获得多条线:
Just for the record, here is how you get multiple lines in the same plot "by hand":