Mr Natural
2007-Jul-20  21:14 UTC
[R] ?R: Removing white space betwen multiple plots, traditional graphics
I would appreciate suggestions for removing the white spaces the graphs in a stack: par(mar=c(2,2,1,1), mfrow = c(6,1)) mydates<-dates(1:20,origin=c(month = 1, day = 1, year = 1986)) plot(rnorm(20,0.1,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") plot(rnorm(20,0.2,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") plot(rnorm(20,0.3,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") plot(rnorm(20,0.5,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") plot(rnorm(20,0.7,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") plot(rnorm(20,0.8,0.1)~mydates, type="b",xlab="",ylim=c(0,1) ) Thanx, Don -- View this message in context: http://www.nabble.com/-R%3A--Removing-white-space-betwen-multiple-plots%2C-traditional-graphics-tf4119626.html#a11716176 Sent from the R help mailing list archive at Nabble.com.
Achim Zeileis
2007-Jul-20  22:20 UTC
[R] ?R: Removing white space betwen multiple plots, traditional graphics
On Fri, 20 Jul 2007, Mr Natural wrote:> > I would appreciate suggestions for removing the white spaces the graphs in a > stack: > > par(mar=c(2,2,1,1), mfrow = c(6,1)) > mydates<-dates(1:20,origin=c(month = 1, day = 1, year = 1986)) > plot(rnorm(20,0.1,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.2,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.3,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.5,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.7,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.8,0.1)~mydates, type="b",xlab="",ylim=c(0,1) )Really, there is no need to do this all by hand. Please have a look at the "zoo" package (as recommended earlier this week). Then you can do x <- cbind(rnorm(20,0.1,0.1), rnorm(20,0.2,0.1), rnorm(20,0.3,0.1), rnorm(20,0.5,0.1), rnorm(20,0.7,0.1), rnorm(20,0.8,0.1)) z <- zoo(x, mydates) plot(z) plot(z, nc = 1, type = "b") and much more. Please consult vignette("zoo-quickref", package = "zoo") vignette("zoo", package = "zoo") as well as the "Date and Time Classes" article by Gabor Grothendieck and Thomas Petzoldt in R News 4(1), 29-32. (available from your favourite CRAN mirror). Z> Thanx, Don > -- > View this message in context: http://www.nabble.com/-R%3A--Removing-white-space-betwen-multiple-plots%2C-traditional-graphics-tf4119626.html#a11716176 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. > >
Stephen Tucker
2007-Jul-22  09:05 UTC
[R] ?R: Removing white space betwen multiple plots, traditional graphics
You could try par(mar=c(0,5,0,2), mfrow = c(6,1), oma=c(5,0,2,0)) ##...then, your plots...## --- Mr Natural <drstrong at ucdavis.edu> wrote:> > I would appreciate suggestions for removing the white spaces the graphs in > a > stack: > > par(mar=c(2,2,1,1), mfrow = c(6,1)) > mydates<-dates(1:20,origin=c(month = 1, day = 1, year = 1986)) > plot(rnorm(20,0.1,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.2,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.3,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.5,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.7,0.1)~mydates, type="b",xlab="",ylim=c(0,1),xaxt = "n") > plot(rnorm(20,0.8,0.1)~mydates, type="b",xlab="",ylim=c(0,1) ) > > Thanx, Don > -- > View this message in context: >http://www.nabble.com/-R%3A--Removing-white-space-betwen-multiple-plots%2C-traditional-graphics-tf4119626.html#a11716176> Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Mr Natural
2007-Jul-22  15:49 UTC
[R] ?R: Removing white space betwen multiple plots, traditional graphics
Dear List: Thank you for the several helpful comments on my original post of
this title.
Most to the point, 
1. that from z, who is a coauthor of zoo was very kind. I have spent a
morning learning zoo 
and find it a very cool package. With zoo, one can make very neat time
series graphs with
a minimum of code. I had great fun downloading and plotting financial data
from the web.
I still have two problems with zoo for my particular application as per the
original post of this title.
   First, my dates are slightly different for each series. Neither of the
two suggestions for dealing 
different-dates-for-different-series that I have found are appropriate
(na.approx(m), na.locf.(m)).
Is there a way that the NAs can be skipped by each plot, with lines plotted
between the dates that exist,
as in my original code below?
    Second, I have complex standard errors for each point, which are either
read in as a distinct column 
for each y value or calculated in R and plotted with code such as (for the
first two series):
plot(MP~dmp, type="b",xlab="",ylim=c(0,1),xaxt =
"n")
arrows(dmp,MP+semp,dmp,MP-semp,length=.02,angle=90,code=3)
plot(C~dc, type="b",xlab="",ylim=c(0,1),xaxt =
"n")
arrows(dc,C+sec,dc,C-sec,length=.02,angle=90,code=3)
   I cannot get zoo to do this. 
2. The second helpful comment is from Steven Tucker, and this solves my
problem completely
and elegantly. He suggests changing my parameter statements to:
par(mar=c(0,5,0,2), mfrow = c(6,1), oma=c(5,0,2,0))
Thank you Steven!
Warm regards, Don
ps. This forum is very valuable to the growth of R usage among those of us
who are not programmers.
Mr Natural wrote:> 
> I would appreciate suggestions for removing the white spaces the graphs in
> a stack:
> 
> par(mar=c(2,2,1,1), mfrow = c(6,1))
> mydates<-dates(1:20,origin=c(month = 1, day = 1, year = 1986))
> plot(rnorm(20,0.1,0.1)~mydates,
type="b",xlab="",ylim=c(0,1),xaxt = "n")
> plot(rnorm(20,0.2,0.1)~mydates,
type="b",xlab="",ylim=c(0,1),xaxt = "n")
> plot(rnorm(20,0.3,0.1)~mydates,
type="b",xlab="",ylim=c(0,1),xaxt = "n")
> plot(rnorm(20,0.5,0.1)~mydates,
type="b",xlab="",ylim=c(0,1),xaxt = "n")
> plot(rnorm(20,0.7,0.1)~mydates,
type="b",xlab="",ylim=c(0,1),xaxt = "n")
> plot(rnorm(20,0.8,0.1)~mydates,
type="b",xlab="",ylim=c(0,1) )
> 
> Thanx, Don
> 
-- 
View this message in context:
http://www.nabble.com/-R%3A--Removing-white-space-betwen-multiple-plots%2C-traditional-graphics-tf4119626.html#a11732080
Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2007-Jul-22  16:10 UTC
[R] ?R: Removing white space betwen multiple plots, traditional graphics
On 7/22/07, Mr Natural <drstrong at ucdavis.edu> wrote:> I still have two problems with zoo for my particular application as per the > original post of this title. > First, my dates are slightly different for each series. Neither of the > two suggestions for dealing > different-dates-for-different-series that I have found are appropriate > (na.approx(m), na.locf.(m)). > Is there a way that the NAs can be skipped by each plot, with lines plotted > between the dates that exist, > as in my original code below?But that is precisely what na.approx does. Here is an example: library(zoo) z <- as.zoo(ldeaths) z[c(4, 8, 17)] <- NA zz <- cbind(z, lag(z, -5)) plot(na.approx(zz), col = 1:2) # classic library(lattice) xyplot(na.approx(zz), col = 1:2) # lattice> Second, I have complex standard errors for each point, which are either > read in as a distinct column > for each y value or calculated in R and plotted with code such as (for the > first two series): > > plot(MP~dmp, type="b",xlab="",ylim=c(0,1),xaxt = "n") > arrows(dmp,MP+semp,dmp,MP-semp,length=.02,angle=90,code=3) > plot(C~dc, type="b",xlab="",ylim=c(0,1),xaxt = "n") > arrows(dc,C+sec,dc,C-sec,length=.02,angle=90,code=3) > I cannot get zoo to do this.Please provide the data.