I have the following data frame d:
TS Turbidity
1 2014-12-12 00:00:00 87
2 2014-12-12 00:15:00 87
3 2014-12-12 00:30:00 91
4 2014-12-12 00:45:00 84
5 2014-12-12 01:00:00 92
6 2014-12-12 01:15:00 89
TS is my time combining the year, month, day, hour, minutes, and second. When I look at the nature of my data, TS is:
$ TS : POSIXct, format: "2014-12-12 00:00:00" "2014-12-12 00:15:00"
So for me , R understand that TS is date format.
I want to create boxplot per month (I precise that I have several years of data). I create a new column Month as follow:
d$Month<-as.Date(cut(d$TS, breaks="month"))
Then I plot this function:
ggplot(d, aes(x = factor(Month), y = Turbidity))+ geom_boxplot() + theme_bw()
This function plots well my data but I have too many x-labels and would like to plot labels for every 4 months for example. I add scale_x_date:
ggplot(d, aes(x = factor(Month), y = Turbidity))+ geom_boxplot() + theme_bw() +
scale_x_date(date_breaks = "4 month", date_labels = "%B")
It is at this step that I have trouble. I got this error message :
" Error: Invalid input: date_trans works with objects of class Date only".
But R precise that Month is in a date format.
$ Month : Date, format: "2014-12-01" "2014-12-01" "2014-12-01"
I look at forums but I cannot figure out where is the problem because for me I have already state that Month was a date.
Thanks for any help!