2013-01-21 11 views
6

मैं में सरल OHLC डेटा है और XTSमैं plot.xts का उपयोग कर मोमबत्ती चार्ट में मोमबत्तियों की चौड़ाई कैसे सेट करूं?

SF <- structure(c(1.064, 1.07, 1.071, 1.08, 1.08, 1.076, 1.078, 1.08, 
1.08, 1.082, 1.081, 1.082, 1.074, 1.07, 1.073, 1.075, 1.081, 
1.084, 1.092, 1.091, 1.097, 1.095, 1.099, 1.094, 1.096, 1.097, 
1.096, 1.096, 1.097, 1.091, 1.078, 1.083, 1.088, 1.084, 1.081, 
1.095, 1.096, 1.085, 1.074, 1.075, 1.073, 1.07, 1.068, 1.072, 
1.084, 1.08, 1.081, 1.077, 1.081, 1.083, 1.084, 1.083, 1.082, 
1.082, 1.075, 1.074, 1.075, 1.092, 1.086, 1.092, 1.093, 1.098, 
1.102, 1.103, 1.099, 1.098, 1.1, 1.101, 1.098, 1.098, 1.1, 1.092, 
1.084, 1.087, 1.088, 1.084, 1.096, 1.099, 1.097, 1.086, 1.078, 
1.076, 1.076, 1.073, 1.064, 1.069, 1.071, 1.077, 1.075, 1.074, 
1.078, 1.078, 1.08, 1.079, 1.078, 1.073, 1.068, 1.07, 1.069, 
1.074, 1.08, 1.083, 1.089, 1.09, 1.096, 1.094, 1.092, 1.092, 
1.094, 1.094, 1.09, 1.092, 1.088, 1.08, 1.076, 1.078, 1.081, 
1.079, 1.08, 1.09, 1.084, 1.072, 1.073, 1.069, 1.066, 1.07, 1.067, 
1.072, 1.08, 1.079, 1.076, 1.077, 1.08, 1.08, 1.082, 1.081, 1.081, 
1.074, 1.072, 1.073, 1.074, 1.081, 1.084, 1.091, 1.092, 1.097, 
1.097, 1.099, 1.095, 1.095, 1.097, 1.097, 1.096, 1.094, 1.091, 
1.08, 1.083, 1.086, 1.083, 1.082, 1.095, 1.096, 1.086, 1.074, 
1.075, 1.073, 1.071, 1.072), .Dim = c(42L, 4L), .Dimnames = list(
NULL, c("Open", "High", "Low", "Close")), index = structure(c(1353427200, 
1353513600, 1353600000, 1353859200, 1353945600, 1354032000, 1354118400, 
1354204800, 1354464000, 1354550400, 1354636800, 1354723200, 1354809600, 
1355068800, 1355155200, 1355241600, 1355328000, 1355414400, 1355673600, 
1355760000, 1355846400, 1355932800, 1356019200, 1356278400, 1356451200, 
1356537600, 1356624000, 1356883200, 1357056000, 1357142400, 1357228800, 
1357488000, 1357574400, 1357660800, 1357747200, 1357833600, 1358092800, 
1358179200, 1358265600, 1358352000, 1358438400, 1358697600), tzone = "", tclass = c("POSIXct", 
"POSIXt")), .indexCLASS = c("POSIXct", "POSIXt"), tclass = c("POSIXct", 
"POSIXt"), .indexTZ = "", tzone = "", class = c("xts", "zoo")) 

plot.xts(SF, type='candles') 

मोमबत्ती बहुत पतली बाहर आ रहे हैं। मैं उन्हें व्यापक कैसे बना सकता हूं?

plot.xts के स्रोत कोड को देखकर मैं देखता हूं कि xts आंतरिक फ़ंक्शन plot.ohlc.candles को ओएचएलसी डेटा को मोमबत्तियों के रूप में प्लॉट करने के लिए कहा जाता है, जिसके लिए ... पास हो जाता है। एच

plot.ohlc.candles(x, bar.col = bar.col, candle.col = candle.col, 
      ...) 

हालांकि, अगर मैं अपने plot.xts समारोह कॉल में तर्क चौड़ाई = 0.5 सेट करने का प्रयास, मैं चेतावनी है कि चौड़ाई ग्राफिक पैरामीटर

Warning messages: 
1: In plot.window(...) : "width" is not a graphical parameter 
2: In plot.xy(xy, type, ...) : "width" is not a graphical parameter 
3: In axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...) : 
    "width" is not a graphical parameter 
