Question

So I am trying to make a plot with the x-axis reading as the dates in my data.frames. However it keeps reading as 0,1,2,3,4,5,....,,20, instead of April-01,April-02...April-29

 data.setup<-function(data,loc='yahoo',start.date=Sys.Date()-months(1),
                                      end.date=Sys.Date()) {
  getSymbols(data,src=loc)
  x<-as.data.frame(window(get(data),
            start=as.character(start.date),
            end=as.character(end.date)))
  x$dates<-row.names(x)
  colnames(x)<-c('Open','High','Low','Close','Volume','Adjusted','Dates')
  x<-x[c(7,1,2,3,4,5,6)]
  return(return(x))
}

data<-data.setup('AAPL',start.date=Sys.Date()-months(1))  
h1<-Highcharts$new()
h1$chart(type='line')
h1$xAxis(category=data$Dates,id='dates')
h1$series(data=data$Low,name='Low',xAxis='dates')
Was it helpful?

Solution

not category but categories.

# data
df <- data.frame(x = 1:10, y = rnorm(10), s = rnorm(10), z = letters[1:10])

# create plot object
p <- hPlot(y ~ x, data = df, size = "s", type = "line")

# set axis
p$xAxis(categories = as.character(seq(Sys.Date(), by = 1, length.out = 10)))

# show
p
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top