[R] Barplots: Editing the frequency x-axis names

hadley wickham h.wickham at gmail.com
Fri Jun 8 10:49:41 CEST 2007


On 6/8/07, Tom.O <tom.olsson at dnbnor.com> wrote:
>
> Hi
> I have a timeSeries object (X) with monthly returns. I want to display the
> returns with a barplot, which I can fix easily. But my problem is labaling
> the x-axis, if I use the positions from the timeseries It gets very messy. I
> have tried rotating and changing the font size but it doesn't do the trick.
> I think the optimal solution for my purpose is too only display every second
> or third date, pherhaps only use every 12 month. But how do I do that?

It's quite easy to do that with ggplot2, see below, or
http://had.co.nz/ggplot2/scale_date.html for examples.

df <- data.frame(
 date = seq(Sys.Date(), len=100, by="1 day")[sample(100, 50)],
 price = runif(50)
)

qplot(date, price, data=df, geom="line")
qplot(date, price, data=df, geom="bar", stat="identity")
qplot(date, price, data=df, geom="bar", stat="identity") +
scale_x_date(major="2 months")
qplot(date, price, data=df, geom="bar", stat="identity") +
scale_x_date(major="10 day", format="%d-%m")
qplot(date, price, data=df, geom="bar", stat="identity") +
scale_x_date(major="5 day", format="%d-%m")

Hadley



More information about the R-help mailing list