[R-SIG-Finance] Vertical lines in chart_Series
Gordon Erlebacher
gordon.erlebach at gmail.com
Thu May 31 17:26:24 CEST 2012
Hi,
Here is my solution to horizontal lines (which work) and vertical
lines (which do not work) in chart_Series (I added an argument, ...)
(I attach the full code).
Here is a snippet. Vertical lines do not work using segments() with
arguments x0,y0, y1. On the other hand, vertical lines work with all
four arguments (x0,y0,x1=x0,y1). STRANGE NO?
On the other hand, horizontal lines work perfectly fine using segments
(with x0, y0, x1 as arguments)
myChart_Series = function (x, name = deparse(substitute(x)), type =
"candlesticks",
subset = "", TA = "", pars = chart_pars(), theme = chart_theme(),
clev = 0, ...)
{
cs <- new.replot()
# … additional code …
ylim = cs$get_ylim()[[2]]
xlim = cs$get_xlim()
#Horizontal lines
if (!is.null(y.coords)) {
cs$Env$x0 = xlim[1]
cs$Env$y0 = y.coords
cs$Env$x1 = xlim[2]
seg.exp = c(expression(segments(x0,y0,x1,col='blue')))
cs$add(seg.exp, env=cs$Env, expr = TRUE)
}
# vertical lines
# x0 <- x; y0 <- ymin; y1 <- ymax
if (!is.null(x.coords)) {
cs$Env$x0 = x.coords
cs$Env$y0 = ylim[1] # does not work when I replace with numbers
cs$Env$y1 = ylim[2]
cs$Env$x1 = cs$Env$x0
# VERTICAL LINES DO NOT WORK with segments!!
# unless I add x1 to the argument list (should not be required)
seg.exp = c(expression(segments(x0,y0,x1,y1,col='red')))
# line through the plot
#seg.exp = c(expression(abline(v=x0,col='red'))) #***WORKS
cs$add(seg.exp, env=cs$Env, expr = TRUE) # *** DOES NOT WORK
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myChart_Series.r
Type: application/octet-stream
Size: 9244 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-sig-finance/attachments/20120531/5077cb4d/attachment.obj>
More information about the R-SIG-Finance
mailing list