0
votes

How to plot the data below in ggplot with x axis to show ticks in format as 'Jan-99'.

My data is as below:

head(rates,10)

    Month Repo_Rate
1  Apr-01      9.00
2  May-01      8.75
3  Jun-01      8.50
4  Jul-01      8.50
5  Aug-01      8.50
6  Sep-01      8.50
7  Oct-01      8.50
8  Nov-01      8.50
9  Dec-01      8.50
10 Jan-02      8.50

sapply(rates,class)

#  Month   Repo_Rate 
# "character"   "numeric" 

I have done the plotting using xts/zoo/ts packages but would like to do using ggplot as this gives my publication quality figures.

1
Well first thing you nedd to do is convert your character vector to date format... see ?as.Date, and perhaps stackoverflow.com/questions/6242955/…. Then plotting should be straight forward. stackoverflow.com/questions/26458822/… , stackoverflow.com/questions/10576095/…, and lots more examples on SOuser20650
Can you check the update by @G.Grothendieck on your previous post with ggplot.akrun

1 Answers

1
votes

you can try the following:

rates$date <- as.character(rates$month, stringAsFactors = FALSE)
rates$date <- as.Date(rates$date, "%B-%d") 

# Now plot the graph #######

ggplot(rates)+
  geom_line(aes(x=date, y= Repo_Rate))+
  scale_x_date(labels = date_format("%B-%d))

In any case if you need to change the date format please refer to : "http://docs.ggplot2.org/current/scale_date.html"