Hello,

I have just ordered the "ggplot2: Elegant Graphics for Data Analysis (Use R)" 
but while it arrives :) can anyone please show me how to setup and add a simple 
legend to a ggplot?

This is my use case, I need a legend showing CI "Classic", "Own bootstrap", "R 
bootstrap":

library(ggplot2)

e <- 1
p <- 1
x <- 1:S
y <- rep(betas[p],S)
data <- data.frame(x,y)
classiclimits <- aes(x=x,ymax = classic[,e,p,1], ymin=classic[,e,p,2]) 
ownlimits <- aes(x=x+0.4,ymax = own[,e,p,1], ymin=own[,e,p,2]) 
rbootlimits <- aes(x=x+0.8,ymax = rboot[,e,p,1], ymin=rboot[,e,p,2]) 
g1 <- ggplot(data, aes(x, y))
g1 + geom_errorbar(classiclimits, colour = "red")  + geom_errorbar(ownlimits, 
colour = "green") + geom_errorbar(rbootlimits, colour = "blue") + 
geom_hline(yintercept = betas[p]) + xlab("Simulation") + ylab("beta_1") + 
opts(title = "CI for error 'normal' and beta_1") + opts(legend.position = 
c(10,2.5))

Many thanks in advance,
Best regards,
Giovanni
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to