I'm *investigating* R as a means of *NOT* writing a dedicated GUI
app. I am not and don't want to be a Linux or Windows programmer. One
of my requirements is the ability to display multiple plots at the
same time. Think of a small matrix of charts, maybe 3x3, so 9 charts
displayed at the same time. Is there a way to do this in R, or with an
R add-on package?
Possibly Lattice is the right answer? Is it as difficult to use as
I seem to read from other newbies? I'm not against digging in but
don't want to waste time on a package that simply cannot do what I
need. If not Lattice then what are the other options?
So far I see nothing in ?plot that clues me in on how to do a
second plot and every experiment I run simply draws over the top of
the old plot so I suspect maybe it's not there.
Any examples of how to pull up multiple charts at the same time
would be greatly appreciated. I promise to post back some results as I
go.
Cheers,
Mark
Finally I noticed that the chart in the upper right which has the
shadow and the strange curve is actually the only data series with
over 1000 points. (1300+ actually) All the others are smaller -
350-800. Is there a limit to how many points the plot command can
handle? I don't see anything in ?plot so probably it's some sort of
overall limit, like 2^10 or something like that?
The problem is worse than that though. The other thing that happened
with this plot only was that R decided to rearrange the trade numbers
on the X axis. Instead of incrementing 1:1300 they have been reordered
with everything above 1000 between 1 and 2!
the code I used to generate this plot is shown here:
> Gallatin <- read.csv("C:\\MSA-Files\\Excel Rollup\\Gallatin.csv", header = TRUE, sep = ",", quote="\"", dec=".",fill = TRUE, comment.char="", skip=1,check.names=FALSE)
> Gallatin$EQUITY <- as.numeric(sub('[",]', '', Gallatin$EQUITY))
> plot(EQUITY ~ TRADE, Gallatin,type="l" )
It's the same code for each of the 9 charts with only the name of the
trading system changed. Again, the only difference that I can see is
this one system has more than 1000 trades...
Thanks,
Mark
My only addition here, btw, was doing a google search and changing the name of the class. The search I used was [r thousands separator, input] and it landed me pretty much dead on the right answer.
Input <- "A B
1,000 1
2,000 2
3,000 3
"
DF <- read.table(textConnection(Input), header = TRUE,
colClasses = c("num.with.comma", "numeric"))
str(DF)
Humm....OK - with it sitting there in front of me it almost looks like
I might understand it, but in truth I'm sure I don't. (Only my 2nd day
using R) I'll have to play with your code to really get it.
textConnection is new to me. library(methods) I don't recognize yet.
str is new.
Now, I think I've got the code in a script file and I ran it one line
at a time. No error messages but I don't understand the str output. It
seems to have changed 1,000 to X1.000.
I need to study this a bit more.
Thanks!
Mark
> library(methods)
> setClass("num.with.comma")
[1] "num.with.comma"
> setAs("character", "num.with.comma", function(from) as.numeric(gsub(",", "",from)))
> Input <- "A B 1,000 1 2,000 2 3,000 3"
> DF <- read.table(textConnection(Input), header = TRUE,colClasses = c("num.with.comma", "numeric"))
> str(DF)
'data.frame': 0 obs. of 8 variables:
$ A : num
$ B : num
$ X1.000: num
$ X1 : num
$ X2.000: num
$ X2 : num
$ X3.000: num
$ X3 : num
>
> DF
[1] A B X1.000 X1 X2.000 X2 X3.000 X3
<0 rows> (or 0-length row.names)
>
Humm....OK - with it sitting there in front of me it almost looks like
I might understand it, but in truth I'm sure I don't. (Only my 2nd day
using R) I'll have to play with your code to really get it.
textConnection is new to me. library(methods) I don't recognize yet.
str is new.
...
This is what I'm thinking but first I have to write a function to fix
the column headers which currently have their own set of problems.
Either that or dump the headers completely and just process everything
by column number, but I think using the headers might be better in the
long run in case my apps start putting things out in a different
order.
This feels like a lot of work but I'm still convinced this is probably
way better in the long run vs my original idea of doing a GUI app from
scratch. With my experience level this is going to take awhile.
Thanks so much for your help, and also to the others who have responded.
Cheers,
Mark
I'm sure that experienced R users can probably do this in a line or
two but I'm making good headway. Wrote my first function. Almost got
it right the first time, but it took a couple passes. Cleaned up all
the data that I need to clean up right now so that I can take the
second step which is creating all the indicator data to evaluate my
system. (Stuff I have in TradeStation and/or Excel as equations and
will move to R as functions.)
My simple code is:
readMSA = function (MyFile) {
x <- read.csv(MyFile, header = TRUE, sep = ",", quote="\"",
dec=".",fill = TRUE, comment.char="", skip=1,check.names=FALSE)
names(x)[1] <- "Trade"
names(x)[2] <- "SysNumber"
names(x)[3] <- "Date"
names(x)[4] <- "PL_Size"
names(x)[5] <- "PS_Method"
names(x)[6] <- "Size"
names(x)[7] <- "Pos_PL"
names(x)[8] <- "DDDollars"
names(x)[9] <- "DDPercent"
names(x)[10]<- "Equity"
x$Trade <- as.numeric(sub('[",]', '', x$Trade))
x$PL_Size <- as.numeric(sub('[",]', '', x$PL_Size))
x$Pos_PL <- as.numeric(sub('[",]', '', x$Pos_PL))
x$DDDollars <- as.numeric(sub('[",]', '', x$DDDollars))
x$DDPercent <- as.numeric(sub('[",]', '', x$DDPercent))
x$Equity <- as.numeric(sub('[",]', '', x$Equity))
readMSA <-x
}
require(TTR)
Bobcat1 <- readMSA("C:\\MSA-Files\\Excel Rollup\\Bobcat1.csv")
DDF <- readMSA("C:\\MSA-Files\\Excel Rollup\\DDF.csv")
Gallatin <- readMSA("C:\\MSA-Files\\Excel Rollup\\Gallatin.csv")
Kaweah <- readMSA("C:\\MSA-Files\\Excel Rollup\\Kaweah.csv")
KaweahNewOpt <- readMSA("C:\\MSA-Files\\Excel Rollup\\Kaweah-NewOpt.csv")
Klamath <- readMSA("C:\\MSA-Files\\Excel Rollup\\Klamath.csv")
MDDF <- readMSA("C:\\MSA-Files\\Excel Rollup\\MDDF.csv")
MDDFNewOpt <- readMSA("C:\\MSA-Files\\Excel Rollup\\MDDF-NewOpt.csv")
PFA_VWAP <- readMSA("C:\\MSA-Files\\Excel Rollup\\PFA_VWAP.csv")
par(mfrow=c(3,3))
plot(Equity ~ Trade, Bobcat1,type="l" )
plot(Equity ~ Trade, DDF,type="l" )
plot(Equity ~ Trade, Gallatin,type="l" )
plot(Equity ~ Trade, Kaweah,type="l" )
plot(Equity ~ Trade, KaweahNewOpt,type="l" )
plot(Equity ~ Trade, Klamath,type="l" )
plot(Equity ~ Trade, MDDF,type="l" )
plot(Equity ~ Trade, MDDFNewOpt,type="l" )
plot(Equity ~ Trade, PFA_VWAP,type="l" )
which generates a nice little 3x3 plot of the 9 system's equity curves
in under 2 seconds. Similar results in Excel take 1-2 minutes on this
same machine.
Kewl!
I'm sure there are probably better ways to manage the list of system
names/file path names. I'll get to that later.
Thanks to all for the help. More questions coming soon! ;-)
Cheers,
Mark
names(x)[1] <- "Trade"
names(x)[2] <- "SysNumber"
names(x)[3] <- "Date"
names(x)[4] <- "PL_Size"
names(x)[5] <- "PS_Method"
names(x)[6] <- "Size"
names(x)[7] <- "Pos_PL"
names(x)[8] <- "DDDollars"
names(x)[9] <- "DDPercent"
names(x)[10]<- "Equity"
I'm sure there are probably better ways to manage the list of system
names/file path names. I'll get to that later.