4: In axis(1, at = xycoords$x[ep], labels = names(ep), las = 1, lwd = 1, : 
    "width" is not a graphical parameter 
5: In axis(2, ...) : "width" is not a graphical parameter 
6: In title(width = 0.5) : "width" is not a graphical parameter 
There were 12 warnings (use warnings() to see them) 
> warnings() 
Warning messages: 
1: "width" is not a graphical parameter 
2: "width" is not a graphical parameter 
3: "width" is not a graphical parameter 
4: "width" is not a graphical parameter 
5: "width" is not a graphical parameter 
6: "width" is not a graphical parameter 
7: "width" is not a graphical parameter 
8: "width" is not a graphical parameter 
9: "width" is not a graphical parameter 
10: "width" is not a graphical parameter 
11: "width" is not a graphical parameter 
12: "width" is not a graphical parameter 

मैं या quantmod का उपयोग करने में असमर्थ हूँ नहीं है मिल xtsExtra क्योंकि मैं दो अलग-अलग भूखंडों (एक टाइमरीज़ और अन्य सामान्य एक्सवाई लाइन ग्राफ) को साइड करने की कोशिश कर रहा हूं।

उत्तर

7

आप चेतावनियों को अनदेखा कर सकते हैं, लेकिन आपको width को बहुत बड़ी चीज़ पर सेट करने की आवश्यकता है। plot.ohlc.candles पर देखकर, आप देख सकते हैं कि width xts ऑब्जेक्ट की अनुक्रमणिका पर आधारित है, जो सेकंड में है।

R> xts:::plot.ohlc.candles 
function (x, width = 0.2, order = 1:4, bar.col = "grey", candle.col = "white", 
    ...) 
{ 
    segments(.index(x), x[, order[2]], .index(x), x[, order[3]], 
     col = bar.col, ...) 
    rect(.index(x) - width, x[, order[1]], .index(x) + width, 
     x[, order[4]], col = candle.col, ...) 
} 
<environment: namespace:xts> 

यह 1/4 दिन के लिए चौड़ाई सेट हो जाएगा:

plot.xts(SF, type='candles', width=60*60*24*0.25) 

1/4 day candle chart

+0

बस इसे स्वयं भी समझ लिया :) स्पष्टीकरण के लिए +1 :) –

1

चूंकि मोमबत्तियां केवल रेखाएं हैं, इसलिए आप लाइन चौड़ाई बढ़ाने के लिए lwd पैरामीटर का उपयोग कर सकते हैं। दुर्भाग्य से उसमें कोई त्रुटि यदि आपने इसे सीधे उपयोग करते हैं:

plot.xts(SF, type='candles',lwd=2) 
Error in axis(1, at = xycoords$x[ep], labels = names(ep), las = 1, lwd = 1, : 
    formal argument "lwd" matched by multiple actual arguments 

यह कैसे काम करता है plot.xts आवरण में एक मुद्दा तरह दिखता है। हालांकि इस ग्रिडलाइनें और चार्ट सीमा भी प्रभावित करता है

opar <- par(lwd=2) 
plot.xts(SF, type='candles') 
par(opar) # reset to original parameters 

:

आप इसे par का उपयोग कर निर्धारित कर उसे काम करने के लिए मिल सकता है।

+0

दुर्भाग्यवश, lwd = 2 आपके द्वारा उल्लिखित सभी चीज़ों को प्रभावित कर रहा है, चार्ट को अनावश्यक प्रस्तुत करता है। कुल्हाड़ी, ग्रिडलाइन इत्यादि को संरक्षित करने वाले कुछ की तलाश में –

6

यहोशू उल्लेख किया है, यहाँ क्या मैं सही चार्ट प्राप्त करने के लिए किया था

candlecolors <- ifelse(SF[,'Close'] > SF[,'Open'], 'RED', 'GREEN') 
plot.xts(SF, type='candles', width=25000, candle.col=candlecolors, bar.col='BLACK') 

इसने मुझे निम्नलिखित चार्ट दिया।

SF

+0

क्या क्षितिज अवधि के आधार पर इसे मैन्युअल रूप से सेट करने से बचने के लिए स्वचालित रूप से चौड़ाई (= 25000?) समायोजित करने का कोई तरीका है? – RockScience

+0

आमतौर पर वित्त में उतना ही महान नहीं है जितना कि आप केवल व्यापारिक दिन प्रदर्शित करना चाहते हैं, सप्ताहांत नहीं – RockScience

0

और क्या ज़ूम पैकेज के बारे में? फिर आप ज़ूम इन और आउट कर सकते हैं हालांकि आप "प्लॉट" कोड के अंत में

plot(datax) 
lines(datay) 
zm() 

के अंत में zm() के माध्यम से करना चाहते हैं?

संबंधित मुद्दे