[R] Need a little help setting the upper median using "layout"...

Jason Rupert jasonkrupert at yahoo.com
Tue Mar 17 20:38:34 CET 2009


The code I'm using is shown below.  

I would like to have a larger median at the top of the plot so that I can show the entirity of "title_text". 

Several times I tried messing with "par(mar", but that seemed to make matters worse.  

By any chance can anyone provide any insight as to the best way to increase the top/upper/northern margin, so the entirity of the title is visible?  

Thank you again for any help that can be provided.  


x <- rnorm(10000)
# op <- par(mar=c(2,2,2,2), oma=c(0,0,0,0)+.8)

op <- par(mar=c(2, 2, 2, 2), oma=c(0,0,0,0)+.8)
layout(matrix(c(2, 2, 2, 3, 3, 3, 
                1, 1, 1, 3, 3, 3, 
                1, 1, 1, 3, 3, 3, 
                1, 1, 1, 3, 3, 3), 4, 6, byrow=TRUE))
#  2  2   2  3  3  3
#  1  1   1  3  3  3
#  1  1   1  3  3  3
#  1  1   1  3  3  3

# 1st Plot
hist(x, probability=TRUE, breaks=20, col="light blue", main="", xlab="Density" )
rug(jitter(x, 5))
points(density(x), type='l', lwd=3, col='red')
box()

# 2nd Plot
#par(mar=c(0,0,0,0), oma=c(0,0,0,0)+.2)
#boxplot( x, horizontal=T, col="white", xaxt='n', yaxt='n')
boxplot(x, horizontal = TRUE, col = "pink", lwd=1, xaxt='n', yaxt='n')  
box(col="white")

#par(op)
# 3rd Plot
#par(mar=c(1,1,1,1), oma=c(0,0,0,0)+.8)
qqnorm(x, , main="")
qqline(x, col="red", lwd=3)

kurtosis_val <-(sum((x-mean(x))^4 ))/(var(x)*var(x))/length(x)-3

skewness<-function(x)
{
    m_skew=mean(x)
    me_skew=median(x)
    s_skew=sqrt(var(x))
    sk_skew=(m_skew-me_skew)/s_skew
    return(sk_skew)
}

title_text<-c("Title Text", "\nMean = ", format(mean(x), digits=4, scientific=F), " Standard Deviation = ", format(sd(x), digits=4, scientific=F),"\n Skewness = ", format(skewness(x), digits=4, scientific=F), "Kurtosis =", format(kurtosis_val, digits=4, scientific=F))

mtext(title_text, NORTH<-3, line=0, adj=0.5, cex=1.2, col="red", outer=TRUE)




More information about the R-help mailing list