Hi, I would like to know if anyone knows how to draw a plot with two Y-axises and one X-axis? When you have two sets of y values that do not have the same scale, but correspond to the same x value, I would like to plot them on one graph. Could you please help me? Thank you Soyoko
Hi, On Fri, 7 Nov 2003, umeno wrote:> I would like to know if anyone knows how to draw a plot with two Y-axises and > one X-axis? When you have two sets of y values that do not have the same > scale, but correspond to the same x value, I would like to plot them on one > graph.I think both "Modern Applied Statistics with S" (Venables and Ripley 2002) and "Introductory Statistics with R" (Dalgaard 2002) have some example. Basically one way to do this is to build the plot "piece by piece" (aka by first principle, or low-level plotting). For example, the axis() command can be useful: axis(1) # x-axis at the bottom axis(2) # y-axis on the left axis(4) # y-axis on the right -- Cheers, Kevin --------------------------------------------------------------- Ko-Kang Kevin Wang Master of Science (MSc) Student SLC Tutor and Lab Demonstrator Department of Statistics University of Auckland New Zealand Homepage: http://www.stat.auckland.ac.nz/~kwan022 Ph: 373-7599 x88475 (City) x88480 (Tamaki)
umeno wrote:> Hi, > > I would like to know if anyone knows how to draw a plot with two Y-axises and > one X-axis? When you have two sets of y values that do not have the same > scale, but correspond to the same x value, I would like to plot them on one > graph. > > Could you please help me?Please look into the help archives before asking! This question has been answered several times during the last years. Example for a short solution: plot(1:10) par("usr") # [1] 0.64 10.36 0.64 10.36 # Now resetting y-axis' usr coordinates: par(usr=c(par("usr")[1:2], 101, 105)) points(1:5, 105:101, col="red") axis(4) Uwe Ligges
On Fri, Nov 07, 2003 at 11:12:06AM -0600, umeno wrote:> I would like to know if anyone knows how to draw a plot with two Y-axises and > one X-axis? When you have two sets of y values that do not have the same > scale, but correspond to the same x value, I would like to plot them on one > graph.x11() plot(1:10) op <- par(new = TRUE) plot(101:110, axes = FALSE, xlab = "", ylab = "", ylim = c(90, 120)) axis(4) par(op) -- WBR, Timur.