I am working with the R programming language. I used the melt() function from the "rehsape" library so that my data looks something like this:
library(dplyr)library(ggplot2)library(reshape2)library(scales)Table_1 <- data.frame("Col_A" = c("2002-01", "2002-01", "2002-01", "2002-02", "2002-02", "2002-02", "2002-03", "2002-03", "2002-03"),"Col_B" = c("AAA", "AAB", "AAC", "AAA", "ABB", "AAC", "AAA", "AAB", "AAC"),"Col_C" = c(111, 122.5, 9, 727, 66.4, 3, 992, 88, 12))
Col_A is a date in the form : year-month
The columns from the table are in the following format:
Table_1$Col_A = as.character(Table_1$Col_A)Table_1$Col_B = as.factor(Table_1$Col_B)Table_1$Col_C = as.numeric(Table_1$Col_C)
From here, I use the melt() function:
melt = melt(Table_1, id = c("Col_A"))
Now, I want to plot this data in the following form:
p = ggplot(melt, aes(x = Col_A, y=value, group = 1)) + geom_line(aes(color=variable)) + facet_grid(variable ~., scales = "free_y")
My real data is a bit more complicated and I am trying to modify the dates (I have a lot of dates) so that they do not appear as cluttered.
I am trying:
p = ggplot(melt, aes(x = Col_A, y=value, group = 1)) + geom_line(aes(color=variable)) + facet_grid(variable ~., scales = "free_y") + scale_x_date(date_labels = "m%-%y", date_breaks = '1 month') + theme(axis.text, x = element_text(angle = 45))
followed by:
final = p + scale_y_continuous(labels = comma)
But, I am getting this error: Error: Invalid input: date_trans works with objects of class Date only
Can someone please show me what I am doing wrong?Thanks