How to overlap two density plots?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to overlap two density plots?

Emre Unal
Hi,

How can I overlap two density plots?


A <- c(8,10,10,11,11,11,12,12,12,12,11,11,11,10,10,7)
B <- c(11,13,13,14,14,14,15,15,15,15,14,14,14,13,13,10)

plot(density(A))
plot(density(B))

Regards,
Emre


P.S. There's a overlap.density function in package DAAG
        Is there another way to do this?




--
---
Emre ÜNAL
http://www.geocities.com/dusemre

        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to overlap two density plots?

David Winsemius
"Emre Unal" <[hidden email]> wrote in
news:[hidden email]:

> Hi,
>
> How can I overlap two density plots?
>
>
> A <- c(8,10,10,11,11,11,12,12,12,12,11,11,11,10,10,7)
> B <- c(11,13,13,14,14,14,15,15,15,15,14,14,14,13,13,10)
>
> plot(density(A))

Instead:
lines(density(B))

--
David Winsemius



> plot(density(B))
>
> Regards,
> Emre
>
>
> P.S. There's a overlap.density function in package DAAG
>         Is there another way to do this?
>
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to overlap two density plots?

Philipp Pagel-5
In reply to this post by Emre Unal
On Fri, Apr 25, 2008 at 10:57:27AM +0300, Emre Unal wrote:
>
> How can I overlap two density plots?
>
> A <- c(8,10,10,11,11,11,12,12,12,12,11,11,11,10,10,7)
> B <- c(11,13,13,14,14,14,15,15,15,15,14,14,14,13,13,10)
 
plot(density(A))
lines(density(B))

cu
        Philipp

--
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
 
 and
 
Institut für Bioinformatik und Systembiologie / MIPS
Helmholtz Zentrum München -
Deutsches Forschungszentrum für Gesundheit und Umwelt
Ingolstädter Landstrasse 1
85764 Neuherberg, Germany
http://mips.gsf.de/staff/pagel

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to overlap two density plots?

Jared O'Connell-2
In reply to this post by Emre Unal
Very näively, you could do something like this,

plot(density(A))
lines(density(B),col=2)

, and tinker your xlim and ylim as suitable.  The Cairo library gives
a pretty example,

data(iris)
attach(iris)
plot(Petal.Length, rep(-0.03,length(Species)), xlim=c(1,7),
          ylim=c(0,1.7), xlab="Petal.Length", ylab="Density",
          pch=21, cex=1.5, col="#00000001", main = "Iris (yet again)",
          bg=c("#ff000020","#00ff0020","#0000ff20")[unclass(Species)])
for (i in 1:3) polygon(density(Petal.Length[unclass(Species)==i],bw=0.2),col=c("#ff000040","#00ff0040","#0000ff40")[i])

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: How to overlap two density plots?

Jared O'Connell-2
My apologies, the previous replies did not show up for me.

On Sat, Apr 26, 2008 at 1:49 PM, Jared O'Connell
<[hidden email]> wrote:

> Very näively, you could do something like this,
>
>  plot(density(A))
>  lines(density(B),col=2)
>
>  , and tinker your xlim and ylim as suitable.  The Cairo library gives
>  a pretty example,
>
>  data(iris)
>  attach(iris)
>  plot(Petal.Length, rep(-0.03,length(Species)), xlim=c(1,7),
>           ylim=c(0,1.7), xlab="Petal.Length", ylab="Density",
>           pch=21, cex=1.5, col="#00000001", main = "Iris (yet again)",
>           bg=c("#ff000020","#00ff0020","#0000ff20")[unclass(Species)])
>  for (i in 1:3) polygon(density(Petal.Length[unclass(Species)==i],bw=0.2),col=c("#ff000040","#00ff0040","#0000ff40")[i])
>

______________________________________________
[hidden email] 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.