s-news
[Top] [All Lists]

Summary: Overlaying Plots

To: s-news@lists.biostat.wustl.edu
Subject: Summary: Overlaying Plots
From: Brian Beckage <bb2@duke.edu>
Date: Wed, 06 Dec 2000 12:46:57 -0600
Thanks to all who responded! My original posting is at the bottom of this
message.   Matthew Austin and Stephen Smith both suggested using subplot
(see 311--314 of the Programmer's Guide).  Sean Keenan and Naomi Robbins
provided solutions using tsplot (and that also work with ts.plot).  Their
code is provided below.

Thanks again,
Brian


###### From Sean Keenan

#Make First Plot.
tsplot(Z$series1, Z$series2, xaxt = "n", ylim = c(0, 20), lty = c(3, 4),
cex = 
0.7)
 title(paste(cus), cex = 0.7)
 mtext("scale 1", side = 2, line = 2, cex = 0.6) #
#Overlay Second Plot.
 par(new = T)
 ts.plot(pred.ts, ylim = c(-3.6, 1), yaxt = "n", xlab = "Months")
 axis(side = 4)
 mtext("EW Score", side = 4, line = 2, cex = 0.6)

###### From Naomi Robbins

# Here is an example that either came from S-Plus help or from Cleveland's
examples:

sun.agg <- aggregate(sunspots, 1, "mean")
par(mar=rep(5, 4))
tsplot(rain.nyc2, ylab="rain in inches")
legend(1946, 65, c("rain", "sunspots"), lty=1:2)
par(new=T) # trick to add plot with different scale
tsplot(window(sun.agg, start(rain.nyc2), end(rain.nyc2)), axes=F, lty=2,
lwd=2)
axis(4)
mtext("mean number of sunspots", side=4, line=3)
title(main="New York Rainfall and Sunspot Activity")



###################### Original Posting
Hi,

        I would like to plot two time series on the same plot but with different
scales for each of the series, i.e. one scale on the left hand y-axis and
the other on the right hand y-axis.  Can this be done from the command window?

I'm using Splus 2000 R3.

Thanks for your help,
Brian


<Prev in Thread] Current Thread [Next in Thread>
  • Summary: Overlaying Plots, Brian Beckage <=