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

jim holtman jholtman at gmail.com
Wed Mar 18 01:20:32 CET 2009


try something like this:

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(
               4, 4, 4, 4, 4, 4,
               2, 2, 2, 3, 3, 3,
               1, 1, 1, 3, 3, 3,
               1, 1, 1, 3, 3, 3,
               1, 1, 1, 3, 3, 3), 5, 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)
}

plot(0,0, axes=FALSE, type='n')

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))

text(0,0, paste(title_text, collapse=''), adj=c(.5,.5), cex=1.2, col="red")


On Tue, Mar 17, 2009 at 3:38 PM, Jason Rupert <jasonkrupert at yahoo.com> wrote:
>
> 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)
>
> ______________________________________________
> R-help at 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.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list