[R] problems with postscript device

kjetil halvorsen kjetilh at umsanet.edu.bo
Tue Oct 23 15:48:35 CEST 2001


Hola!

I am producing postscript output from R (windows 98), both using firts
the windows devicd and then " copy to postscript", or using the
postscript device directly.  The problem shows up equally both ways.
The function producing the plot is given below. The only difference I
can see with this function and other I have producing plots, is that
this uses split.screen(). I include the plot in latex, and the result is
1)
a very small, unreadabkle plot and 2) the plot is rotated on head!

I had no problems with other functions:

 boot.stat <-
function (x, B = 1000, norm = FALSE) 
{
    xname <- deparse(substitute(x))
    means <- meds <- numeric(B)
    for (i in 1:B) {
        s <- sample(x, replace = TRUE)
        means[i] <- mean(s)
        meds[i] <- median(s)
    }
    CImedian <- quantile(meds, c(0.025, 0.5, 0.975))
    CImean <- quantile(means, c(0.025, 0.5, 0.975))
    hmean <- hist(means, freq = FALSE, plot = FALSE)
    hmeds <- hist(meds, freq = FALSE, plot = FALSE)
    split.screen(c(1, 2))
    xlims <- range(c(hmean$breaks, hmeds$breaks))
    ymax <- max(c(hmean$density, hmeds$density))
    screen(1)
    plot(hmean, freq = FALSE, col = "red", xlim = xlims, ylim = c(0, 
        ymax), xlab = paste("Sampling dist. of mean of ", xname), 
        main = "")
    bringToTop()
    if (norm) {
        n <- length(x)
        mu <- mean(x)
        sd <- sqrt(var(x)/n)
        ps <- seq(xlims[1], xlims[2], len = 100)
        lines(ps, dnorm(ps, mu, sd), col = "darkgreen")
    }
    lines(CImean, rep(ymax/2, 3))
    points(CImean[2], ymax/2, cex = 2, col = "black")
    screen(2)
    plot(hmeds, freq = FALSE, col = "lightblue", xlim = xlims, 
        ylim = c(0, ymax), xlab = paste("Sampling dist. of median of ", 
            xname), main = "")
    if (norm) {
        n <- length(x)
        p <- 1/2
        mu <- median(x)
        d <- density(x, n = 1, from = mu, to = mu)$y
        sd <- sqrt(p * (1 - p)/n)/d
        ps <- seq(xlims[1], xlims[2], len = 100)
        lines(ps, dnorm(ps, mu, sd), col = "darkgreen")
    }
    lines(CImedian, rep(ymax/2, 3))
    points(CImedian[2], ymax/2, cex = 2, col = "black")
    names(B) <- "Number of bootstrap replicactions"
    invisible(list(CImean = CImean, CImedian = CImedian, B, means =
means, 
        meds = meds))
}


call with for example:

boot.stat(rnorm(100))

Kjetil Halvorsen.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list