jhilbe at aol.com
2010-May-03 22:42 UTC
[R] Need help on having multiple distributions in one graph
R-listers: I have searched the help files and everything I have related to R graphics. I cannot find how to graph y against several distributions on a single graph. Here is code for creating 4 Poisson distributions with different mean values, although I would prefer having it in a loop: The top of the y axis for the first distribution, with count of 0, is .6, which is the highest point for any of the distributions. obs <- 1:20 y <- obs-1 m0 <- (exp(-.5) * .5^y)/factorial(y) m1 <- (exp(-1) * 1^y)/factorial(y) m3 <- (exp(-3) * 3^y)/factorial(y) m4 <- (exp(-5) * 5^y)/factorial(y) How do I plot the graph of each distribution on y, all on a single graph? I have spent so many hours on this, which is really quite simple in applications such as Stata. Thanks very much for the assistance: Joseph Hilbe hilbe at asu.edu or jhilbe at aol.com
Jorge Ivan Velez
2010-May-04 04:14 UTC
[R] Need help on having multiple distributions in one graph
Hi Joseph,
How about this?
matplot(cbind(m0, m1, m3, m4), type = 'l', lty = 1)
legend('topright', paste('m', c(0, 1, 3, 4), sep =
""), lty = 1, col = 1:4)
See ?matplot and ?legend for details.
HTH,
Jorge
On Mon, May 3, 2010 at 6:42 PM, <> wrote:
> R-listers:
>
> I have searched the help files and everything I have related to R graphics.
> I cannot find how to graph y against
> several distributions on a single graph. Here is code for creating 4
> Poisson distributions with different mean values, although I would prefer
> having it in a loop: The top of the y axis for the first distribution, with
> count of 0, is .6, which is the highest point for any of the
distributions.
>
> obs <- 1:20 y <- obs-1
> m0 <- (exp(-.5) * .5^y)/factorial(y)
> m1 <- (exp(-1) * 1^y)/factorial(y)
> m3 <- (exp(-3) * 3^y)/factorial(y)
> m4 <- (exp(-5) * 5^y)/factorial(y)
>
> How do I plot the graph of each distribution on y, all on a single graph? I
> have spent so many hours on this,
> which is really quite simple in applications such as Stata. Thanks very
> much for the assistance:
>
> Joseph Hilbe
> hilbe@asu.edu or jhilbe@aol.com
>
> ______________________________________________
> R-help@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]]
Reasonably Related Threads
- Heterogeneous negative binomial
- [LLVMdev] Generate code for ARM Cortex m0, m3, and m4.
- Wilcox test and data collection
- multcomp::glht() doesn't work for an incomplete factorial using aov()?
- [LLVMdev] Newbee question: LLVM backend regression tests for thumb1 targets on simulator possible?