Hi Jim, I tried your code, however it still gives me only one plot. I don't understand what is going on. Any clue? On Wed, Aug 3, 2016 at 4:55 PM, Jim Lemon <drjimlemon at gmail.com> wrote:> Hi Roslina, > You only specify space for two plots in: > > par(mfrow=c(1,2)) > > However, you only try to plot two plots, so I will assume that you > only want two. You haven't defined "x" in the above code, which will > cause an error. The code below gives me two plots as I would expect (I > made up the data that you didn't supply). > > par(mfrow=c(1,2)) > stn_all<-matrix(400*rnorm(20)+4,ncol=2) > par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") > hist(stn_all[,1],prob=TRUE, main ="Balok ",col="yellowgreen", cex.axis=1.2, > xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), > xlim=c(0,1200)) > x<-c(400,600,800,1000) > dgam1<-(rnorm(4)+4)/2000 > lines(x, dgam1,col="red",lwd=3) > legend("topright", legend = c("observed","fitted"), > col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), > lwd=c(0,3),bty="n", pt.cex=2) > text(100,.012 , expression(paste(beta==64.64))) > box() > > par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") > hist(stn_all[,2],prob=TRUE, main ="Gambang ",col="yellowgreen", > cex.axis=1.2, > xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), > xlim=c(0,1200)) > dgam2<-(rnorm(4)+4)/2000 > lines(x, dgam2,col="red",lwd=3) > legend("topright", legend = c("observed","fitted"), > col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), > lwd=c(0,3),bty="n", pt.cex=2) > text(100,.012 , expression(paste(beta==64.64))) > box() > > Jim > > > On Wed, Aug 3, 2016 at 3:44 PM, roslinazairimah zakaria > <roslinaump at gmail.com> wrote: > > Dear r-users, > > > > I would like to plot 4 graphs arranged as 2 by 2 and follows are my > codes. > > However, it only shows one graph. > > > > par(mfrow=c(1,2)) > > > > par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") ## To control > > white space around and between the plots > > hist(stn_all[,1],prob=TRUE, main ="Balok ",col="yellowgreen", > cex.axis=1.2, > > xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), > > xlim=c(0,1200)) > > lines(x, dgam1,col="red",lwd=3) > > legend("topright", legend = c("observed","fitted"), > > col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), > > lwd=c(0,3),bty="n", pt.cex=2) > > text(100,.012 , expression(paste(beta==64.64))) > > box() > > > > par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") ## To control > > white space around and between the plots > > hist(stn_all[,2],prob=TRUE, main ="Gambang ",col="yellowgreen", > > cex.axis=1.2, > > xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), > > xlim=c(0,1200)) > > lines(x, dgam2,col="red",lwd=3) > > legend("topright", legend = c("observed","fitted"), > > col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), > > lwd=c(0,3),bty="n", pt.cex=2) > > text(100,.012 , expression(paste(beta==64.64))) > > box() > > > > > > Thank you for your help. > > > > -- > > *Dr. Roslinazairimah Binti Zakaria* > > *Tel: +609-5492370; Fax. No.+609-5492766* > > > > *Email: roslinazairimah at ump.edu.my <roslinazairimah at ump.edu.my>; > > roslinaump at gmail.com <roslinaump at gmail.com>* > > Deputy Dean (Academic & Student Affairs) > > Faculty of Industrial Sciences & Technology > > University Malaysia Pahang > > Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. >-- *Dr. Roslinazairimah Binti Zakaria* *Tel: +609-5492370; Fax. No.+609-5492766* *Email: roslinazairimah at ump.edu.my <roslinazairimah at ump.edu.my>; roslinaump at gmail.com <roslinaump at gmail.com>* Deputy Dean (Academic & Student Affairs) Faculty of Industrial Sciences & Technology University Malaysia Pahang Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia [[alternative HTML version deleted]]
On 03/08/2016 8:01 AM, roslinazairimah zakaria wrote:> Hi Jim, > > I tried your code, however it still gives me only one plot. I don't > understand what is going on. Any clue?The third par() call tells R that you want to start a new page. (So did the second one, but it wasn't a problem there.) Just drop it. Duncan Murdoch> > On Wed, Aug 3, 2016 at 4:55 PM, Jim Lemon <drjimlemon at gmail.com> wrote: > >> Hi Roslina, >> You only specify space for two plots in: >> >> par(mfrow=c(1,2)) >> >> However, you only try to plot two plots, so I will assume that you >> only want two. You haven't defined "x" in the above code, which will >> cause an error. The code below gives me two plots as I would expect (I >> made up the data that you didn't supply). >> >> par(mfrow=c(1,2)) >> stn_all<-matrix(400*rnorm(20)+4,ncol=2) >> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") >> hist(stn_all[,1],prob=TRUE, main ="Balok ",col="yellowgreen", cex.axis=1.2, >> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >> xlim=c(0,1200)) >> x<-c(400,600,800,1000) >> dgam1<-(rnorm(4)+4)/2000 >> lines(x, dgam1,col="red",lwd=3) >> legend("topright", legend = c("observed","fitted"), >> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >> lwd=c(0,3),bty="n", pt.cex=2) >> text(100,.012 , expression(paste(beta==64.64))) >> box() >> >> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") >> hist(stn_all[,2],prob=TRUE, main ="Gambang ",col="yellowgreen", >> cex.axis=1.2, >> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >> xlim=c(0,1200)) >> dgam2<-(rnorm(4)+4)/2000 >> lines(x, dgam2,col="red",lwd=3) >> legend("topright", legend = c("observed","fitted"), >> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >> lwd=c(0,3),bty="n", pt.cex=2) >> text(100,.012 , expression(paste(beta==64.64))) >> box() >> >> Jim >> >> >> On Wed, Aug 3, 2016 at 3:44 PM, roslinazairimah zakaria >> <roslinaump at gmail.com> wrote: >>> Dear r-users, >>> >>> I would like to plot 4 graphs arranged as 2 by 2 and follows are my >> codes. >>> However, it only shows one graph. >>> >>> par(mfrow=c(1,2)) >>> >>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") ## To control >>> white space around and between the plots >>> hist(stn_all[,1],prob=TRUE, main ="Balok ",col="yellowgreen", >> cex.axis=1.2, >>> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >>> xlim=c(0,1200)) >>> lines(x, dgam1,col="red",lwd=3) >>> legend("topright", legend = c("observed","fitted"), >>> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >>> lwd=c(0,3),bty="n", pt.cex=2) >>> text(100,.012 , expression(paste(beta==64.64))) >>> box() >>> >>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") ## To control >>> white space around and between the plots >>> hist(stn_all[,2],prob=TRUE, main ="Gambang ",col="yellowgreen", >>> cex.axis=1.2, >>> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >>> xlim=c(0,1200)) >>> lines(x, dgam2,col="red",lwd=3) >>> legend("topright", legend = c("observed","fitted"), >>> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >>> lwd=c(0,3),bty="n", pt.cex=2) >>> text(100,.012 , expression(paste(beta==64.64))) >>> box() >>> >>> >>> Thank you for your help. >>> >>> -- >>> *Dr. Roslinazairimah Binti Zakaria* >>> *Tel: +609-5492370; Fax. No.+609-5492766* >>> >>> *Email: roslinazairimah at ump.edu.my <roslinazairimah at ump.edu.my>; >>> roslinaump at gmail.com <roslinaump at gmail.com>* >>> Deputy Dean (Academic & Student Affairs) >>> Faculty of Industrial Sciences & Technology >>> University Malaysia Pahang >>> Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia >>> >>> [[alternative HTML version deleted]] >>> >>> ______________________________________________ >>> 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. >> > > >
Hi Duncan and Jim, Yes, definitely you are right. I should comment the third par(). par(mfrow=c(1,2)) stn_all<-matrix(400*rnorm(20)+4,ncol=2) par(mar=c(4,4,2,1.2),oma = c(1, 1, 1, 1),xaxs="i", yaxs="i") hist(stn_all[,1],prob=TRUE, main ="Balok ",col="yellowgreen", cex.axis=1.2, xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), xlim=c(0,1200)) x<-c(400,600,800,1000) dgam1<-(rnorm(4)+4)/2000 lines(x, dgam1,col="red",lwd=3) legend("topright", legend = c("observed","fitted"), col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), lwd=c(0,3),bty="n", pt.cex=2) text(100,.012 , expression(paste(beta==64.64))) box() #par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") hist(stn_all[,2],prob=TRUE, main ="Gambang ",col="yellowgreen", cex.axis=1.2, xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), xlim=c(0,1200)) dgam2<-(rnorm(4)+4)/2000 lines(x, dgam2,col="red",lwd=3) legend("topright", legend = c("observed","fitted"), col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), lwd=c(0,3),bty="n", pt.cex=2) text(100,.012 , expression(paste(beta==64.64))) box() Thank you. On Wed, Aug 3, 2016 at 8:14 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> On 03/08/2016 8:01 AM, roslinazairimah zakaria wrote: > >> Hi Jim, >> >> I tried your code, however it still gives me only one plot. I don't >> understand what is going on. Any clue? >> > > The third par() call tells R that you want to start a new page. (So did > the second one, but it wasn't a problem there.) Just drop it. > > Duncan Murdoch > > > >> On Wed, Aug 3, 2016 at 4:55 PM, Jim Lemon <drjimlemon at gmail.com> wrote: >> >> Hi Roslina, >>> You only specify space for two plots in: >>> >>> par(mfrow=c(1,2)) >>> >>> However, you only try to plot two plots, so I will assume that you >>> only want two. You haven't defined "x" in the above code, which will >>> cause an error. The code below gives me two plots as I would expect (I >>> made up the data that you didn't supply). >>> >>> par(mfrow=c(1,2)) >>> stn_all<-matrix(400*rnorm(20)+4,ncol=2) >>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") >>> hist(stn_all[,1],prob=TRUE, main ="Balok ",col="yellowgreen", >>> cex.axis=1.2, >>> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >>> xlim=c(0,1200)) >>> x<-c(400,600,800,1000) >>> dgam1<-(rnorm(4)+4)/2000 >>> lines(x, dgam1,col="red",lwd=3) >>> legend("topright", legend = c("observed","fitted"), >>> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >>> lwd=c(0,3),bty="n", pt.cex=2) >>> text(100,.012 , expression(paste(beta==64.64))) >>> box() >>> >>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") >>> hist(stn_all[,2],prob=TRUE, main ="Gambang ",col="yellowgreen", >>> cex.axis=1.2, >>> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >>> xlim=c(0,1200)) >>> dgam2<-(rnorm(4)+4)/2000 >>> lines(x, dgam2,col="red",lwd=3) >>> legend("topright", legend = c("observed","fitted"), >>> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >>> lwd=c(0,3),bty="n", pt.cex=2) >>> text(100,.012 , expression(paste(beta==64.64))) >>> box() >>> >>> Jim >>> >>> >>> On Wed, Aug 3, 2016 at 3:44 PM, roslinazairimah zakaria >>> <roslinaump at gmail.com> wrote: >>> >>>> Dear r-users, >>>> >>>> I would like to plot 4 graphs arranged as 2 by 2 and follows are my >>>> >>> codes. >>> >>>> However, it only shows one graph. >>>> >>>> par(mfrow=c(1,2)) >>>> >>>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") ## To control >>>> white space around and between the plots >>>> hist(stn_all[,1],prob=TRUE, main ="Balok ",col="yellowgreen", >>>> >>> cex.axis=1.2, >>> >>>> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >>>> xlim=c(0,1200)) >>>> lines(x, dgam1,col="red",lwd=3) >>>> legend("topright", legend = c("observed","fitted"), >>>> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >>>> lwd=c(0,3),bty="n", pt.cex=2) >>>> text(100,.012 , expression(paste(beta==64.64))) >>>> box() >>>> >>>> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i") ## To control >>>> white space around and between the plots >>>> hist(stn_all[,2],prob=TRUE, main ="Gambang ",col="yellowgreen", >>>> cex.axis=1.2, >>>> xlab="Rain (mm)", ylab="Relative frequency", ylim= c(0,.004), >>>> xlim=c(0,1200)) >>>> lines(x, dgam2,col="red",lwd=3) >>>> legend("topright", legend = c("observed","fitted"), >>>> col = c("yellowgreen", "red"), pch=c(15,NA), lty = c(0, 1), >>>> lwd=c(0,3),bty="n", pt.cex=2) >>>> text(100,.012 , expression(paste(beta==64.64))) >>>> box() >>>> >>>> >>>> Thank you for your help. >>>> >>>> -- >>>> *Dr. Roslinazairimah Binti Zakaria* >>>> *Tel: +609-5492370; Fax. No.+609-5492766* >>>> >>>> *Email: roslinazairimah at ump.edu.my <roslinazairimah at ump.edu.my>; >>>> roslinaump at gmail.com <roslinaump at gmail.com>* >>>> Deputy Dean (Academic & Student Affairs) >>>> Faculty of Industrial Sciences & Technology >>>> University Malaysia Pahang >>>> Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia >>>> >>>> [[alternative HTML version deleted]] >>>> >>>> ______________________________________________ >>>> 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. >>>> >>> >>> >> >> >> >-- *Roslinazairimah Zakaria* *Tel: +609-5492370; Fax. No.+609-5492766* *Email: roslinazairimah at ump.edu.my <roslinazairimah at ump.edu.my>; roslinaump at gmail.com <roslinaump at gmail.com>* Faculty of Industrial Sciences & Technology University Malaysia Pahang Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia [[alternative HTML version deleted]]