[R] Howto Superimpose Multiple Density Curves Into One Plot

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Wed Sep 2 13:30:35 CEST 2009


Have a look at the ggplot2 package.

library(ggplot2)
dat <- read.table("mydat.txt") 
ggplot(dat, aes(x = V1, colour = factor(V2))) + geom_density()
#or a few alternatives
ggplot(dat, aes(x = V1, fill = factor(V2))) + geom_density(alpha = 0.2)
ggplot(dat, aes(x = V1)) + geom_density() + facet_wrap(~V2)

HTH,

Thierry


------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Gundala Viswanath
Verzonden: woensdag 2 september 2009 12:10
Aan: r-help at stat.math.ethz.ch
Onderwerp: [R] Howto Superimpose Multiple Density Curves Into One Plot

I have a data that looks like this:
http://dpaste.com/88561/plain/

And I intend to create multiple density curve into one plot, where each
curve correspond to the unique ID.

I tried to use "sm" package, with this code, but without success.

__BEGIN__
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();
__END__

Please advice what's the right way to do it or if  there is alternative
way to do it?
I am trying to get this kind of figure:
http://img524.imageshack.us/img524/2736/testl.png


- G.V.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.




More information about the R-help mailing list