varin sacha
2015-Mar-23 15:54 UTC
[R] Superimposing 2 curves on the same graph with par(new=TRUE)
Dear R-Experts, I try to superimpose/present 2 curves/plots on the same graph. I would like the result/graph to be readable. For that, I use the par(new=TRUE) argument but on the Y-axis there is a superposition of writings and the Y-axis becomes unreadable. How can I solve this problem ? Here is a reproducible example : Date<-c(1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010) MORTSFr<-c(16445,17671,18113,17043,14738,14355,15028,14283,13229,13603,13672,13547,13527,13021,12737,11388,11947,10742,11497,11476,11215,10483,9900,9568,9019,8891,8541,8444,8918,8487,8079,8160,7655,6058,5593,5318,4709,4620,4275,4273,3992) MORTSBu<-c(838,889,934,946,960,1030,1021,1040,1153,1149,1199,1219,1229,1123,1119,1113,1070,1153,1153,1280,1567,1114,1299,1307,1390,1264,1014,915,1003,1047,1012,1011,959,960,943,957,1043,1006,1061,901,776) plot(Date,MORTSFr,type="l") par(new=TRUE) plot(Date,MORTSBu,lwd=2,lty="dashed") Thanks for your time. Best, S
Boris Steipe
2015-Mar-23 16:18 UTC
[R] Superimposing 2 curves on the same graph with par(new=TRUE)
Here is how: plot(Date,MORTSFr,type="l", ylim=c(0,max(MORTSFr))) points(Date,MORTSBu,type="l",lty=2) If you don't use the same scale for the two plots, you are probably misrepresenting the data. If you want to plot relative change, normalize the data before plotting. norm <- function(x) {(x - min(x))/(max(x) - min(x))} plot(Date,norm(MORTSFr),ylab=c("Relative Change"),type="l") points(Date,norm(MORTSBu),type="l",lty=2) B. On Mar 23, 2015, at 11:54 AM, varin sacha <varinsacha at yahoo.fr> wrote:> Dear R-Experts, > > I try to superimpose/present 2 curves/plots on the same graph. I would like the result/graph to be readable. > For that, I use the par(new=TRUE) argument but on the Y-axis there is a superposition of writings and the Y-axis becomes unreadable. > How can I solve this problem ? > > Here is a reproducible example : > Date<-c(1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010) > > MORTSFr<-c(16445,17671,18113,17043,14738,14355,15028,14283,13229,13603,13672,13547,13527,13021,12737,11388,11947,10742,11497,11476,11215,10483,9900,9568,9019,8891,8541,8444,8918,8487,8079,8160,7655,6058,5593,5318,4709,4620,4275,4273,3992) > > MORTSBu<-c(838,889,934,946,960,1030,1021,1040,1153,1149,1199,1219,1229,1123,1119,1113,1070,1153,1153,1280,1567,1114,1299,1307,1390,1264,1014,915,1003,1047,1012,1011,959,960,943,957,1043,1006,1061,901,776) > > plot(Date,MORTSFr,type="l") > par(new=TRUE) > > plot(Date,MORTSBu,lwd=2,lty="dashed") > > Thanks for your time. > Best, > S > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Clint Bowman
2015-Mar-23 16:34 UTC
[R] Superimposing 2 curves on the same graph with par(new=TRUE)
Try: plot(Date,MORTSBu,lwd=2,lty="dashed",axes=F,xlab="",ylab="") Clint Bowman INTERNET: clint at ecy.wa.gov Air Quality Modeler INTERNET: clint at math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX: (360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 On Mon, 23 Mar 2015, varin sacha wrote:> Dear R-Experts, > > I try to superimpose/present 2 curves/plots on the same graph. I would like the result/graph to be readable. > For that, I use the par(new=TRUE) argument but on the Y-axis there is a superposition of writings and the Y-axis becomes unreadable. > How can I solve this problem ? > > Here is a reproducible example : > Date<-c(1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010) > > MORTSFr<-c(16445,17671,18113,17043,14738,14355,15028,14283,13229,13603,13672,13547,13527,13021,12737,11388,11947,10742,11497,11476,11215,10483,9900,9568,9019,8891,8541,8444,8918,8487,8079,8160,7655,6058,5593,5318,4709,4620,4275,4273,3992) > > MORTSBu<-c(838,889,934,946,960,1030,1021,1040,1153,1149,1199,1219,1229,1123,1119,1113,1070,1153,1153,1280,1567,1114,1299,1307,1390,1264,1014,915,1003,1047,1012,1011,959,960,943,957,1043,1006,1061,901,776) > > plot(Date,MORTSFr,type="l") > par(new=TRUE) > > plot(Date,MORTSBu,lwd=2,lty="dashed") > > Thanks for your time. > Best, > S > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >
Boris Steipe
2015-Mar-23 17:04 UTC
[R] Superimposing 2 curves on the same graph with par(new=TRUE)
... which is exactly what he shouldn't do because now it the plot falsely asserts that both curves are plotted to the same scale. B. On Mar 23, 2015, at 12:34 PM, Clint Bowman <clint at ecy.wa.gov> wrote:> Try: > plot(Date,MORTSBu,lwd=2,lty="dashed",axes=F,xlab="",ylab="") > > > > Clint Bowman INTERNET: clint at ecy.wa.gov > Air Quality Modeler INTERNET: clint at math.utah.edu > Department of Ecology VOICE: (360) 407-6815 > PO Box 47600 FAX: (360) 407-7534 > Olympia, WA 98504-7600 > > USPS: PO Box 47600, Olympia, WA 98504-7600 > Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 > > On Mon, 23 Mar 2015, varin sacha wrote: > >> Dear R-Experts, >> >> I try to superimpose/present 2 curves/plots on the same graph. I would like the result/graph to be readable. >> For that, I use the par(new=TRUE) argument but on the Y-axis there is a superposition of writings and the Y-axis becomes unreadable. >> How can I solve this problem ? >> >> Here is a reproducible example : >> Date<-c(1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010) >> >> MORTSFr<-c(16445,17671,18113,17043,14738,14355,15028,14283,13229,13603,13672,13547,13527,13021,12737,11388,11947,10742,11497,11476,11215,10483,9900,9568,9019,8891,8541,8444,8918,8487,8079,8160,7655,6058,5593,5318,4709,4620,4275,4273,3992) >> >> MORTSBu<-c(838,889,934,946,960,1030,1021,1040,1153,1149,1199,1219,1229,1123,1119,1113,1070,1153,1153,1280,1567,1114,1299,1307,1390,1264,1014,915,1003,1047,1012,1011,959,960,943,957,1043,1006,1061,901,776) >> >> plot(Date,MORTSFr,type="l") >> par(new=TRUE) >> >> plot(Date,MORTSBu,lwd=2,lty="dashed") >> >> Thanks for your time. >> Best, >> S >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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 -- To UNSUBSCRIBE and more, see > 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.