Hi all, I tried to have plot of many vector in one plot and i have got a nice plot but i have problem with x-axis. I want to have month and year only(Jul.07 means July 2007) in x-axis without appearing other number behaind it. I would appercit any help. The R code: F<-c(7.49,6.91,6.78,6.99,7.44,7.42) M<-c(4.81,4.51,5.21,4.65,4.75,3.86) P<-c(7.49,15.03,15.19,15.32,15.42,15.45) B<-c(16.24,15.87,12.94,11.82,10.86,9.61) time<-c("Jul/07","Aug/07","Sep/07","Oct/07","Nov/07","Dec/07") model<-data.frame(F,M,P,B) row.names(model)<-c("Jul07","Aug07","Sep07","Oct07","Nov07","Dec007") model par(mgp=c(2, 1, 0),bty="o" ) matplot(model, pch = c(1,22,17,16), type = "o",lty=c(2,2,2,5), col =c("gray10"," gray10","gray10","gray10"),xlab="Month-Year",ylab="Zinth", xaxs = "i", yaxs = "i",main="Model Output") legend("topleft", legend = c("F", "M","P","B"),text.width strwidth("1,000,000,"),pch=c(1,22,17,16),col =c("gray10"," gray10","gray10","gray10"),lty=c(2,2,2,5), xjust = 1, yjust = 1, bty="n", cex=0.8, ncol=2) axis(1, 1:6, row.names(model)) -- View this message in context: http://n4.nabble.com/x-axis-plot-problem-tp1472286p1472286.html Sent from the R help mailing list archive at Nabble.com.
On Feb 7, 2010, at 3:22 PM, abotaha wrote:> > Hi all, > I tried to have plot of many vector in one plot and i have got a > nice plot > but i have problem with x-axis. I want to have month and year > only(Jul.07 > means July 2007) in x-axis without appearing other number behaind it.I'm going to assume that you did not want that period between the Mon and Yr since you did not include it in your label strings.> > I would appercit any help. > > The R code: > > F<-c(7.49,6.91,6.78,6.99,7.44,7.42) > M<-c(4.81,4.51,5.21,4.65,4.75,3.86) > P<-c(7.49,15.03,15.19,15.32,15.42,15.45) > B<-c(16.24,15.87,12.94,11.82,10.86,9.61) > > time<-c("Jul/07","Aug/07","Sep/07","Oct/07","Nov/07","Dec/07") > model<-data.frame(F,M,P,B) > row.names(model)<-c("Jul07","Aug07","Sep07","Oct07","Nov07","Dec007") > model > > par(mgp=c(2, 1, 0),bty="o" ) > matplot(model, pch = c(1,22,17,16), type = "o",lty=c(2,2,2,5), col > =c("gray10"," gray10","gray10","gray10"),xlab="Month- > Year",ylab="Zinth", > xaxs = "i", yaxs = "i",main="Model Output")# Change the xaxs="i" to xaxt="n" to suppress the numbers 1:6 from being stuck under the labels you later lay down with the axis command.> legend("topleft", legend = c("F", "M","P","B"),text.width > strwidth("1,000,000,"),pch=c(1,22,17,16),col =c("gray10"," > gray10","gray10","gray10"),lty=c(2,2,2,5), xjust = 1, yjust = 1, > bty="n", > cex=0.8, ncol=2) > axis(1, 1:6, row.names(model)) > -- > View this message in context: http://n4.nabble.com/x-axis-plot-problem-tp1472286p1472286.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
I think you just need to set axes=FALSE in your call to matplot(). You'll then need to add the y-axis manually --- do axis(2) in addition to your call which draws the x axis. You'll also need to do box() if you want a box around your graph. cheers, Rolf Turner P. S. You are clearly a Good Person! A relative newbie who has read the Posting Guide! :-) R. T. On 8/02/2010, at 9:22 AM, abotaha wrote:> > Hi all, > I tried to have plot of many vector in one plot and i have got a nice plot > but i have problem with x-axis. I want to have month and year only(Jul.07 > means July 2007) in x-axis without appearing other number behaind it. > > I would appercit any help. > > The R code: > > F<-c(7.49,6.91,6.78,6.99,7.44,7.42) > M<-c(4.81,4.51,5.21,4.65,4.75,3.86) > P<-c(7.49,15.03,15.19,15.32,15.42,15.45) > B<-c(16.24,15.87,12.94,11.82,10.86,9.61) > > time<-c("Jul/07","Aug/07","Sep/07","Oct/07","Nov/07","Dec/07") > model<-data.frame(F,M,P,B) > row.names(model)<-c("Jul07","Aug07","Sep07","Oct07","Nov07","Dec007") > model > > par(mgp=c(2, 1, 0),bty="o" ) > matplot(model, pch = c(1,22,17,16), type = "o",lty=c(2,2,2,5), col > =c("gray10"," gray10","gray10","gray10"),xlab="Month-Year",ylab="Zinth", > xaxs = "i", yaxs = "i",main="Model Output") > legend("topleft", legend = c("F", "M","P","B"),text.width > strwidth("1,000,000,"),pch=c(1,22,17,16),col =c("gray10"," > gray10","gray10","gray10"),lty=c(2,2,2,5), xjust = 1, yjust = 1, bty="n", > cex=0.8, ncol=2) >> -- > View this message in context: http://n4.nabble.com/x-axis-plot-problem-tp1472286p1472286.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.###################################################################### Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ######################################################################
Hi abotaha, Modify your matplot() call as matplot(model, pch = c(1,22,17,16), type = "o",lty=c(2,2,2,5), col =c("gray10"," gray10","gray10","gray10"),xlab="Month-Year",ylab="Zinth", xaxt = "n", yaxs = "i",main="Model Output") and then add axis(1, 1:6, time) HTH, Jorge On Sun, Feb 7, 2010 at 3:22 PM, abotaha <> wrote:> > Hi all, > I tried to have plot of many vector in one plot and i have got a nice plot > but i have problem with x-axis. I want to have month and year only(Jul.07 > means July 2007) in x-axis without appearing other number behaind it. > > I would appercit any help. > > The R code: > > F<-c(7.49,6.91,6.78,6.99,7.44,7.42) > M<-c(4.81,4.51,5.21,4.65,4.75,3.86) > P<-c(7.49,15.03,15.19,15.32,15.42,15.45) > B<-c(16.24,15.87,12.94,11.82,10.86,9.61) > > time<-c("Jul/07","Aug/07","Sep/07","Oct/07","Nov/07","Dec/07") > model<-data.frame(F,M,P,B) > row.names(model)<-c("Jul07","Aug07","Sep07","Oct07","Nov07","Dec007") > model > > par(mgp=c(2, 1, 0),bty="o" ) > matplot(model, pch = c(1,22,17,16), type = "o",lty=c(2,2,2,5), col > =c("gray10"," gray10","gray10","gray10"),xlab="Month-Year",ylab="Zinth", > xaxs = "i", yaxs = "i",main="Model Output") > legend("topleft", legend = c("F", "M","P","B"),text.width > strwidth("1,000,000,"),pch=c(1,22,17,16),col =c("gray10"," > gray10","gray10","gray10"),lty=c(2,2,2,5), xjust = 1, yjust = 1, bty="n", > cex=0.8, ncol=2) > axis(1, 1:6, row.names(model)) > -- > View this message in context: > http://n4.nabble.com/x-axis-plot-problem-tp1472286p1472286.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
Thanks guys, it works now properly when I change axas="i" to axat="n", but there is a space between the box from the left side (y-axis) and the beginning plotted curve. please could you tell me how avoid that. any suggestions thanks, -- View this message in context: http://n4.nabble.com/x-axis-plot-problem-tp1472286p1472728.html Sent from the R help mailing list archive at Nabble.com.