I'm using ggvis
stacked barplots to create a graph where the x-axis is a time series of dates and the y-axis are frequencies.
The dates however, are in the format "Apr 2015" i.e. months and years.
In ggvis
, this means that I have to make the dates in my dataframe factors.
I'm having trouble converting these month-year dates into factors that are ordered by their date. Instead, I get this order "Apr 2015, Jun 2015, May 2015"
This is my code:
selecteddates <- with(dailyIndMelt, dailyIndMelt[date >= as.Date(input$monthlydateInd[1]) & date <= as.Date(input$monthlydateInd[2]),])
selecteddates <- aggregate(selecteddates[,3],by=list(selecteddates$variable,substr(selecteddates$date,1,7)),sum)
colnames(selecteddates) <- c("industry", "date", "vacancyno")
selecteddates$date <- as.Date(paste(selecteddates$date,"-28",sep=""))
selecteddates <- selecteddates[order(as.Date(selecteddates$date)),]
selecteddates$date <- format(selecteddates$date, "%m %Y")
selecteddates$date <- factor(selecteddates$date)
levels(selecteddates$date) <- levels(selecteddates$date)[order(as.Date(levels(selecteddates$date), format="%m %Y"))]
levels(selecteddates)