On Tue, 2006-10-31 at 18:11 +0000, Gavin Simpson wrote:
> On Tue, 2006-10-31 at 12:08 -0500, Leeds, Mark (IED) wrote:
> > i have the following code below and at the end there are some plotting
> > statements.
> > it actualy looks quite nice when you run it but there is just one
> > strange thing happening that
> > don't know how to fix.
>
> The problem you had, was that par(new = TRUE) # not T! resets the
> plotting coordinate system, so even though the axis looks like it
> extends the full range of the first data series, it covers the range of
> lt, e.g.:
>
> > plot(aggfxdata[,"logbidask"],main="",col=4)
> > lines(rollmeanlogbidask,col=2)
> > par(new=T)
> > plot(lt,axes=F,type="l",lty=2)
> > axis(side = 3) # new coords system
>
> This works:
>
> plot(aggfxdata[,"logbidask"], main = "", col = 4)
> lines(rollmeanlogbidask, col = 2)
> usr <- par("usr")
> par(usr = c(usr[1:2], 0.76, 7.24))
> lines(lt, lty = 2)
> axis(4, at = pretty(range(lt)), tck = -0.02)
Following off-list emails with Mark, I tracked down how to do this
automatically, for the thread...
It is document in ?par in the section on xaxs and yaxs (x and y axis
styles). This defaults to "r", which adds/subtracts 4% to the x/ylims,
so,
plot(aggfxdata[,"logbidask"], main = "", col = 4)
lines(rollmeanlogbidask, col = 2)
usr <- par("usr")
# extend range of data by 4%
rany <- (max(lt) - min(lt)) * 0.04
par(usr = c(usr[1:2], min(lt) - rany, max(lt) + rany))
lines(lt, lty = 2)
axis(4, at = pretty(range(lt)), tck = -0.02)
the above does exactly as I'd done before, but automagically.
G
>
> ..., I think. But I cheat, because, here:
>
> par(usr = c(usr[1:2], 0.76, 7.24))
>
> I got the last two numbers by doing the following
>
> > plot(lt)
> > par("usr")[3:4]
> [1] 0.76 7.24
>
> A question then arises, how to process lt such that we end up with the
> same numbers that R would have used to plot lt, i.e. which function or
> bit of code will give:
>
> > what.R.would.give(lt)
> [1] 1.152076e+09 1.152088e+09 7.600000e-01 7.240000e+00
>
> Without doing the plotting?
>
> HTH
>
> G
>
> >
> > the three things being plotted are
> >
> > aggfxdata[,logbidask] which has its own set of times ( it's a zoo object
> > ).
> > rollmeanlogbidask which has a subset of the times that aggfxdata has.
> > basically it starts later than aggfxdata[,logbidask] and when the plot
> > is done, it works in the
> > sense that rollmeanlogbidask gets plotted later.
> >
> > then, i plot the variable lt on the same plot witrh it's vertical axis
> > on the right side and this works nicely also.
> >
> > the only that doesn't quite work is that lt, time wise, lt, starting at
> > the same time as the aggfxdata[,logbidask] when it should be starting a
> > few minutes after
> > rollmeanlogbidask. the times in it are correct and i don't think it has
> > to do with the fact that things are zoo ( but i could be wrong ? ).
> > i must be doing something wrong in my commands. the weird thing is that
> > rollmeanlogbidask starts at the appropriate place ?
> >
> > maybe i have to give lt a different frequency but when i do the dput , i
> > don'ts ee freequency as part of it ?
> >
> > this probably sounds way more confusing than it actually is but, if you
> > run below, you will see exactly what io mean.
> > thanks a lot to anyone who can be bothered pasitng below. as usual, you
> > would need zoo and chron.
> >
> >
> > aggfxdata<-structure(c(114.834516129032, 114.7922, 114.820808080808,
> > 114.838260869565,
> > 114.837560975610, 114.776697247706, 114.796933333333, 114.745714285714,
> > 114.734923076923, 114.661939393939, 114.646574074074, 114.703486238532,
> > 114.646453900709, 114.651948051948, 114.742671755725, 114.721132075472,
> > 114.828647058824, 114.885978260870, 114.936860465116, 114.94,
> > 114.967763157895, 114.935107526882, 114.92225, 115.015606060606,
> > 115.077261146497, 115.034248366013, 114.961923076923, 114.976463414634,
> > 115.063468208092, 115.085882352941, 115.166847826087, 115.153306451613,
> > 115.137719298246, 115.080735294118, 115.074090909091, 115.021134751773,
> > 114.903450292398, 114.916153846154, 114.888306451613, 114.937469879518,
> > 114.890943396226, 114.849747899160, 114.926912751678, 114.874567901235,
> > 114.837980769231, 114.797538461538, 114.746707317073, 114.696013071895,
> > 114.676458333333, 114.852184466019, 114.848548387097, 114.8078,
> > 114.835050505051, 114.851304347826, 114.852439024390, 114.792844036697,
> > 114.811733333333, 114.759206349206, 114.748307692308, 114.675939393939,
> > 114.661296296296, 114.717889908257, 114.660921985816, 114.665779220779,
> > 114.756870229008, 114.735471698113, 114.841941176471, 114.899184782609,
> > 114.949186046512, 114.953990384615, 114.982280701754, 114.948924731183,
> > 114.9368, 115.028863636364, 115.091592356688, 115.047777777778,
> > 114.975576923077, 114.990365853659, 115.078381502890, 115.099705882353,
> > 115.180326086957, 115.166370967742, 115.151052631579, 115.095147058824,
> > 115.088522727273, 115.035390070922, 114.917894736842, 114.930128205128,
> > 114.903790322581, 114.952409638554, 114.906226415094, 114.863865546218,
> > 114.940939597315, 114.890370370370, 114.852211538462, 114.812307692308,
> > 114.760548780488, 114.710326797386, 114.690208333333, 114.866213592233,
> > 4.74355319771057, 4.74319148388547, 4.74343474081987, 4.74358150022944,
> > 4.74358339314172, 4.74305881517423, 4.74322922997911, 4.74277728938584,
> > 4.74268277772736, 4.74204918880485, 4.7419183321792, 4.74241320264843,
> > 4.74191617575789, 4.74196131670693, 4.74275385322944, 4.74256674074965,
> > 4.74349887668465, 4.74399761812053, 4.74443655563793, 4.74447111073972,
> > 4.74471490416156, 4.74442779363424, 4.74431911442163, 4.74512545618279,
> > 4.74566600467616, 4.74528870019174, 4.74466035230505, 4.74478789738982,
> > 4.74554867613244, 4.74573870836097, 4.74644044208183, 4.74632106516708,
> > 4.74618687097407, 4.74569654200703, 4.74563889435559, 4.74517785826786,
> > 4.74415506578588, 4.74426356601777, 4.74402779250609, 4.74445322900522,
> > 4.74404986890124, 4.74368619357562, 4.7443574082389, 4.74390959824271,
> > 4.74358423039023, 4.7432343669113, 4.74278746542368, 4.74234766049834,
> > 4.74217470698038, 4.7437070219583), .Dim = c(50, 3), .Dimnames = list(
> > NULL, c("bid", "ask", "logbidask")), index = structure(c(1152058200,
> >
> > 1152058800, 1152059400, 1152060000, 1152060600, 1152061200, 1152061800,
> > 1152062400, 1152063000, 1152063600, 1152064200, 1152064800, 1152065400,
> > 1152066000, 1152066600, 1152067200, 1152067800, 1152068400, 1152069000,
> > 1152069600, 1152070200, 1152070800, 1152071400, 1152072000, 1152072600,
> > 1152073200, 1152073800, 1152074400, 1152075000, 1152075600, 1152076200,
> > 1152076800, 1152077400, 1152078000, 1152078600, 1152079200, 1152079800,
> > 1152080400, 1152081000, 1152081600, 1152082200, 1152082800, 1152083400,
> > 1152084000, 1152084600, 1152085200, 1152085800, 1152086400, 1152087000,
> > 1152087600), class = c("POSIXt", "POSIXct")), class = "zoo")
> >
> >
> > rollmeanlogbidask<-structure(c(4.74371176689231, 4.74380800837135,
> > 4.7439123277474,
> > 4.74400406541921, 4.7440745668118, 4.74414308351893, 4.74421371828871,
> > 4.74424457948227, 4.74429412203667, 4.74433895586263, 4.74441909053597,
> > 4.74449014176004, 4.74453257479095, 4.74461394920698, 4.74467889192484,
> > 4.74470657116353, 4.74472882536892, 4.74470511166022, 4.74465011307282,
> > 4.74457471811757, 4.74454924849152), index = structure(c(1152075600,
> > 1152076200, 1152076800, 1152077400, 1152078000, 1152078600, 1152079200,
> > 1152079800, 1152080400, 1152081000, 1152081600, 1152082200, 1152082800,
> > 1152083400, 1152084000, 1152084600, 1152085200, 1152085800, 1152086400,
> > 1152087000, 1152087600), class = c("POSIXt", "POSIXct")), class = "zoo")
> >
> >
> > lt<-structure(c(1, 2, 3, 4, 5, 6, 1, 1, 2, 3, 4, 5, 6, 7, 1, 1, 1,
> > 1, 1), index = structure(c(1152076800, 1152077400, 1152078000,
> > 1152078600, 1152079200, 1152079800, 1152080400, 1152081000, 1152081600,
> > 1152082200, 1152082800, 1152083400, 1152084000, 1152084600, 1152085200,
> > 1152085800, 1152086400, 1152087000, 1152087600), class = c("POSIXt",
> > "POSIXct")), class = "zoo")
> >
> >
> > plot(aggfxdata[,"logbidask"],main="",col=4)
> > lines(rollmeanlogbidask,col=2)
> >
> > par(new=T)
> >
> > plot(lt,axes=F,type="l",lty=2)
> > axis(4,at=pretty(range(lt)),line=0.5,tck=0.02)
> >
> >
> > #-----------------------------------------------------------------------
> > ------------------------------------------------------------------
> > --------------------------------------------------------
> >
> > This is not an offer (or solicitation of an offer) to buy/sell the
> > securities/instruments mentioned or an official confirmation. Morgan
> > Stanley may deal as principal in or own or act as market maker for
> > securities/instruments mentioned or may advise the issuers. This is not
> > research and is not from MS Research but it may refer to a research
> > analyst/research report. Unless indicated, these views are the author's
> > and may differ from those of Morgan Stanley research or others in the Firm.
> > We do not represent this is accurate or complete and we may not update
> > this. Past performance is not indicative of future returns. For
> > additional information, research reports and important disclosures, contact
> > me or see https://secure.ms.com/servlet/cls. You should not use e-mail to
> > request, authorize or effect the purchase or sale of any security or
> > instrument, to send transfer instructions, or to effect any other
> > transactions. We cannot guarantee that any such requests received !
vi!
> a !
> > e-mail will be processed in a timely manner. This communication is solely
> > for the addressee(s) and may contain confidential information. We do not
> > waive confidentiality by mistransmission. Contact me if you do not wish to
> > receive these communications. In the UK, this communication is directed in
> > the UK to those persons who are market counterparties or intermediate
> > customers (as defined in the UK Financial Services Authority's rules).
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [email protected] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [t] +44 (0)20 7679 0522
ECRC & ENSIS, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.