Skip to content

plot probability density function (pdf)

9 messages · jdospina, pigpigmeow, R. Michael Weylandt +1 more

#
I have 2 series of variables, I want to plot the probability density function
of these 2 variabels (i.e. two curves in one graph), I just want to compare
these two variable distribution.
what should I do?
can I use ggplot2 package?

--
View this message in context: http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3897055.html
Sent from the R help mailing list archive at Nabble.com.
#
x=rnorm(100,1,0.8) # A series.
y=rnorm(100,0,0.5) # Another series with different mean and variance.

plot(density(x),ylim=c(0,1))
lines(density(y),col="red")

Remember that density() is a nonparametric estimator. You should properly
choose the bandwith.

--
View this message in context: http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3897747.html
Sent from the R help mailing list archive at Nabble.com.
#
i want to plot probability density function,predictvalue has missing value
and observevalue has not missing value, I tried ..

attach(test) #test is the name of the data file
names(test)

plot(density(predictvalue,na.rm=TRUE))
lines(density(observevalue))

is it correct?


--
View this message in context: http://r.789695.n4.nabble.com/plot-probability-density-function-pdf-tp3897055p3898605.html
Sent from the R help mailing list archive at Nabble.com.
#
Assuming you mean you want them on the same device:

layout(1:2)
plot(density(a))
lines(density(d),col=2)
plot(density(b))
lines(density(e),col=2)

Getting your data into R is more of a challenge, but if you want my
unsolicited advice, you can do far worse than saving as CSV and using
read.csv()

Michael
On Wed, Oct 12, 2011 at 10:31 AM, pigpigmeow <glorykwok at hotmail.com> wrote: