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
}
_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.