Hello Ista,

On May 1, 2010, at 8:37 PM, Ista Zahn wrote:
> Hi Giovanni,
> A reproducible example would help. Also, since I think this will be
> tricky, it might be a good idea to post it to the ggplot2 mailing list
> (you can register at http://had.co.nz/ggplot2/ ).
> 
> Best,
> Ista

First, thank you so much for showing me the way ... the plots generated from 
ggplot2 are super nice! 

Please find below a self contained reproducible example nearly exactly as the 
ones I need to produce.

Thanks in advance,
Best regards,
Giovanni

rm(list=ls())                                              # clear workspace
library(ggplot2)                                           # use ggplot2 library

methodlabels <- c("Classic", "Own Bootstrap",              # prepare plot 
labels 
        "R Bootstrap")               
errortypelabels <- c("'Normal'", "'Student-t'",            # prepare plot labels
        "'Exponential'")
betalabels <- c("'Beta_1'", "'Beta_2'", "'Beta_3'")        # prepare plot labels
betas <- c(1, -2, 3)                                       # my real parameters
set.seed(11)
S <- 100
B <- 50
P <- length(betas)
classiccis <- owncis <- rbootcis <- array(data=0,dim=c(S,1,3,2))
for (p in 1:P) {
        classiccis[,1,p,1] <- rnorm(100,mean=betas[p]-1.0,sd=0.5)
        classiccis[,1,p,2] <- rnorm(100,mean=betas[p]+1.0,sd=0.5)
        owncis[,1,p,1] <- rnorm(100,mean=betas[p]-1.0,sd=0.5)
        owncis[,1,p,2] <- rnorm(100,mean=betas[p]+1.0,sd=0.5)
        rbootcis[,1,p,1] <- rnorm(100,mean=betas[p]-1.0,sd=0.5)
        rbootcis[,1,p,2] <- rnorm(100,mean=betas[p]+1.0,sd=0.5)
}

##
## Function that generates the ggplot of the CI for a given parameter
## and error type
##
ciplot <- function() {
        x <- 1:S
        y <- rep(betas[p],S)
        data <- data.frame(x,y)
        classiclimits <- aes(x=x[1:100],ymax = classiccis[1:100,e,p,1], 
                ymin=classiccis[1:100,e,p,2]) 
        ownlimits <- aes(x=x[1:100]+0.4,ymax = owncis[1:100,e,p,1], 
                ymin=owncis[1:100,e,p,2]) 
        rbootlimits <- aes(x=x[1:100]+0.8,ymax = rbootcis[1:100,e,p,1], 
                ymin=rbootcis[1:100,e,p,2]) 
        g1 <- ggplot(data, aes(x=x, y=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(betalabels[p]) + opts(title = paste("CI for",
             errortypelabels[e],"error, ",betalabels[p],",",S/5,
             "simulations and ",B,"bootstrapped samples"))
}

##
## Execute one by one ... note they have to be global 
## otherwise seems that ggplot won't find them.
## 
## p - means parameter index
## e - means error type index
## 
p=1;e=1;ciplot()
p=1;e=2;ciplot()
p=1;e=3;ciplot()
p=2;e=1;ciplot()
p=2;e=2;ciplot()
p=2;e=3;ciplot()
p=3;e=1;ciplot()
p=3;e=2;ciplot()
p=3;e=3;ciplot() 
        [[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