[R] problems with plot.data.frame
Prof Brian Ripley
ripley at stats.ox.ac.uk
Thu Aug 31 19:06:12 CEST 2006
On Thu, 31 Aug 2006, Monica Pisica 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
This has no column names, so it looks like this is 3 columns with row
names. I think it is actually four columns, but it would never print like
that.
Quite likely then the first column is a factor with levels in alphabetical
order. If I copy your layout and do
> read.table("clipboard") -> A
> A
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
> levels(A[[1]])
[1] "jan" "jul" "mar" "may" "nov" "sep"
and you seem to want
a <- as.character(A[[1]])
A[[1]] <- factor(a, levels=a)
and then
plot.default(A[c(1,3)])
(You are showing a boxplot, since you are plotting a numeric variable
against a factor.)
>
> 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.
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
More information about the R-help
mailing list