Re: [問題] quantmod 繪製股價交易時序圖

作者: psinqoo (零度空間)   2015-04-14 07:56:22
HI~
試看看
x<-read.csv(file.choose())
x<-as.xts(read.zoo(x,header=T))
這樣子圖就就來
備註 我的.csv 長如此
Date Open High Low Close Volume
2012/1/2 8.81 8.81 8.62 8.67 777
2012/1/3 8.7 8.83 8.7 8.82 1375
2012/1/4 8.89 8.99 8.8 8.87 1661
2012/1/5 8.87 8.96 8.87 8.93 1546
※ 引述《andrew43 (討厭有好心推文後刪文者)》之銘言:
: library(quantmod)
: txt <- "Date Open High Low Close Volume
: 2013/1/2 13257 13289 13162 13194 168353
: 2013/1/3 13195 13198 13055 13055 242457
: 2013/1/4 13050 13100 13005 13079 256215
: 2013/1/7 13085 13128 13025 13126 228488
: "
: dat <- read.table(textConnection(txt), header=T, sep=" ", row.names="Date")
: ## 關鍵是 barChart() 要餵食一個 xts 物件
: ## 參考 ?xts 及 ?sample_matrix
: ## 以下是想辦法生成 xts 物件的過程
: dat.xts <- as.xts(as.matrix(dat))
: ## 畫畫看吧。結果對或錯都請推個文告訴我一聲。
: barChart(dat.xts)
: ※ 引述《psinqoo (零度空間)》之銘言:
: : 問題 圖跑不出
: : [問題類型]:
: : 程式諮詢
: : [軟體熟悉度]:
: : 入門
: : [問題敘述]:
: : 是不是資料格式錯誤? 還是其他方面有問題?
: : barChart 畫不出來 其他的也無法畫出
: : 底下是資料格式
: : 讀入 .csv
: : 資料格式 如下
: : Date Open High Low Close Volume
: : 2013/1/2 13257 13289 13162 13194 168353
: : 2013/1/3 13195 13198 13055 13055 242457
: : 2013/1/4 13050 13100 13005 13079 256215
: : 2013/1/7 13085 13128 13025 13126 228488
: : [程式範例]:
: : euo=read.csv(file.choose())
: : head(euo)
: : library(quantmod)
: : barChart(euo)
: : 出現
: : Error in try.xts(x, error = "chartSeries requires an xtsible object") :
: : chartSeries requires an xtsible object
: : quantmod
: : xts

Links booklink

Contact Us: admin [ a t ] ucptt.com