Attached is a plot with a time series. If I have a time series object in R. How do I get the plot in the attached format of time axis?. When I issue plot(ts) I get a time series plot with tic only for years. -- with best regards Sudheer ********************************************************************************** Dr. Sudheer Joseph Scientist INDIAN NATIONAL CENTRE FOR OCEAN INFORMATION SERVICES (INCOIS) MINISTRY OF EARTH SCIENCES, GOVERNMENT OF INDIA "OCEAN VALLEY" PRAGATHI NAGAR (BO) OPP.JNTU, NIZAMPET SO Andhra Pradesh, India. PIN- 500 090. TEl:+91-40-23044600(R),Tel:+91-9440832534(Mobile) Tel:+91-40-23886047(O),Fax:+91-40-23892910(O) E-mail: sudheer.joseph at yahoo.com; sjo at incois.gov.in. Web- http://oppamthadathil.tripod.com --------------* --------------- "The ultimate measure of a man is not where he stands in moments of comfort and convenience, but where he stands at times of challenge and controversy." Martin Luther King, Jr. "What we have done for ourselves alone dies with us. What we have done for others and the world remains and is immortal." - Albert Pines
There was not attached plot or data. Plot without the x-axis (probably xaxt = 'n') and then use "axis" to create your own ticks. It would be helpful if you had supplied data using 'dput'. On Sun, Aug 25, 2013 at 11:09 AM, Sudheer Joseph <sjo.india@gmail.com>wrote:> Attached is a plot with a time series. If I have a time series object in R. > How do I get the plot in the attached format of time axis?. When I issue > plot(ts) I get a time series plot with tic only for years. > > > -- > with best regards > > Sudheer > > > ********************************************************************************** > Dr. Sudheer Joseph > > Scientist > > INDIAN NATIONAL CENTRE FOR OCEAN INFORMATION SERVICES (INCOIS) > MINISTRY OF EARTH SCIENCES, GOVERNMENT OF INDIA > "OCEAN VALLEY" PRAGATHI NAGAR (BO) > OPP.JNTU, NIZAMPET SO > Andhra Pradesh, India. PIN- 500 090. > TEl:+91-40-23044600(R),Tel:+91-9440832534(Mobile) > Tel:+91-40-23886047(O),Fax:+91-40-23892910(O) > E-mail: sudheer.joseph@yahoo.com; sjo@incois.gov.in. > Web- http://oppamthadathil.tripod.com > --------------* --------------- > "The ultimate measure of a man is > not where he stands in moments of > comfort and convenience, but where > he stands at times of challenge and > controversy." > Martin Luther King, Jr. > "What we have done for ourselves alone dies with us. > What we have done for others and the world remains and is immortal." > - Albert Pines > > ______________________________________________ > 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. > >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]]
Try this: n <- 100 x <- data.frame(time = seq(from = as.Date('2010-1-1') , to = as.Date('2012-1-1') , length = n ) , val = runif(n) ) plot(x$time, x$val, type = 'l', main = 'Default') # now plot with your own axis with the first character of month in the center plot(x$time, x$val, type = 'l', main = 'Manual Labels', xaxt = 'n') # create sequence of start of month monthTick <- seq(from = as.Date(format(min(x$time), "%Y-%m-1")) , to = as.Date(format(max(x$time), "%Y-%m-1")) , by = '1 month' ) # create tick marks axis(1, at = monthTick, labels = FALSE) # add months mtext(substring(months(monthTick), 1, 1) , at = monthTick + 15 , side = 1 ) On Sun, Aug 25, 2013 at 1:08 PM, Sudheer Joseph <sjo.india@gmail.com> wrote:> Thank you, > I rechecked it , I had attached the plot > but it may have been blocked due to site policies. So here is the link. > > > https://docs.google.com/file/d/0B3heUQNme7G5RUxhYkN3NUQzdlk/edit?usp=sharing > > > On Sun, Aug 25, 2013 at 10:12 PM, jim holtman <jholtman@gmail.com> wrote: > >> There was not attached plot or data. Plot without the x-axis (probably >> xaxt = 'n') and then use "axis" to create your own ticks. It would be >> helpful if you had supplied data using 'dput'. >> >> >> On Sun, Aug 25, 2013 at 11:09 AM, Sudheer Joseph <sjo.india@gmail.com>wrote: >> >>> Attached is a plot with a time series. If I have a time series object in >>> R. >>> How do I get the plot in the attached format of time axis?. When I issue >>> plot(ts) I get a time series plot with tic only for years. >>> >>> >>> -- >>> with best regards >>> >>> Sudheer >>> >>> >>> ********************************************************************************** >>> Dr. Sudheer Joseph >>> >>> Scientist >>> >>> INDIAN NATIONAL CENTRE FOR OCEAN INFORMATION SERVICES (INCOIS) >>> MINISTRY OF EARTH SCIENCES, GOVERNMENT OF INDIA >>> "OCEAN VALLEY" PRAGATHI NAGAR (BO) >>> OPP.JNTU, NIZAMPET SO >>> Andhra Pradesh, India. PIN- 500 090. >>> TEl:+91-40-23044600(R),Tel:+91-9440832534(Mobile) >>> Tel:+91-40-23886047(O),Fax:+91-40-23892910(O) >>> E-mail: sudheer.joseph@yahoo.com; sjo@incois.gov.in. >>> Web- http://oppamthadathil.tripod.com >>> --------------* --------------- >>> "The ultimate measure of a man is >>> not where he stands in moments of >>> comfort and convenience, but where >>> he stands at times of challenge and >>> controversy." >>> Martin Luther King, Jr. >>> "What we have done for ourselves alone dies with us. >>> What we have done for others and the world remains and is immortal." >>> - Albert Pines >>> >>> ______________________________________________ >>> 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. >>> >>> >> >> >> -- >> Jim Holtman >> Data Munger Guru >> >> What is the problem that you are trying to solve? >> Tell me what you want to do, not how you want to do it. >> > > > > -- > with best regards > > Sudheer > > > ********************************************************************************** > Dr. Sudheer Joseph > > Scientist > > INDIAN NATIONAL CENTRE FOR OCEAN INFORMATION SERVICES (INCOIS) > MINISTRY OF EARTH SCIENCES, GOVERNMENT OF INDIA > "OCEAN VALLEY" PRAGATHI NAGAR (BO) > OPP.JNTU, NIZAMPET SO > Andhra Pradesh, India. PIN- 500 090. > TEl:+91-40-23044600(R),Tel:+91-9440832534(Mobile) > Tel:+91-40-23886047(O),Fax:+91-40-23892910(O) > E-mail: sudheer.joseph@yahoo.com; sjo@incois.gov.in. > Web- http://oppamthadathil.tripod.com > --------------* --------------- > "The ultimate measure of a man is > not where he stands in moments of > comfort and convenience, but where > he stands at times of challenge and > controversy." > Martin Luther King, Jr. > "What we have done for ourselves alone dies with us. > What we have done for others and the world remains and is immortal." > - Albert Pines >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]]
On 08/26/2013 01:09 AM, Sudheer Joseph wrote:> Attached is a plot with a time series. If I have a time series object in R. > How do I get the plot in the attached format of time axis?. When I issue > plot(ts) I get a time series plot with tic only for years. > >Hi Sudheer, If your problem is similar to that answered last week "X axis label as months", you can follow the suggestion by the other Jim and then add a custom x axis. The problem is getting the axis labels aligned, and this function: tsxpos<-function(x) { # make sure that there is a graphics device open if(dev.cur() == 1) stop("A graphics device must be open") plotlim<-par("usr") divlim<-ifelse(par("xaxs") == "r",0.04,0) xrange<-(plotlim[2]-plotlim[1])/(1+2*divlim) xstart<-plotlim[1]+xrange*divlim nint<-length(x)-1 return(cumsum(c(xstart,rep(xrange/nint,nint)))) } when called after creating the original time series plot will return the x positions for the time series (the "x" argument is for the time series object). You can then pass these values to the axis function in the "at" argument with your desired labels in the "labels" argument. This function has been added to the plotrix package and will appear in the next version. Jim