[R] legend help
casperyc
casperyc at hotmail.co.uk
Fri Feb 5 00:24:55 CET 2010
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??????
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
--
View this message in context: http://n4.nabble.com/legend-help-tp1461992p1469559.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list