tolga.i.uzuner at jpmorgan.com
2008-Jun-30 09:11 UTC
[R] Plotting three time series on the same graph
Dear R Users, I would like to plot three time series on the same graph, two axis on the left and one axis on the right. The time series that I am graphing on the left do not share a similar scale: one has a range of 1:100 and the other a range of 25000:70000. How can I display the tick marks for both on the left hand side without superimposing them, i.e. one set of tick marks in black right up on the edge of the plot and another set of tick marks in red placed further to the left so that the tick marks and axis identifiers do not sit on top of each other ? Many thanks in advance, Tolga Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[alternative HTML version deleted]]
Dear list, I have to vectors: x <- rep(c(2,4,8,24,48,72),2) y <-c(82543,169105,207615,96633,31988,7005,82687,172931,205541,101842,31898,69 50) that follows a log-normal function as f(x)= SO/(sqrt(2*pi)*sigma *x) * exp(-(ln x - mu)^2/(2*sigma^2)) that is a log-normal distribution multiplied with SO. How can I estimate SO, mu and sigma in R ? Wishes Gunther
tolga.i.uzuner at jpmorgan.com
2008-Jun-30 11:06 UTC
[R] Plotting three time series on the same graph
Thanks Romain for trying to help, but my issue is that I have three time series, not two, so at least two of them would have to go on the same side. There may be no solution to this problem in R but if there is, would appreciate hearing about it from someone ? Figure 1 in this link shows what I am trying to achieve: http://www.aditus.nu/jpgraph/howto04.php Thanks anyway, Tolga Romain Francois <rfrancois@mango-solutions.com> 30/06/2008 10:51 To tolga.i.uzuner@jpmorgan.com cc Matt Aldridge <maldridge@mango-solutions.com> Subject Re: [R] Plotting three time series on the same graph Hello Tolga, I am not sure what you are looking for is achievable easily, however, you can have an axis on the left and another on the right. Look at the side argument of the axis function. Would the following code work for you: # generating some data y <- 1:100 + runif( 100, min = -10, max = 10 ) x <- 1:100 + runif( 100, min = -10, max = 10 ) z <- seq( 70000, 25000, length.out = 100) + runif( 100, min = -2000, max = 2000) # prettier version of lines .myLines <- function(x,y, col = "blue", lwd = 2, ...){ lines( x,y,col = "black", lwd=2 + lwd) lines( x,y,col = col, lwd=lwd, ...) } # transform from the scale c(25000,70000) to (0,100) transform <- function( data ){ ( data - 25000 ) / ( 70000 - 25000 ) * 100 } par( mar = c(5,4,4,4)+.1 ) plot( 1:100, x , type = "n", las = 1 ) axs <- pretty( c(25000, 70000), n = 5 ) abline( h = transform(axs), col = "gray") .myLines( 1:100, x, col = "red" ) .myLines( 1:100, y, col = "blue" ) .myLines( 1:100, transform(z), col = "green" ) axis( 4, transform(axs), axs, las = 1 ) Best Regards, Romain Francois -- Mango Solutions data analysis that delivers Tel: +44(0) 1249 76 77 00 Fax: +44(0) 1249 76 77 07 Mob: +44(0) 7813 52 61 23 R for finance course: 8th-10th july. London The R Language: 9th-10th september. London More courses from: http://www.mango-solutions.com/services/rtraining/r_schedule.html tolga.i.uzuner@jpmorgan.com wrote:> Dear R Users, > > I would like to plot three time series on the same graph, two axis onthe> left and one axis on the right. > > The time series that I am graphing on the left do not share a similar > scale: one has a range of 1:100 and the other a range of 25000:70000.How> can I display the tick marks for both on the left hand side without > superimposing them, i.e. one set of tick marks in black right up on the > edge of the plot and another set of tick marks in red placed further to > the left so that the tick marks and axis identifiers do not sit on topof> each other ? > > Many thanks in advance, > Tolga >[attachment "plot3timeseries.png" deleted by Tolga I Uzuner/JPMCHASE] Generally, this communication is for informational purposes only and it is not intended as an offer or solicitation for the purchase or sale of any financial instrument or as an official confirmation of any transaction. In the event you are receiving the offering materials attached below related to your interest in hedge funds or private equity, this communication may be intended as an offer or solicitation for the purchase or sale of such fund(s). All market prices, data and other information are not warranted as to completeness or accuracy and are subject to change without notice. Any comments or statements made herein do not necessarily reflect those of JPMorgan Chase & Co., its subsidiaries and affiliates. This transmission may contain information that is privileged, confidential, legally privileged, and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is STRICTLY PROHIBITED. Although this transmission and any attachments are believed to be free of any virus or other defect that might affect any computer system into which it is received and opened, it is the responsibility of the recipient to ensure that it is virus free and no responsibility is accepted by JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, for any loss or damage arising in any way from its use. If you received this transmission in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you. Please refer to http://www.jpmorgan.com/pages/disclosures for disclosures relating to UK legal entities. [[alternative HTML version deleted]]
In the zoo package there is an example of a graph with an axis on the left and on the right in the examples section of ?plot.zoo. Run that with but use ylab = "" on the plot call to make room for the third axis. To add a third axis supposing 1 - 15 is the range of our third time series: usr <- par("usr") opar <- par(usr = c(usr[1:2], c(1, 15))) axis(2, pos = usr[1] - diff(usr[1:2])/12, col = "green") par(opar) On Mon, Jun 30, 2008 at 5:11 AM, <tolga.i.uzuner at jpmorgan.com> wrote:> Dear R Users, > > I would like to plot three time series on the same graph, two axis on the > left and one axis on the right. > > The time series that I am graphing on the left do not share a similar > scale: one has a range of 1:100 and the other a range of 25000:70000. How > can I display the tick marks for both on the left hand side without > superimposing them, i.e. one set of tick marks in black right up on the > edge of the plot and another set of tick marks in red placed further to > the left so that the tick marks and axis identifiers do not sit on top of > each other ? > > Many thanks in advance, > Tolga > > Generally, this communication is for informational purposes only > and it is not intended as an offer or solicitation for the purchase > or sale of any financial instrument or as an official confirmation > of any transaction. In the event you are receiving the offering > materials attached below related to your interest in hedge funds or > private equity, this communication may be intended as an offer or > solicitation for the purchase or sale of such fund(s). All market > prices, data and other information are not warranted as to > completeness or accuracy and are subject to change without notice. > Any comments or statements made herein do not necessarily reflect > those of JPMorgan Chase & Co., its subsidiaries and affiliates. > > This transmission may contain information that is privileged, > confidential, legally privileged, and/or exempt from disclosure > under applicable law. If you are not the intended recipient, you > are hereby notified that any disclosure, copying, distribution, or > use of the information contained herein (including any reliance > thereon) is STRICTLY PROHIBITED. Although this transmission and any > attachments are believed to be free of any virus or other defect > that might affect any computer system into which it is received and > opened, it is the responsibility of the recipient to ensure that it > is virus free and no responsibility is accepted by JPMorgan Chase & > Co., its subsidiaries and affiliates, as applicable, for any loss > or damage arising in any way from its use. If you received this > transmission in error, please immediately contact the sender and > destroy the material in its entirety, whether in electronic or hard > copy format. Thank you. > Please refer to http://www.jpmorgan.com/pages/disclosures for > disclosures relating to UK legal entities. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org 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. >
Hello Tolga, Further hacking on par(mar) leads me to the code below. I hope it can help you. Cheers, Romain y <- 1:100 + runif( 100, min = -10, max = 10 ) x <- 1000 + 1:100 + runif( 100, min = -10, max = 10 ) z <- seq( 70000, 25000, length.out = 100) + runif( 100, min = -2000, max = 2000) .myLines <- function(x,y, col = "blue", lwd = 2, ...){ lines( x,y,col = "black", lwd=2 + lwd) lines( x,y,col = col, lwd=lwd, ...) } transform <- function( data, n = 5, lim = range(data) ){ scaledData <- ( data - lim[1] ) / ( lim[2] - lim[1] ) tickMarks <- pretty( data, n = n ) tickPositions <- ( tickMarks - lim[1] ) / ( lim[2] - lim[1] ) list( scaledData = scaledData, tickMarks = tickMarks, tickPositions = tickPositions ) } par( mar = c(5,4,4,8)+.1 ) plot( 0, 0 , type = "n", las = 1, ylim = c(0,1), xlim = c(0,100), ann = F, axes=F ) x.tr <- transform(x) y.tr <- transform(y) z.tr <- transform(z) # first draw the lines .myLines( 1:100, x.tr$scaledData , col = "red" ) .myLines( 1:100, y.tr$scaledData , col = "blue" ) .myLines( 1:100, z.tr$scaledData , col = "green" ) axis(1) box() # then the axis axis( 4, x.tr$tickPositions, x.tr$tickMarks, col = "red", col.axis = "red" ) par( mar = par("mar") - c(0,0,0,2.5) ) axis( 4, y.tr$tickPositions, y.tr$tickMarks, col = "blue", col.axis = "blue" ) par( mar = par("mar") - c(0,0,0,2.5) ) axis( 4, z.tr$tickPositions, z.tr$tickMarks, col = "green", col.axis = "green" ) tolga.i.uzuner at jpmorgan.com wrote:> > Thanks Romain for trying to help, but my issue is that I have three > time series, not two, so at least two of them would have to go on the > same side. > > There may be no solution to this problem in R but if there is, would > appreciate hearing about it from someone ? > > Figure 1 in this link shows what I am trying to achieve: > http://www.aditus.nu/jpgraph/howto04.php > > Thanks anyway, > Tolga > > > > *Romain Francois <rfrancois at mango-solutions.com>* > > 30/06/2008 10:51 > > > To > tolga.i.uzuner at jpmorgan.com > cc > Matt Aldridge <maldridge at mango-solutions.com> > Subject > Re: [R] Plotting three time series on the same graph > > > > > > > > > > Hello Tolga, > > I am not sure what you are looking for is achievable easily, however, > you can have an axis on the left and another on the right. Look at the > side argument of the axis function. Would the following code work for you: > > # generating some data > y <- 1:100 + runif( 100, min = -10, max = 10 ) > x <- 1:100 + runif( 100, min = -10, max = 10 ) > z <- seq( 70000, 25000, length.out = 100) + runif( 100, min = -2000, max > = 2000) > > # prettier version of lines > .myLines <- function(x,y, col = "blue", lwd = 2, ...){ > lines( x,y,col = "black", lwd=2 + lwd) > lines( x,y,col = col, lwd=lwd, ...) > } > > # transform from the scale c(25000,70000) to (0,100) > transform <- function( data ){ > ( data - 25000 ) / ( 70000 - 25000 ) * 100 > } > > par( mar = c(5,4,4,4)+.1 ) > plot( 1:100, x , type = "n", las = 1 ) > axs <- pretty( c(25000, 70000), n = 5 ) > abline( h = transform(axs), col = "gray") > .myLines( 1:100, x, col = "red" ) > .myLines( 1:100, y, col = "blue" ) > .myLines( 1:100, transform(z), col = "green" ) > axis( 4, transform(axs), axs, las = 1 ) > > Best Regards, > > Romain Francois > > -- > Mango Solutions > data analysis that delivers > > Tel: +44(0) 1249 76 77 00 > Fax: +44(0) 1249 76 77 07 > Mob: +44(0) 7813 52 61 23 > > R for finance course: 8th-10th july. London > The R Language: 9th-10th september. London > More courses from: > http://www.mango-solutions.com/services/rtraining/r_schedule.html > > > > tolga.i.uzuner at jpmorgan.com wrote: > > Dear R Users, > > > > I would like to plot three time series on the same graph, two axis > on the > > left and one axis on the right. > > > > The time series that I am graphing on the left do not share a similar > > scale: one has a range of 1:100 and the other a range of > 25000:70000. How > > can I display the tick marks for both on the left hand side without > > superimposing them, i.e. one set of tick marks in black right up on the > > edge of the plot and another set of tick marks in red placed further to > > the left so that the tick marks and axis identifiers do not sit on > top of > > each other ? > > > > Many thanks in advance, > > Tolga > > > > > [attachment "plot3timeseries.png" deleted by Tolga I Uzuner/JPMCHASE] > ------------------------------------------------------------------------ > > Generally, this communication is for informational purposes only and > it is not intended as an offer or solicitation for the purchase or > sale of any financial instrument or as an official confirmation of any > transaction. In the event you are receiving the offering materials > attached below related to your interest in hedge funds or private > equity, this communication may be intended as an offer or solicitation > for the purchase or sale of such fund(s). All market prices, data and > other information are not warranted as to completeness or accuracy and > are subject to change without notice. Any comments or statements made > herein do not necessarily reflect those of JPMorgan Chase & Co., its > subsidiaries and affiliates. This transmission may contain information > that is privileged, confidential, legally privileged, and/or exempt > from disclosure under applicable law. If you are not the intended > recipient, you are hereby notified that any disclosure, copying, > distribution, or use of the information contained herein (including > any reliance thereon) is STRICTLY PROHIBITED. Although this > transmission and any attachments are believed to be free of any virus > or other defect that might affect any computer system into which it is > received and opened, it is the responsibility of the recipient to > ensure that it is virus free and no responsibility is accepted by > JPMorgan Chase & Co., its subsidiaries and affiliates, as applicable, > for any loss or damage arising in any way from its use. If you > received this transmission in error, please immediately contact the > sender and destroy the material in its entirety, whether in electronic > or hard copy format. Thank you. Please refer to > http://www.jpmorgan.com/pages/disclosures for disclosures relating to > UK legal entities. >-- Mango Solutions data analysis that delivers Tel: +44(0) 1249 76 77 00 Fax: +44(0) 1249 76 77 07 Mob: +44(0) 7813 52 61 23
Hi, Gunther, maybe fitdistr() in MASS library can do the job , the code should be >library(MASS) > fitdistr( x, densfun = "log-normal") by using your data we can obtain the parameters , meanlog sdlog 2.5808007 1.2999517 (0.3752637) (0.2653515) is that what you want? On 2008-6-30, at ??5:26, Gunther H?ning wrote:> Dear list, > > I have to vectors: > > x <- rep(c(2,4,8,24,48,72),2) > y > <- > c > (82543,169105,207615,96633,31988,7005,82687,172931,205541,101842,31898,69 > 50) > > that follows a log-normal function as > > f(x)= SO/(sqrt(2*pi)*sigma *x) * exp(-(ln x - mu)^2/(2*sigma^2)) > > that is a log-normal distribution multiplied with SO. > > How can I estimate SO, mu and sigma in R ? > > > Wishes > Gunther > > ______________________________________________ > R-help at r-project.org 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.----------------------------------------------- Peng Jiang ?? ,Ph.D. Candidate Antai College of Economics & Management ???????? Department of Mathematics ??? Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China
Hi, thanks but not exactly. If you plot x vs. y you will see that the function that fits the data is a log-normal distribution multiplied with a constant. So what I want to do is more like a regression.. Estimating parameters to a model.. Gunther -----Urspr?ngliche Nachricht----- Von: Peng Jiang [mailto:jp021 at sjtu.edu.cn] Gesendet: Montag, 30. Juni 2008 14:00 An: H?ning, Gunther Cc: r-help at r-project.org Betreff: Re: [R] Estimating parameters of log-normal distribution Hi, Gunther, maybe fitdistr() in MASS library can do the job , the code should be >library(MASS) > fitdistr( x, densfun = "log-normal") by using your data we can obtain the parameters , meanlog sdlog 2.5808007 1.2999517 (0.3752637) (0.2653515) is that what you want? On 2008-6-30, at ??5:26, Gunther H?ning wrote:> Dear list, > > I have to vectors: > > x <- rep(c(2,4,8,24,48,72),2) > y > <- > c > (82543,169105,207615,96633,31988,7005,82687,172931,205541,101842,31898 > ,69 > 50) > > that follows a log-normal function as > > f(x)= SO/(sqrt(2*pi)*sigma *x) * exp(-(ln x - mu)^2/(2*sigma^2)) > > that is a log-normal distribution multiplied with SO. > > How can I estimate SO, mu and sigma in R ? > > > Wishes > Gunther > > ______________________________________________ > R-help at r-project.org 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.----------------------------------------------- Peng Jiang ?? ,Ph.D. Candidate Antai College of Economics & Management ???????? Department of Mathematics ??? Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China