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? Thanks Tom -- View this message in context: http://www.nabble.com/Barplots%3A-Editing-the-frequency-x-axis-names-tf3888029.html#a11021315 Sent from the R help mailing list archive at Nabble.com.
Tom.O schrieb:> 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? > > Thanks Tom >I think you could use: library(chron): f.e x <- c(dates(02/27/92),dates(02/27/95)) y <- c(10,50) plot(x, y) Regards Knut
Knut Krueger
2007-Jun-08 08:05 UTC
[R] Barplots: Editing the frequency x-axis names -doouble post
Sorry for double posting - was wrong e-mail adress , thougt this one will run into Spam filter
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