-3

My dataframe has two columns date and value

2004-10-12     2

my problem is my data is too large ie more than 10 years.

How can I plot for monthly frequency for just one year.

zx8754
  • 52,746
  • 12
  • 114
  • 209
  • Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Jan 31 '17 at 19:48
  • Dear zx8754, this was my very first question on stackoverflow, thank you for guiding me and helping me improve on my questions in future. – Amit Kumar Feb 09 '17 at 12:46
  • Please try to improve this post by clickin on [edit](http://stackoverflow.com/posts/41965692/edit). If the answer provided below is useful, consider [upvoting and/or accepting it as an answer](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work). – zx8754 Feb 09 '17 at 12:50
  • Yes I now learn how to accept a answer. I ticked the grey tick but somehow it still doesn't allow me to up vote and says I have very little reputation for before my up vote could be registered. Thank you. – Amit Kumar Feb 10 '17 at 23:54

1 Answers1

0

First ensure that your dates are well formatted (yyyy-mm-dd). Then the following should work. First three lines should be skipped as you already have a dataset.

dates <- c('2004-10-12', '2004-10-13', '2005-01-30')
freqs <- c(5, 6, 7)
data <- as.data.frame(cbind(dates, freqs), stringsAsFactors=F)


data[,1] <- as.Date(data[,1], "%Y-%m-%d") ##formatting as a date
break1 <- as.Date('2005-01-01', "%Y-%m-%d") ##2005
break2 <- as.Date('2004-01-01', "%Y-%m-%d") ##2004
yearsubset <- data[data[,1] < break1 & data[,1] > break2 , ]

plot(yearsubset, type="o", pch=16)

In data, column 1 (data[,1]) is the dates. Column 2 is the frequencies. You would have two play around with colors to make it look nice, so look up colors with the plot function.

Sam Ulloa
  • 186
  • 2
  • 12