Skip to content
Prev 13133 / 15274 Next

Problems with xts and plotting charts in quantmod

Hi Carlos,

My explanation was incomplete sorry. You need to format the data correctly
first, and removing the first column is necessary. Also, naming the columns
Open, High, Low, Close also helps. Here is the code that should work (I
tested it):

data <- read.csv("file.csv", header=FALSE)
data.xts <- xts(data[, -1], order.by=as.POSIXct(data$V1, format="%Y%m%d
%H%M%S"))
colnames(data.xts) <- c("Open", "High", "Low", "Close")
chartSeries(data.xts, type="candlesticks")

Note, it is %Y%m%d, not %Y%h%m as in what you put in your example.

It is also good to do a head(data), head(data.xts) after each command to
see how the structure of the data and the xts object changes after each
command, to see it does what you want it to do.

Oh, and please also cc the list (reply-all) so that others can follow :)

Wouter
On Thu Feb 05 2015 at 1:12:17 PM Liu <carloslewlew at gmail.com> wrote: