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

From: hadley wickham <h.wickham_at_gmail.com>
Date: Fri, 08 Jun 2007 10:49:41 +0200

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



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. Received on Fri 08 Jun 2007 - 08:55:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Jun 2007 - 09:31:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.