如何将多个密度曲线叠加到R中的一个图中

nev*_*int 6 statistics plot r

我有一个看起来像这样的数据.

我打算在一个图中创建多个密度曲线,其中每个曲线对应于唯一ID.

我尝试使用"sm"包,使用此代码,但没有成功.

library(sm)
dat <- read.table("mydat.txt");
plotfn <- ("~/Desktop/flowgram_superimposed.pdf");
pdf(plotfn);

sm.density.compare(dat$V1,dat$V2, xlab = "Flow Signal")
colfill <- c(2:10);
legend(locator(1), levels(dat$V2), fill=colfill)

dev.off();
Run Code Online (Sandbox Code Playgroud)

请告知正确的方法是什么,或者是否有其他方法可以做到这一点?

我想在最后得到这种情节. 图http://img524.imageshack.us/img524/2736/testl.png

Edu*_*oni 11

尝试使用ggplot2:

dnow <- read.table("http://dpaste.com/88561/plain/")
library(ggplot2)
qplot(V1, colour=factor(V2), data=dnow, geom="density")
Run Code Online (Sandbox Code Playgroud)

  • @Manoel`qplot(mtcars $ drat,color = factor(mtcars $ cyl),data = mtcars,geom ="density")`应该给你一个功能性的例子. (3认同)