My data, ret, includes 3 variables and 208 rows for each variable.
dim(ret)
[1] 208 3
I do the plot one by one for different variables.
hist(ret$AAPL,breaks
freq=F,
main="The probaility distribution of AAPL",
xlab="AAPL")
hist(ret$GOOGL,breaks
freq=F,
main="The probaility distribution of GOOGL",
xlab="GOOGL")
hist(ret$WMT,breaks
freq=F,
main="The probaility distribution of WMT",
xlab="WMT")
Now,I try to use sapply function to plot variables separately in one time.
sapply(ret, function(x) hist(x,breaks=100,
freq=F,
main="the probaility distribution of x",
xlab="x"))
However, "main="the probaility distribution of x"" and "xlab=x" do not work. I try to put the colnames in x.
In addition, I also try to put the line in the plot together with variables. The function I use is
lines(density(,main="",lty=1,lwd=1)
If I plot separately with variables, I do
hist(ret$AAPL,breaks
freq=F,
main="the probaility distribution of AAPL",
xlab="AAPL")
lines(density(ret$AAPL),main="AAPL",lty=1,lwd=1)
But how to use sapply function to do it together? Could someone please tell me how to solve the problems: using sapply function to plot the probability distribution with the line of probability density for different variables.



