0

I can not get my month labels (let say Jan/15) on x. Tried all things, what the trick ? If I use YYYYMM it's kinda ok, but I need more readable. Is it possible to change background color too?

require(shiny)
require(rCharts)

x <- data.frame(Category=factor(c("Alpha", "Alpha","Alpha","Alpha","Alpha")), 
                    YYYYMM= factor(c("2/1/2015","3/1/2015","4/1/2015","5/1/2015","6/1/2015")),
                    COUNT=c(44,22,37,76,97))

str(x)
to_jsdate2 <- function(x){
  as.numeric(as.POSIXct(as.Date(x), origin="1970-01-01")) * 1000}

x$DATEPX <-  to_jsdate2(as.Date(x$YYYYMM))

myplot <- hPlot(COUNT ~ YYYYMM, data=x, type="line")
#myplot$xAxis(title = list (text = "Time"), type= "datetime")
myplot

And I doing this x labels dissappeared

myplot <- hPlot(COUNT ~ DATEPX, data=x, type="line")
myplot$xAxis(title =list (text = "Month") , type= "datetime")
myplot
ekstroem
  • 5,957
  • 3
  • 22
  • 48
Mario Trento
  • 513
  • 1
  • 4
  • 14

1 Answers1

1

To get the labels like "Jan/15" you need to pass the dates through strptime to get them into time since epoch and then through strftime to get them formatted accordingly. No need to multiply the dates by 1000 etc. For your case, let me know if the following works out. You can read more about the formatting of dates by doing ?strptime and ?strftime in R REPL.

x$dmy = strftime(strptime(x$YYYYMM, format = "%m/%d/%Y"), format = "%b/%y")
myplot <- hPlot(COUNT ~ dmy, data=x, type="line")
myplot

Not sure how to change the background color in rcharts

Frash
  • 724
  • 1
  • 10
  • 19
  • Found only one related post: http://stackoverflow.com/questions/21081469/. All it points to is editing the stylesheet generated with the chart. Maybe you can open an issue in `rcharts` github repo to get the background color done directly through `rcharts` plotting function call. – Frash Oct 03 '15 at 19:34