chrisr34000
2012-Jan-17 13:11 UTC
[R] Plotting probability density and cumulative distribution function
Hi! I want to plot the probability density function and the cumulative distribution function for the gamma, lognormal, exponential and Pareto distribution. I want to vary the parameters and and have a plot with 2-3 different parameters in the same figure. It should look like this (example weibull distribution): http://en.wikipedia.org/wiki/File:Weibull_PDF.svg library(Cairo) CairoFonts(regular="DejaVu Sans:style=Regular") CairoSVG("Weibull PDF.svg") par(mar=c(3, 3, 1, 1)) x <- seq(0, 2.5, length.out=1000) plot(x, dweibull(x, .5), type="l", col="blue", xlab="", ylab="", xlim=c(0, 2.5), ylim=c(0, 2.5), xaxs="i", yaxs="i") lines(x, dweibull(x, 1), type="l", col="red") lines(x, dweibull(x, 1.5), type="l", col="magenta") lines(x, dweibull(x, 5), type="l", col="green") legend("topright", legend=paste("\u03bb = 1, k =", c(.5, 1, 1.5, 5)), lwd=1, col=c("blue", "red", "magenta", "green")) dev.off() and http://en.wikipedia.org/wiki/File:Weibull_CDF.svg library(Cairo) CairoFonts(regular="DejaVu Sans:style=Regular") CairoSVG("Weibull CDF.svg") par(mar=c(3, 3, 1, 1)) x <- seq(0, 2.5, length.out=1000) plot(x, pweibull(x, .5), type="l", col="blue", xlab="", ylab="", xlim=c(0, 2.5), ylim=c(0, 1), xaxs="i", yaxs="i") lines(x, pweibull(x, 1), type="l", col="red") lines(x, pweibull(x, 1.5), type="l", col="magenta") lines(x, pweibull(x, 5), type="l", col="green") legend("bottomright", legend=paste("\u03bb = 1, k =", c(.5, 1, 1.5, 5)), lwd=1, col=c("blue", "red", "magenta", "green")) dev.off() How do I adapt the syntax to use it for the other distributions? -- View this message in context: http://r.789695.n4.nabble.com/Plotting-probability-density-and-cumulative-distribution-function-tp4303198p4303198.html Sent from the R help mailing list archive at Nabble.com.
R. Michael Weylandt <michael.weylandt@gmail.com>
2012-Jan-17 15:17 UTC
[R] Plotting probability density and cumulative distribution function
Perhaps I misunderstand you, but it sounds like all you need to do is change weibull to the name of another distribution Michael On Jan 17, 2012, at 8:11 AM, chrisr34000 <crisr at wolke7.net> wrote:> Hi! > > I want to plot the probability density function and the cumulative > distribution function for the gamma, lognormal, exponential and Pareto > distribution. I want to vary the parameters and and have a plot with 2-3 > different parameters in the same figure. It should look like this (example > weibull distribution): > > http://en.wikipedia.org/wiki/File:Weibull_PDF.svg > > library(Cairo) > CairoFonts(regular="DejaVu Sans:style=Regular") > CairoSVG("Weibull PDF.svg") > par(mar=c(3, 3, 1, 1)) > x <- seq(0, 2.5, length.out=1000) > plot(x, dweibull(x, .5), type="l", col="blue", xlab="", ylab="", xlim=c(0, > 2.5), ylim=c(0, 2.5), xaxs="i", yaxs="i") > lines(x, dweibull(x, 1), type="l", col="red") > lines(x, dweibull(x, 1.5), type="l", col="magenta") > lines(x, dweibull(x, 5), type="l", col="green") > legend("topright", legend=paste("\u03bb = 1, k =", c(.5, 1, 1.5, 5)), lwd=1, > col=c("blue", "red", "magenta", "green")) > dev.off() > > and > > http://en.wikipedia.org/wiki/File:Weibull_CDF.svg > > library(Cairo) > CairoFonts(regular="DejaVu Sans:style=Regular") > CairoSVG("Weibull CDF.svg") > par(mar=c(3, 3, 1, 1)) > x <- seq(0, 2.5, length.out=1000) > plot(x, pweibull(x, .5), type="l", col="blue", xlab="", ylab="", xlim=c(0, > 2.5), ylim=c(0, 1), xaxs="i", yaxs="i") > lines(x, pweibull(x, 1), type="l", col="red") > lines(x, pweibull(x, 1.5), type="l", col="magenta") > lines(x, pweibull(x, 5), type="l", col="green") > legend("bottomright", legend=paste("\u03bb = 1, k =", c(.5, 1, 1.5, 5)), > lwd=1, col=c("blue", "red", "magenta", "green")) > dev.off() > > How do I adapt the syntax to use it for the other distributions? > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Plotting-probability-density-and-cumulative-distribution-function-tp4303198p4303198.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.