Hi Petr
I followed your suggestion and I have attached a saved txt file with the data 
and the script using dput(). I hope this time will work. 
But by the way your code worked as well. 
Many thanks. 
Kind regards,Maria 
    Στις 1:06 μ.μ. Τρίτη, 28 Φεβρουαρίου 2017, ο/η PIKAL Petr 
<petr.pi...@precheza.cz> έγραψε:
 

 Hi

better to send us your data by copying result of dput()

Based on Jims toy data, do you want something like that?

plot(aa$sdate,aa$var1,xaxt="n")
sel <- seq(1,15, 2)
axis(1, at=axis.dates[sel], labels=format(axis.dates, "%Y")[sel])

You can easily adopt it by managing the sequention.

Cheers
Petr

> -----Original Message-----
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Maria
> Lathouri via R-help
> Sent: Tuesday, February 28, 2017 1:14 PM
> To: r-help@r-project.org; Jim Lemon <drjimle...@gmail.com>
> Subject: [R] Σχετ: Σχετ: plotting dates in x axis
>
> Dear Jim
> Many thanks for this. I tried and it somehow worked. I removed the nlines=3
> from your script so I can have the years in one line, but still the problem is
> that while trying to show all the years, there are years in the first line and
> then other years in a second line. I was wondering if I can show every two
> years instead. I think it would be much better. Many thanks. Kind
> regards,Maria
>
>    Στις 11:56 π.μ. Τρίτη, 28 Φεβρουαρίου 2017, ο/η Maria Lathouri via R-help
> <r-help@r-project.org> έγραψε:
>
>
>  Dear all,
> Sorry about that. My mistake. Here is an example of my data
> > head(aa)      SDATE  var11 1998-01-29 0.7282 1998-02-17 1.0803
> > 1998-03-20 0.6374 1998-05-07 1.1205 1998-05-26 0.9036 1998-06-05
> > 1.210.........................178 2012-10-4  0.71179 2012-11-4
> > 0.663180 2012-12-10 0.484
> I hope this helps.
> Maria
>
>    Στις 10:00 μ.μ. Δευτέρα, 27 Φεβρουαρίου 2017, ο/η Jeff Newmiller
> <jdnew...@dcn.davis.ca.us> έγραψε:
>
>
>  While humorous, the term "Mexican Wall" is unlikely to be clear to the OP.
> This is a reference to the mailing list anti-virus strategy of cutting out
> attachments that don't meet a very restrictive set of requirements outlined
> in the Posting Guide that all R-users are supposed to have read and
> memorized, but which few even seem to know exists. You can best avoid the
> "Mexican Wall" by setting your email program to send plain text instead of
> HTML, and to embed your R code example (believe it or not, this is not the
> Excel-To-R translation service, so show us your R code and text data, not your
> Excel file) in the email along with your description of your problem. For more
> help on getting help search the Internet for "R reproducible example".
> --
> Sent from my phone. Please excuse my brevity.
>
> On February 27, 2017 1:11:05 PM PST, Jim Lemon <drjimle...@gmail.com>
> wrote:
> >Hi Maria,
> >First, Excel files don't make it through the Mexican Wall. A CSV with
> >the extension changed to .txt might. You can get all of the years like
> >this:
> >
> >aa<-data.frame(var1=runif(180),
> > SDATE=paste(sample(1998:2012,180,TRUE),
> > sample(1:12,180,TRUE),sample(1:28,180,TRUE),sep="-"))
> >aa$sdate<-as.Date(aa$SDATE)
> >plot(aa$sdate,aa$var1,xaxt="n")
> >library(plotrix)
> ># set the tick marks at the middle of each year
> >axis.dates<-as.Date(paste(1998:2012,6,30,sep="-"))
> >staxlab(1,axis.dates,1998:2012,nlines=3)
> >
> >Obviously you don't want all of the months, so just add the months to
> >the years:
> >
> >plot(aa$sdate,aa$var1,xaxt="n")
> >staxlab(1,axis.dates,format(axis.dates,"%b/%Y"),nlines=3)
> >
> >Jim
> >
> >
> >On Tue, Feb 28, 2017 at 2:26 AM, Maria Lathouri via R-help
> ><r-help@r-project.org> wrote:
> >> Dear all,
> >> I have an excel file of 180 observations with dates and one variable,
> >from 1998 to 2012 by random months (there are some years that I might
> >not have all the months or I might have two observations in one month).
> >I am trying to plot the dates in x axis and the variable in y axis. I
> >have already used as.Date for the dates so I can import them into R.
> >> Here is my script:> aa<-read.csv("aa.csv")> attach(aa)>
> >names(aa)#"SDATE" "var1"
> >> I convert the dates into R: > sdate<-as.Date(SDATE,
> >format="%Y-%m-%d")
> >>
> >> I am plotting the dates with my var1:> plot(sdate, var1, type="l") Up
> >> to now, everything seems ok. However, in the x-axis I only get
> >three years, 2000, 2005 and 2010. As I want to show all the years or at
> >least as many as it could be, I am using the following:
> >>> plot(sdate, var1, type="l", xaxt="n")
> >>
> >>> d1<-c((sdate[1]), (sdate[183]))> d2<-as.Date((d1[1])+365*(0:15))
> >>> axis(side=1, at=0:15, labels=strftime(d2, format="%Y"),
> >cex.axis=0.8,las=2);  I tried also to plot the dates in a month-Year
> >form:
> >>
> >>> d2<-as.Date((d1[1])+150*(0:20))
> >>> plot(sdate, var1, type="l", xaxt="n")> axis(side=1, at=0:15,
> >labels=strftime(d2, format="%m-%Y"), cex.axis=0.8,las=2)
> >>
> >> But nothing happened. I cannot understand why it doesn't show
> >anything.
> >> I have attached the file as well in case you want to have a more
> >clear picture.
> >> I really appreciate it if you can help me on this.
> >> Thank you very much in advance.
> >> Kind regards,Maria
> >> ______________________________________________
> >> R-help@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@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.
>
>
>    [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>
>
>      [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.


   
structure(list(SDATE = structure(1:183, .Label = c("1998-01-29", 
"1998-02-17", "1998-03-20", "1998-05-07", "1998-05-26", "1998-06-05", 
"1998-06-29", "1998-07-22", "1998-08-19", "1998-09-10", "1998-11-04", 
"1998-11-11", "1998-11-19", "1998-12-10", "1998-12-14", "1999-02-10", 
"1999-03-04", "1999-03-22", "1999-04-08", "1999-05-06", "1999-05-26", 
"1999-08-05", "1999-08-17", "1999-09-29", "1999-10-21", "1999-11-11", 
"1999-12-09", "2000-01-13", "2000-02-03", "2000-03-01", "2000-04-05", 
"2000-05-04", "2000-06-16", "2000-07-19", "2000-09-06", "2000-09-26", 
"2000-10-16", "2000-11-29", "2000-12-06", "2000-12-11", "2001-01-18", 
"2001-02-08", "2002-01-23", "2002-03-05", "2002-03-21", "2002-04-15", 
"2002-05-27", "2002-06-24", "2002-09-12", "2002-10-10", "2002-10-18", 
"2002-10-24", "2002-11-11", "2002-11-22", "2002-11-28", "2002-12-05", 
"2003-01-14", "2003-02-11", "2003-03-11", "2003-04-10", "2003-04-25", 
"2003-05-13", "2003-06-27", "2003-07-07", "2003-09-02", "2003-10-13", 
"2003-11-24", "2003-12-02", "2003-12-16", "2004-02-23", "2004-03-26", 
"2004-04-27", "2004-05-25", "2004-06-30", "2004-07-27", "2004-08-27", 
"2004-09-27", "2004-10-12", "2004-11-15", "2004-11-26", "2004-11-30", 
"2004-12-13", "2004-12-15", "2005-01-17", "2005-02-04", "2005-03-08", 
"2005-04-08", "2005-05-04", "2005-06-14", "2005-07-08", "2005-07-15", 
"2005-08-23", "2005-09-08", "2005-10-18", "2005-11-18", "2005-12-01", 
"2006-01-09", "2006-02-16", "2006-03-01", "2006-04-24", "2006-05-04", 
"2006-06-26", "2006-07-11", "2006-08-10", "2006-09-05", "2006-10-10", 
"2006-11-08", "2007-03-22", "2007-04-10", "2007-04-25", "2007-05-18", 
"2007-06-07", "2007-07-12", "2007-09-04", "2007-09-19", "2007-10-08", 
"2007-10-19", "2007-11-06", "2007-12-04", "2008-02-05", "2008-02-15", 
"2008-03-04", "2008-04-18", "2008-05-13", "2008-05-30", "2008-07-14", 
"2008-08-07", "2008-09-23", "2008-10-09", "2008-10-31", "2008-11-25", 
"2008-12-10", "2009-01-19", "2009-02-12", "2009-02-19", "2009-03-17", 
"2009-04-06", "2009-04-29", "2009-05-12", "2009-05-28", "2009-06-24", 
"2009-07-22", "2009-08-21", "2009-09-16", "2009-10-20", "2009-11-05", 
"2009-11-17", "2009-11-26", "2009-12-14", "2011-01-11", "2011-01-12", 
"2011-02-07", "2011-02-28", "2011-03-10", "2011-03-22", "2011-03-30", 
"2011-04-06", "2011-05-05", "2011-05-20", "2011-06-01", "2011-07-01", 
"2011-07-18", "2011-07-27", "2011-08-11", "2011-09-08", "2011-09-20", 
"2011-10-12", "2011-11-07", "2011-11-24", "2011-12-08", "2011-12-28", 
"2012-01-18", "2012-02-07", "2012-03-13", "2012-04-17", "2012-05-11", 
"2012-06-18", "2012-07-18", "2012-08-15", "2012-09-19", "2012-10-16", 
"2012-11-07", "2012-11-21"), class = "factor"), CUDIS = c(0.728, 
1.08, 0.637, 1.12, 0.903, 1.21, 1.21, 1.59, 1.310498353, 1.52, 
1.15, 1.166803955, 0.915, 1.04, 1.168554514, 0.537, 0.94, 1.02, 
1.08, 0.917, 0.787, 0.798, 0.893, 1.35, 0.669, 0.673, 0.996169675, 
1.3, 1.39, 0.688, 1.03, 0.877, 0.995, 1.13, 1.07, 1.07, 1.74, 
0.935, 1.19, 1.19, 1.13, 0.755, 0.867, 1.37, 0.59, 1.15, 0.9, 
1.34, 0.77, 1.04, 0.61, 1.13, 1.54, 1.72, 1.707065063, 1.33, 
2.25, 0.89, 1.48, 0.82, 0.95, 1.19, 1.33, 1.51, 1.42, 0.78, 0.89, 
1.58, 0.99, 0.78, 1.12, 1.01, 0.9, 1.21, 1.7, 1.5, 0.98, 0.98, 
1.04, 1.195125596, 0.859558911, 1.27, 1.322141224, 0.77, 1.1, 
1.08, 1.33, 2.51, 1.3, 1.06, 1.21, 1.12, 1.8, 1.12, 1.62, 1.28, 
1.37, 1.59, 0.89, 0.76, 1.52, 1.02, 1.07, 0.98, 1.65, 1.44, 0.96, 
0.9, 0.76, 1.56, 2.15, 1.83, 0.444166504, 0.450378353, 0.511635536, 
0.55, 1.37, 1.4, 4.3, 4.7, 0.55525642, 3, 1.1, 1.1, 1.9, 2.2, 
1.8, 0.590842068, 2.7, 0.621726314, 1.1, 1.65, 1.4, 0.649503169, 
1.28, 0.675072133, 0.698996502, 0.7, 0.721655543, 0.743318767, 
0.9, 1.7, 1.4, 0.76418593, 0.784410241, 1.3, 1.4, 0.86, 0.804112632, 
1.02, 1.22, 0.93, 1.04, 1.02, 0.823390949, 0.842326119, 1.32, 
0.860986412, 1.06, 0.879430486, 1.32, 1.28, 1.15, 1.1, 2.17, 
1.02, 2.85, 1.01, 1.1, 0.92, 1.15, 0.89770961, 0.915869328, 0.933950733, 
0.951991468, 1.67, 1.32, 1.07, 0.970026513, 1.2, 1.77, 0.98808884, 
1.36)), .Names = c("SDATE", "CUDIS"), class = "data.frame", row.names = c(NA, 
-183L))
______________________________________________
R-help@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.

Reply via email to