Hello R-experts, I am having difficulties with 3D plotting (i.e. the evolution of various forward curves through time). I have two comma seperated files both ordered by date (in the first column) one containing contracts (meaning forward delivery months from YEAR_ & Letter "F" ... January through letter "Z" ... December) and the other holding the closing price of the respective contract on the day also defined in the first column (see attachments). What I would like to do is plot a three dimensional figure with trade day (date) on the X-axis, contract on the Y-axis and the price of the forward contract being the z-value. I am quite a newbie and did not manage to merge these two files in a logic way, so that R could do a 3D plot. Any help would be appreciated. -- WD
Since your files did not come through the mail list, I'd suggest to put them on some webside and provide a link. Uwe Ligges On 02.02.2010 13:01, walter.djuric at chello.at wrote:> Hello R-experts, > > I am having difficulties with 3D plotting (i.e. the evolution of various forward curves through time). > > I have two comma seperated files both ordered by date (in the first column) one containing contracts (meaning forward delivery months from YEAR_& Letter "F" ... January through letter "Z" ... December) and the other holding the closing price of the respective contract on the day also defined in the first column (see attachments). > > What I would like to do is plot a three dimensional figure with trade day (date) on the X-axis, contract on the Y-axis and the price of the forward contract being the z-value. > I am quite a newbie and did not manage to merge these two files in a logic way, so that R could do a 3D plot. > > Any help would be appreciated. > -- > WD > > > > ______________________________________________ > 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.
On 02.02.2010 16:01, walter.djuric at chello.at wrote:> Here they are for now for you. > And I will put them somewhere in a few minutes and poost the link.No need to do so. If you really want to use 3D plots (which I doubt you really want since you could do better in 2D using dotcharts or so): setwd('d:/') #READ IN Contracts NG.contracts <- read.csv('NG_contracts.csv', header=FALSE, sep=";", na.string="") NG.contracts$V1 <- as.Date(NG.contracts$V1,format='%d.%m.%Y') #READ IN Values NG.values <- read.csv('NG_values.csv', header=FALSE, sep=";", na.string="?") NG.values$V1 <- as.Date(NG.values$V1, format='%d.%m.%Y') ## new stuff by UL: NG.valuesl <- reshape(NG.values, direction="long", varying=list(2:32), idvar="V1") NG.contractsl <- reshape(NG.contracts, direction="long", varying=list(2:32), idvar="V1") NG <- NG.valuesl[,c("V1","V2")] colnames(NG) <- c("Date", "value") rownames(NG) <- NULL NG$contract <- NG.contractsl[,"V2"] ## two ways, one for nice viewing, one for easier printout: library(rgl) plot3d(NG$Date, NG$contract, NG$value) library(scatterplot3d) scatterplot3d(NG$Date, NG$contract, NG$value, pch=20) Now you need to prettify exes etc. Uwe Ligges> Greetings, > Walter > > ---- Uwe Ligges<ligges at statistik.tu-dortmund.de> schrieb: >> Since your files did not come through the mail list, I'd suggest to put >> them on some webside and provide a link. >> >> Uwe Ligges >> >> >> >> On 02.02.2010 13:01, walter.djuric at chello.at wrote: >>> Hello R-experts, >>> >>> I am having difficulties with 3D plotting (i.e. the evolution of various forward curves through time). >>> >>> I have two comma seperated files both ordered by date (in the first column) one containing contracts (meaning forward delivery months from YEAR_& Letter "F" ... January through letter "Z" ... December) and the other holding the closing price of the respective contract on the day also defined in the first column (see attachments). >>> >>> What I would like to do is plot a three dimensional figure with trade day (date) on the X-axis, contract on the Y-axis and the price of the forward contract being the z-value. >>> I am quite a newbie and did not manage to merge these two files in a logic way, so that R could do a 3D plot. >>> >>> Any help would be appreciated. >>> -- >>> WD >>> >>> >>> >>> ______________________________________________ >>> 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. > > -- > mfg > WD
a link to the 3D plot data files http://members.chello.at/gwd the files are NG_contracts and NG_values -- mfg WD
On 02/02/2010 11:01 PM, walter.djuric at chello.at wrote:> Hello R-experts, > > I am having difficulties with 3D plotting (i.e. the evolution of various forward curves through time). > > I have two comma seperated files both ordered by date (in the first column) one containing contracts (meaning forward delivery months from YEAR_& Letter "F" ... January through letter "Z" ... December) and the other holding the closing price of the respective contract on the day also defined in the first column (see attachments). > > What I would like to do is plot a three dimensional figure with trade day (date) on the X-axis, contract on the Y-axis and the price of the forward contract being the z-value. > I am quite a newbie and did not manage to merge these two files in a logic way, so that R could do a 3D plot. >Has anyone tried to program Hans Rosling's time evolution graphs in R? Jim