[R] problems with plot.data.frame

jim holtman jholtman at gmail.com
Thu Aug 31 18:52:34 CEST 2006


Convert the column with the months to an actual date.  I am going to
assume this is all the same year, so try this:

> x <- read.table('clipboard', as.is=T)
> x
   V1 V2 V3 V4
1 jan  3  1  7
2 mar  2  4  2
3 may  1  3  2
4 jul  3  7  4
5 sep  5  2  3
6 nov  3  1  5
> x$Date <- as.POSIXct(strptime(paste(x$V1, '1 2006'), format='%b %d %Y'))
> x
   V1 V2 V3 V4       Date
1 jan  3  1  7 2006-01-01
2 mar  2  4  2 2006-03-01
3 may  1  3  2 2006-05-01
4 jul  3  7  4 2006-07-01
5 sep  5  2  3 2006-09-01
6 nov  3  1  5 2006-11-01
> plot(x$Date, x$V2)
>


On 8/31/06, Monica Pisica <pisicandru at hotmail.com> wrote:
> Hi list,
>
> I have a question about 'plot'. I am trying to plot values registered every
> month - or every other month. If i build a data.frame called mydata like
> this (as an example)
>
> jan   3   1   7
> mar  2   4   2
> may 1   3   2
> jul    3   7   4
> sep  5   2   3
> nov  3   1   5
>
> and use the command line:
>
> plot(mydata[c(1,3)])
>
> I get a graph that has on the x axis my months in alphabetical order - which
> i don't want, and instead of points i have thick horizontal lines. I've
> tried everything i could and understood from the R help files to give me
> points and on x axis the month in my order instead of alpha order. No
> success. What is the trick?
>
> I fixed the month order by using numerals in front of them like 01, 03, ...
> etc, but this is not an elegant solution.
>
> Any help will be much appreciated.
>
> Monica
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list