Quantcast
Channel: Getting the following error despite having variables in suitable format: Error: Invalid input: date_trans works with objects of class Date only - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Getting the following error despite having variables in suitable format: Error: Invalid input: date_trans works with objects of class Date only

$
0
0

I am just trying to plot a small 27 point dataset with X-axis as Date (CommonDate) in date R format, and y-axis as a continuous variable.

Despite having the date variable in Date format, and even after commenting out the part where scale_x_date() is being utilized, I am getting this error. I have tried multiple ways of debugging it based on some of the answers to this particular error, but to no avail.

Sample dataset: I have sample a 12 point dataset out of the 27 point one

> example     Brand     Period X2014_2013 X2015_2014 CommonDate Year6        B 2014-06-01  -9.168405 -19.508786 2000-05-31 201411       B 2014-11-01  33.747651   0.000000 2000-10-31 201419       B 2014-07-01  50.199601   0.000000 2000-06-30 201420       B 2014-08-01  69.084423   0.000000 2000-07-31 201422       B 2014-10-01 130.377668   0.000000 2000-09-30 20143        B 2014-03-01  29.807692   9.856387 2000-02-29 2014NA    <NA>       <NA>         NA         NA       <NA>   NANA.1  <NA>       <NA>         NA         NA       <NA>   NA2        B 2014-02-01  21.843116 -13.037997 2000-02-01 201416       B 2014-04-01 601.443299  43.298060 2000-03-31 20145        B 2014-05-01  15.477101 -23.492664 2000-04-30 201423       B 2014-11-01 126.591315   0.000000 2000-10-31 2014     Month6        611      1119       720       822      103        3NA      NANA.1    NA2        216       45        523      11

This is the code I am running. Here instead of data = perc_change_YOY_abs, you may use data = example

newb_brand_abs_perc_YOY_2015 = ggplot(data = perc_change_YOY_abs, aes(x = CommonDate, y = X2015_2014, colour = Brand))+geom_point()+geom_line()+geom_text(aes(label = paste(round(X2015_2014,0), "%"), hjust = 0, vjust = 1), size = 4)+scale_x_date(breaks = date_breaks("months"),labels = date_format("%b"))+scale_y_continuous(breaks = pretty_breaks(n = 8))+theme_bw()+xlab("")+ylab("%Change 2015 vs. 2014")+annotate("text", x = 4, y = 25, label = "Some text")plot(newb_brand_abs_perc_YOY_2015)

Sessioninfo:

> sessionInfo()R version 3.2.0 (2015-04-16)Platform: x86_64-w64-mingw32/x64 (64-bit)Running under: Windows 7 x64 (build 7601) Service Pack 1locale:[1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252   [3] LC_MONETARY=English_United States.1252[4] LC_NUMERIC=C                          [5] LC_TIME=English_United States.1252    attached base packages:[1] grid      stats     graphics  grDevices utils     datasets [7] methods   base     other attached packages:[1] lubridate_1.3.3 reshape2_1.4.1  plyr_1.8.3     [4] gridExtra_0.9.1 scales_0.2.5    lattice_0.20-31[7] ggplot2_1.0.1  loaded via a namespace (and not attached): [1] Rcpp_0.11.6      digest_0.6.8     MASS_7.3-40      [4] gtable_0.1.2     magrittr_1.5     stringi_0.5-4    [7] proto_0.3-10     tools_3.2.0      stringr_1.0.0   [10] munsell_0.4.2    colorspace_1.2-6 memoise_0.2.1

Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images