[R] legend

From: Thomas Steiner <e9826064_at_student.tuwien.ac.at>
Date: Wed 22 Jun 2005 - 21:44:09 EST


I color some area grey with polygon() (with a red border) and then I want to have the dashed red border in the legend as well. How do I manage it?

And I want to mix (latex) expressions with text in my legend.

Just execute my lines below and you know want I mean. Or pass by at http://de.wikipedia.org/wiki/Bild:GBM.png to see the picture online.

Thomas

bm <- function(n=500, from=0, to=1) {

  x=seq(from=from,to=to,length=n)
  BM<-c(0,cumsum(rnorm(n-1,mean=0,sd=sqrt(to/n))))
  cbind(x,BM)

}

gbm <- function(bm,S0=1,sigma=0.1,mu=1) {   gbm=S0
  for (t in 2:length(bm[,1])) {
    gbm[t]=S0*exp((mu-sigma^2/2)*bm[t,1]+sigma*bm[t,2])   }
  cbind(bm[,1],gbm)
}

set.seed(9826064)
cs=c("dark green", "steelblue", "red", "yellow")

#png(filename = "GBM.png", width=1600, height=1200, pointsize = 12) par(bg="lightgrey")
x=seq(from=0,to=1,length=500)
plot(x=x, y=exp(0.7*x), type="n", xlab="Zeit", ylab="", ylim=c(1,3.5)) polygon(x=c(x,rev(x)),
y=c(exp(0.7*x)+0.4*sqrt(x),rev(exp(0.7*x)-0.4*sqrt(x))), col="grey", border=cs[3], lty="dashed")

lines(x=x,y=exp(0.7*x), type="l", lwd=3, col=cs[1])
lines(gbm(bm(),S0=1,mu=0.7,sigma=0.4), lwd=3, col=cs[2])
lines(gbm(bm(),S0=1,mu=0.7,sigma=0.2), lwd=3, col=cs[3])
lines(gbm(bm(),S0=1,mu=0.7,sigma=0.1), lwd=3, col=cs[4])
title(main="Geometrische Brownsche Bewegung",cex.main=2.5)
legend(x=0,y=3.5,legend=c("exp(0.7x)","mu=0.7, sigma=0.4","mu=0.7, sigma=0.2","mu=0.7, sigma=0.1","Standardabweichung für sigma=0.2"),lwd=c(4,4,4,4,12),col=c(cs,"grey"),bg="transparent",cex=1.15) #dev.off()

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Jun 22 21:51:22 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:56 EST