I have a data frame which contains 2 weeks of data that indicate how many passengers have been on a train each day. Each observation contains 3 values, the date, the number of passengers, and the day of the week. I want to compare the passengers on each day from the previous week to this week (Monday to Monday, Tusday to Tuesday etc). Here is the data:
structure(list(total = structure(c(17455, 17456, 17457, 17458,
17459, 17460, 17461, 17462, 17463, 17464, 17465, 17466, 17467,
17468), class = "Date"), passengers = c(9299L, 9166L, 10234L,
10176L, 10098L, 2867L, 5416L, 9312L, 10555L, 10858L, 10169L,
9515L, 2679L, 5490L), dow = c("Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday",
"Wednesday", "Thursday", "Friday", "Saturday", "Sunday")), .Names =
c("total", "passengers", "dow"), class = "data.frame")
(The automated system that created the reports used the term "total" for dates, I felt the need to point that out as it might be confusing).
When I create a ggplot, it only maps 1 y value for a bar chart instead of 2 side by side:
ggplot(x, aes(x=dow, y=passengers), fill=variable) +
geom_bar(stat = "identity", position = "dodge")
I have seen reshape used to melt the data for instances such as this, but when I melt using the day of the week as the id.vars value, the date is converted to scientific notation (small problem) but ggplot cannot find the passengers variable (big problem).