[R] problems with plot.data.frame

Gabor Grothendieck ggrothendieck at gmail.com
Fri Sep 1 03:00:58 CEST 2006


On 8/31/06, Monica Pisica <pisicandru at hotmail.com> wrote:
> Hi again,
>
> OK i came up with this after i got few good sugegstions.
>
> First my data.frame actually looks like that (Thanks for clarifications to
> Prof. Brian Ripley)
>
>   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
>
> What i want: 1. On x axis i want the ticks with labels column V1 in that
> order and not alpha order.
> 2. i want points to represent the data, not horizoltal bars as a box-plot
> with only one value as it will plot if i use plot.data.frame
>
> Note. In my table i already have the order i want, but if i wouldn't have it
> prof. Ripley's sugegstion is very welcome.
>
> What i've done in the end:
>
> >plot (mydata$V3, xlab="month")
> >axis (side=1, at=c(1:6), labels=c(1:6), ticks=TRUE, col.axis="white")
> >month.label <- as.character(mydata[[1]])
> >axis(side=1, at=c(1:6), labels = month.label, ticks=TRUE)
>
> This is not an elegant solution but i get the graph i wanted. If anybody has
> a better solution certainly i would like to see it.
>
> thanks you again for all your help,
>

Try plotting without the axis using xaxt = "n" and then call axis:

plot(mydata$V3, xlab = "month", xaxt = "n")
axis(1, 1:nrow(mydata), format(mydata$V1))

or convert V1 to "Date" class and then plot:

dd <- as.Date(paste("2006", mydata$V1, 1), "%Y %b %d")
plot(V3 ~ dd, mydata)



More information about the R-help mailing list