# Re: [R] Plot Mixtures of Synthetically Generated Gamma Distributions

From: Jorge Ivan Velez <jorgeivanvelez_at_gmail.com>
Date: Sun, 06 Jul 2008 23:42:34 -0400

Dear Gundala,

It's just a starting points and I'm sure completely sure it will be improved. Try this (for now):

set.seed(123)
x=c(

```rgamma(30,shape=.2,scale=14),
rgamma(30,shape=12,scale=10),
rgamma(30,shape=5,scale=6))

```

plot(density(x[1:30]),col=2,xlim=range(0,max(density(x)\$x)),type='l',main="Density for your vector")

```points(density(x[31:60]),col=1,type='l')
points(density(x[61:90]),col=4,type='l')
legend("topright",paste('Type',1:3,sep=""),col=c(2,1,4),lty=1)

```

Also, see ?density, ?points and ?plot for more information.

HTH, Jorge

On Sun, Jul 6, 2008 at 11:24 PM, Gundala Viswanath <gundalav_at_gmail.com> wrote:

> Hi,
>
> I have the following vector
> which is created from 3 distinct distribution (three components) of gamma:
>
>
> x=c(rgamma(30,shape=.2,scale=14),rgamma(30,shape=12,scale=10),rgamma(30,shape=5,scale=6))
>
> I want to plot the density curve of X, in a way that it shows
> a distinct 3 curves that represent each component.
>
> How can I do that?
>
> I tried this but doesn't work:
>
> lines(density(x))
>
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> 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.
>

[[alternative HTML version deleted]]

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. Received on Mon 07 Jul 2008 - 03:46:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 Jul 2008 - 04:31:50 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.