Hello all, When I tried to plot the following two arrays in one figure with the following: x = c(0,0,0,10,20,30) y = c(40,50,60,70,80,90) plot(x, type='o', ylim=c(min(x),max(x))) par(new=T) plot(y, type='l', ylim=c(min(y),max(y))) Found that the first points and last points from those two arrays are overlapping together, but the value 30 is not equal to 90. How could I draw those two arrays in one plot with their real values shown in the plot? i.e., x is in the lower part of the plot and y is in the upper part of the plot. Thanks very much! Cheers, Rebecca ---------------------------------------------------------------------- This message, and any attachments, is for the intended r...{{dropped:5}}
One method is to follow correct usage of base graphics and only use the plot function once for each plot. To overlay, use a function like points or lines. Another approach is to use lattice graphics or ggplot2 and give the data to higher-level plot routines that know how to plot multiple groups of data together. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. "Yuan, Rebecca" <rebecca.yuan at bankofamerica.com> wrote:>Hello all, > >When I tried to plot the following two arrays in one figure with the >following: > >x = c(0,0,0,10,20,30) >y = c(40,50,60,70,80,90) >plot(x, type='o', ylim=c(min(x),max(x))) >par(new=T) >plot(y, type='l', ylim=c(min(y),max(y))) > >Found that the first points and last points from those two arrays are >overlapping together, but the value 30 is not equal to 90. How could I >draw those two arrays in one plot with their real values shown in the >plot? i.e., x is in the lower part of the plot and y is in the upper >part of the plot. > >Thanks very much! > >Cheers, > >Rebecca > > > >---------------------------------------------------------------------- >This message, and any attachments, is for the intended >r...{{dropped:5}} > >______________________________________________ >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.
Hello David, When I used the same ylim for both plots, I got what I need: x = c(0,0,0,10,20,30) y = c(40,50,60,70,80,90) plot(x, type='o', ylim=c(min(x,y),max(x,y))) par(new=T) plot(y, type='l', ylim=c(min(x,y),max(x,y))) Thanks, Rebecca -----Original Message----- From: David Winsemius [mailto:dwinsemius at comcast.net] Sent: Friday, February 01, 2013 11:39 AM To: Yuan, Rebecca Subject: Re: [R] Range difference of plot two arrays in one plot On Feb 1, 2013, at 10:28 AM, Yuan, Rebecca wrote:> Hello all, > > When I tried to plot the following two arrays in one figure with the > following: > > x = c(0,0,0,10,20,30) > y = c(40,50,60,70,80,90) > plot(x, type='o', ylim=c(min(x),max(x))) > par(new=T) > plot(y, type='l', ylim=c(min(y),max(y))) > > Found that the first points and last points from those two arrays are > overlapping together, but the value 30 is not equal to 90. How could I > draw those two arrays in one plot with their real values shown in the > plot? i.e., x is in the lower part of the plot and y is in the upper > part of the plot. >Use the same ylim for each plot? -- David Winsemius, MD Alameda, CA, USA ---------------------------------------------------------------------- This message, and any attachments, is for the intended r...{{dropped:2}}