Set MaxY value for plot

25 views
Skip to first unread message

Mark Knecht

unread,
Sep 3, 2009, 3:28:15 PM9/3/09
to Bay Area R Helpers
Hi,
I've got a small function I call to implement a standard 5 line
plot that I like to look at for each trading system. The problem with
this code is that sometimes the first system plotted doesn't have the
largest final result so the plot doesn't show the final results on the
last 4 systems.

How can I set the max Y axis value to MyMaxY?

Thanks,
Mark


FiveLinePlot = function(TradeSystem, SysA, SysB, SysC, SysD) {
A = cumsum(TradeSystem$PL_Pos)
B = cumsum(SysA$PL_Pos)
C = cumsum(SysB$PL_Pos)
D = cumsum(SysC$PL_Pos)
E = cumsum(SysD$PL_Pos)

MyMaxY = max(
max(A),
max(B),
max(C),
max(D),
max(E)
)

plot(A, typ="l", main=deparse(substitute(TradeSystem)), ylab="Profit")
lines(B, col="green")
lines(C, col="red")
lines(D, col="purple")
lines(E, col="magenta")
}

Daniel Levine

unread,
Sep 3, 2009, 3:35:42 PM9/3/09
to Mark Knecht, Bay Area R Helpers
I'm not positive this is the question but here goes.

When you plot set ylim = c(0, MyMaxY), that will solve the problem of
including all of it, but the number might show up on the axis, I would
also bump that up a bit so you have some room on top:

plot(x,..,..,ylim=c(0,MyMaxY))

You might not want 0 as the bottom of the plot though.

To get tick marks wherever you want you coule add an axis() call
afterwards and make the ticks some function of MyMaxY as well.

You might want to ?plot for these kind of questions. The help is
pretty straightforward.

You could also plot the the biggest set first though that doesn't
appear to be the best way.

Hope that helps.

Dan
--
Daniel Levine
TechCrunch Research Analyst
(m) 202.256.1912

Mark Knecht

unread,
Sep 3, 2009, 4:04:58 PM9/3/09
to Daniel Levine, Bay Area R Helpers
Thanks Dan. That does the job fine.

Yes, I'll probably want to bump the value up a bit. I might also want
to explore going a bit below 0 also as sometimes a trading system will
lose a little money before it starts making money.

Anyway, thanks. I looked at the help file for an hour and somehow that
parameter never registered mentally/ With your help now it does.
thanks!

Cheers,
Mark
Reply all
Reply to author
Forward
0 new messages