R package to automatically produce combination plot?
Hi
Jason Rupert wrote:
Paul, This is great! Like you said it is really close. I made a few changes and for some reason the y-axis label magically came back. I tried to remove it but it wouldn't stay away.
You have removed the 'axes=FALSE' from the qqplot() call. Also, you have removed some of the explicit setting of 'ylim', 'xlim', and 'breaks', which means that your plots are using subtly different coordinate systems.
Also, for some reason the title exceeds the margins of the layout. I am going ot mess around with this a bit more, but any suggestions for fixing this are also greatly appreciated.
The title fits (just) for me. If you need more room, bump up the value in the par(oma) setting. You could also reduce the 'line' value in your mtext() call. Paul
Thank you again.
y<-rnorm(1000)
yrange <- range(y)
#histdata <- hist(y, breaks=breaks, plot=FALSE) histdata <- hist(y,
plot=FALSE) densitydata <- density(y)
par(oma=rep(3, 4), mar=rep(0, 4))
layout(matrix(1:3, ncol=3), widths=c(.2, .1, 1), respect=TRUE)
barplot(histdata$density, horiz=TRUE, space=0, xlim=c(0,
max(histdata$density)*1.1), axes=FALSE) par(new=TRUE)
plot(densitydata$y, densitydata$x, xlim=c(0,
max(histdata$density)*1.1), ylim=yrange, type="l", ann=FALSE,
axes=FALSE) axis(2) box()
boxplot(y, ylim=yrange, axes=FALSE) box()
# qqnorm(y, axes=FALSE, ylim=yrange, xlim=yrange, main="") qqnorm(y,
, main="") axis(2, labels = FALSE) #abline(0, 1) qqline(y, col="red",
lwd=3) box()
kurtosis_val <-(sum((y - mean(y))^4 ))/(var(y)*var(y))/length(y)-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<-paste("Title Text", "\n Mean = ", format(mean(y),
digits=4, scientific=F), " Standard Deviation = ", format(sd(y),
digits=4, scientific=F), "\n Skewness = ", format(skewness(y),
digits=4, scientific=F), "Kurtosis =", format(kurtosis_val, digits=4,
scientific=F), sep="")
mtext(title_text, NORTH<-3, line=0, adj=0.5, cex=1.2, col="red",
outer=TRUE)
--- On Tue, 3/17/09, Paul Murrell <p.murrell at auckland.ac.nz> wrote:
From: Paul Murrell <p.murrell at auckland.ac.nz> Subject: Re: [R] R package to automatically produce combination plot? To: jasonkrupert at yahoo.com Cc: R-help at r-project.org Date: Tuesday, March 17, 2009, 2:51 PM Hi Jason Rupert wrote:
I guess no reply means there is not an existing
package to produce
the plot? I will post the results of my script to hopefully help
others who are
trying to formulate the same plot. Thanks again.
I don't know of an existing function that does that particular arrangement of plots, but here's a start ... breaks <- seq(-3.5, 3.5, by=.5) yrange <- range(breaks) histdata <- hist(y, breaks=breaks, plot=FALSE) densitydata <- density(y) par(oma=rep(3, 4), mar=rep(0, 4)) layout(matrix(1:3, ncol=3), widths=c(.2, .1, 1), respect=TRUE) barplot(histdata$density, horiz=TRUE, space=0, xlim=c(0, max(histdata$density)*1.1), axes=FALSE) par(new=TRUE) plot(densitydata$y, densitydata$x, xlim=c(0, max(histdata$density)*1.1), ylim=yrange, type="l", ann=FALSE, axes=FALSE) axis(2) box() boxplot(y, ylim=yrange, axes=FALSE) box() qqnorm(y, axes=FALSE, ylim=yrange, xlim=yrange, main="") abline(0, 1) axis(1) box() ... the important bits are the call to layout() to get the plots at different sizes and the numerous efforts made to make sure that the coordinate systems of the various plots are coherent. Paul
--- On Mon, 3/16/09, Jason Rupert
<jasonkrupert at yahoo.com> wrote:
From: Jason Rupert <jasonkrupert at yahoo.com>
Subject: [R] R package
to automatically produce combination plot? To:
R-help at r-project.org
Date: Monday, March 16, 2009, 8:14 PM By any
chance is there an R
package that automatically produces the plot shown
at the following
link:
That is an R package to produce on plot that has
the following: (a)
a vertically oriented histogram, (b) associated
barplot, and (c)
quantile-quantile plot (Q-Q Plot). This is based on a class lecture from University
of Pennsylvania: stat.wharton.upenn.edu/~mcjon/stat-431/lecture-02.pdf
I am pretty confident I can put one together, but
just wanted to
check that there does not already exist an R
package to output such
a plot. Thanks again.
______________________________________________
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. ______________________________________________ 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. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/