Think of a data frame providing three columns:
- year
- month
- value
I want to plot value by year/month in its natural order. But so far I didn't find a good way to accomplish this in ggplot. Below you'll find a simplified example showing my desired result but by applying a workaround - concatenating year and month or a and b in the example. But this solution brings already several disadvantages with it.
Is there a generic way to accomplish this in ggplot?
> library(ggplot2)
> df <- data.frame(a = c(1,1,1,2,2,2), b = c(1,2,3,1,2,3), v = 1:6)
> df
a b v
1 1 1 1
2 1 2 2
3 1 3 3
4 2 1 4
5 2 2 5
6 2 3 6
> dfX <- data.frame(ab = paste(df$a,df$b), v = df$v)
> dfX
ab v
1 1 1 1
2 1 2 2
3 1 3 3
4 2 1 4
5 2 2 5
6 2 3 6
> ggplot(dfX, aes(x = ab, y = v)) + geom_point()

How would I get the above plot using df directly?