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.
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.
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.