[R] legend help
Uwe Ligges
ligges at statistik.tu-dortmund.de
Fri Feb 5 10:54:41 CET 2010
On 05.02.2010 00:24, casperyc wrote:
>
> Yes, that is pretty much what I want.
>
> However, there was slightly a mistake.
>
> we need to use ''rate=rate[i]"" and "shape=shape[i]" because the default is
>
> ==============================================
> dgamma(x, shape, rate = 1, scale = 1/rate, log = FALSE)
> ==============================================
>
> if we use
>
> ==============================================
> dgamma(x, rate[i], shape[i])
> ==============================================
>
> it actually takes shape=rate[i], shape[i]=rate )
>
>
>
> Now I have another problem,
> I printed it out, the colorful does not seem to pretty, so i tried to use
> STRAIGHT lines for all of them
> ==============================================
> x<- 5 * ppoints(100)
> rate<- rep(c(2, 4), each = 3)
> shape<- rep(c(1, 3, 5), 2)
> gamden<- matrix(NA, nrow = 6, ncol = 100)
> for(i in 1:6) gamden[i, ]<- dgamma(x, rate=rate[i], shape=shape[i])
> matplot(x, t(gamden), type = 'l', col = 1:6, ylab = 'density')
> ==============================================
>
> this does not plot with straight line.
> i am guessing it is not controlled by lty??????
It is, hence
matplot(x, t(gamden), type = 'l', col = 1:6, ylab = 'density', lty=1)
does the trick.
Uwe Ligges
>
> now i have gone back and used this to produce the graph and sorted out.
> ==============================================
> plot(sin,xlim=c(0,4),ylim=c(0,3),type='n',ylab="density",las=1)
> i=1
> for(rate in c(2,4) ){
> for(shape in c(1,3,5) ){
> curve(dgamma(x,rate=rate,shape=shape),col=i,lwd=2,add=T)
> i=i+1
> }
> }
>
> rate<- rep(c(2, 4), each = 3)
> shape<- rep(c(1, 3, 5), 2)
>
> parText<- function(names, pars) {
> p1<- paste("* '= ", pars[-length(pars)], ", '*", sep = "")
> p2<- paste("* '= ", pars[length(pars)], "'")
> p<- c(p1, p2)
> txt<- paste(names, p, collapse = "")
> parse(text = txt)
> }
>
> names<- c('lambda', 'theta')
> vals<- cbind(rate, shape)
>
> legnames<- c(parText(names, vals[1, ]), parText(names, vals[2, ]),
> parText(names, vals[3, ]), parText(names, vals[4, ]),
> parText(names, vals[5, ]), parText(names, vals[6, ]))
>
> legend(locator(1), legend = legnames, lwd=rep(c(2),6), col = 1:6)
> ==============================================
>
>
> [[elided Hotmail spam]]
>
> Thanks!
>
> casper
More information about the R-help
mailing list