4
I’m having trouble plotting a Candlesticks chart from a file data.frame
.
Code example
# Pacotes necessários ----------------------------------------------
library(BatchGetSymbols)
library(quantmod)
# Inputs necessários ------------------------------------------------------
#data inicial
first.date <- as.Date("2018-01-01")
#data final
last.date <- Sys.Date()
#frequencia das observações
freq.data <- 'daily'
# Ativos a serem baixados
tickers <- c("^BVSP")
# Importando ativos -------------------------------------------------------
ibov <- BatchGetSymbols(tickers = tickers,
first.date = first.date,
last.date = last.date,
freq.data = freq.data,
cache.folder = file.path(tempdir(),
'BGS_Cache') )
ibov<-as.data.frame(ibov)
With this code are imported the data for an example. What I would like to learn would be how to plot this data using the function.
chartSeries
From the date.frame ibov
, I tried to do it this way:
ibov <- xts(ibov, order.by = ibov$df.tickers.ref.date)
chartSeries(ibov)
But the error is appearing:
Error in (function (cl, name, valueClass) :
assignment of an object of class “character” is not valid for @‘yrange’ in
an object of class “chob”; is(value, "numeric") is not TRUE
this is not clear in your question, but anyway.. what you need is to take out all the columns that are not numeric from the data.frame. I will update with a possible solution
– Daniel Falbel
Thank you very much Daniel, this other solution has solved the problem perfectly, thank you very much
– Henrique Faria de Oliveira