4
How to play the chart below using the ggplot2
? I don’t know how to add the various charts into one layer
single!
bs<-function(t,mu,phi){
fdp=((exp(phi/2)*sqrt(phi+1))/(4*sqrt(pi*mu)*t^(3/2)))*(t+((phi*mu)/(phi+1)))*
exp((-phi/4)*((t*(phi+1)/(phi*mu))+(phi*mu/(t*(phi+1)))))
return(fdp)
}
t=seq(0.5,6,by=0.01)
plot(t,bs(t,1,100),main=expression(T%~%BS(mu,phi==100)),ylab='Densidade',type='l')
lines(t,bs(t,1.5,100),col=2,lty=2, lwd=1)
lines(t,bs(t,2,100),col=3,lty=3, lwd=2)
lines(t,bs(t,2.5,100),col=4,lty=4, lwd=3)
lines(t,bs(t,3,100),col=5,lty=5, lwd=3)
lines(t,bs(t,3.5,100),col=6,lty=6, lwd=2)
legend(4.3,2.7, c(expression(mu==1),
expression(mu==1.5),
expression(mu==2),
expression(mu==2.5),
expression(mu==3),
expression(mu==3.5)),
col=1:6,
lwd=c(1,1,2,3,3,2),
lty=c(1,2,3,4,5,6))
I don’t know if it helps, but I tried to create a dataframe
as below:
library(ggplot2)
df <- data.frame(x=t,y=bs(t,1,10))
ggplot(data = df, aes(x, y)) + scale_x_log10() + geom_point() + geom_line()
Thank you @Marcusnunes
– fsbmat