Thanks! On Thu, Jan 6, 2011 at 7:13 PM, Dennis Murphy <djmu...@gmail.com> wrote: > Hi: > > On Thu, Jan 6, 2011 at 5:36 AM, Eduardo de Oliveira Horta > <eduardo.oliveiraho...@gmail.com> wrote: >> >> Peter, >> thank you, that's what I was looking for! >> David, I forgot to tell you my OS. Sorry... it's Win7. I'm running a >> RKWard session. >> And this is strange: >> > Cairo("example.pdf", type="pdf",width=12,height=12,units="cm",dpi=300) >> Error: could not find function "Cairo" >> ... maybe you're not using the Cairo >> package? http://cran.r-project.org/web/packages/Cairo/Cairo.pdf >> >> And Dennis, thanks for the code. It worked, and I'm considering to adopt >> data frames in the near future. By the way, I'm working with functional time >> series, so each observation is a function (or a vector representing that >> function evaluated on a grid) indexed by time. Any insights on how to >> implement data frames here? > > I don't see a real issue. It would be easier to give you concrete > information if there were an artificial example that mimics your situation, > but it's not that hard. I'd suggest looking into the zoo package to create > a series - it can handle both regular (zooreg()) and irregular (zoo()) > series. Basically, a zoo object is a numeric vector with a time index. One > can create multiple series with a single index, individual series with > different indices that can be combined into data frames, etc. I've browsed > through some of the code that accompanies Ramsey, Hooker and Graves' FDA > book in R and Matlab, and occasionally they use the zoo package as well. > > Here's an example, but I expect that someone will show how to convert the > zoo series to data frames much more efficiently for use in ggplot2... > > library(zoo) > library(ggplot2) > library(lattice) > # Generate three daily series with different start times and lengths > a <- zoo(rnorm(450), as.Date("2005-01-01") + 0:449) > b <- zoo(rnorm(600, 1, 2), as.Date('2005-06-01') + 0:599) > d <- zoo(rnorm(300, 2, 1), as.Date('2004-09-01') + 0:299) > > # Convert to data frame, make time index a variable and make sure it's a > Date object > A <- as.data.frame(a) > B <- as.data.frame(b) > D <- as.data.frame(d) > A$Date <- as.Date(rownames(A)) > B$Date <- as.Date(rownames(B)) > D$Date <- as.Date(rownames(D)) > # Give all three series the same name > names(A)[1] <- names(B)[1] <- names(D)[1] <- 'y' > # Stack the three data frames and create a series ID variable > comb <- rbind(A, B, D) > comb$Series <- rep(c('A', 'B', 'D'), c(nrow(A), nrow(B), nrow(D))) > str(comb) # make sure that Date is a Date object > > # ggplot of the three series > ggplot(comb, aes(x = Date, y = y, color = Series)) + geom_path() > # Stacked individual plots (faceted) > last_plot() + facet_grid(Series ~ .) > > # lattice version > xyplot(y ~ Date, data = comb, groups = Series, type = 'l', col.line = 1:3) > # Stacked individual series > xyplot(y ~ Date | Series, data = comb, type = 'l', layout = c(1, 3)) > > If you need the grid coordinates, use expand.grid() - it can be used when > creating a data frame, too. > > As Bert noted the other night in another thread, one can use xyplot directly > on zoo objects, but I don't have any direct experience with that yet so will > defer to others if they wish to contribute. ?xyplot.zoo provides some > examples. > > Hope this gives you some idea of what can be done, > Dennis > >> Best regards, >> Eduardo >> On Thu, Jan 6, 2011 at 1:47 AM, Peter Langfelder >> <peter.langfel...@gmail.com> wrote: >>> >>> On Wed, Jan 5, 2011 at 7:35 PM, Eduardo de Oliveira Horta >>> <eduardo.oliveiraho...@gmail.com> wrote: >>> > Something like this: >>> > >>> > u=seq(from=-pi, to=pi, length=1000) >>> > f=sin(u) >>> > Cairo("example.pdf", type="pdf",width=12,height=12,units="cm",dpi=300) >>> > par(cex.axis=.6,col.axis="grey",ann=FALSE, lwd=.25,bty="n", las=1, >>> > tcl=-.2, >>> > mgp=c(3,.5,0)) >>> > xlim=c(-pi,pi) >>> > ylim=round(c(min(f),max(f))) >>> > plot(u,f,xlim,ylim,type="l",col="firebrick3", axes=FALSE) >>> > axis(side=1, lwd=.25, col="darkgrey", at=seq(from=xlim[1], to=xlim[2], >>> > length=5)) >>> > axis(side=2, lwd=.25, col="darkgrey", at=seq(from=ylim[1], to=ylim[2], >>> > length=5)) >>> > abline(v=seq(from=xlim[1], to=xlim[2], length=5), lwd=.25,lty="dotted", >>> > col="grey") >>> > abline(h=seq(from=ylim[1], to=ylim[2], length=5), lwd=.25,lty="dotted", >>> > col="grey") >>> > dev.off() >>> > >>> > >>> >>> >>> Wow, you must like light colors :) >>> >>> To the point, just set margins, for example >>> >>> par(mar = c(2,2,0.5, 0.5)) >>> >>> (margins are bottom, left, top, right) >>> >>> after the Cairo command. >>> >>> BTW, Cairo doesn't work for me either... but I tried your example by >>> plotting to the screen. >>> >>> Peter >>> >>> >>> >>> >>> Notice how the canvas' margins are relatively far from the plotting >>> area. >>> > >>> > Thanks, >>> > >>> > Eduardo >>> > >>> > On Thu, Jan 6, 2011 at 1:00 AM, David Winsemius >>> > <dwinsem...@comcast.net>wrote: >>> > >>> >> >>> >> On Jan 5, 2011, at 9:38 PM, Eduardo de Oliveira Horta wrote: >>> >> >>> >> Hello, >>> >>> >>> >>> I want to save a pdf plot using Cairo, but the canvas of the saved >>> >>> file >>> >>> seems too large when compared to the actual plotted area. >>> >>> >>> >>> Is there a way to control the relation between the canvas size and >>> >>> the >>> >>> size >>> >>> of actual plotting area? >>> >>> >>> >>> >>> >> OS?, ... example? >>> >> >>> >> == >>> >> >>> >> David Winsemius, MD >>> >> West Hartford, CT >>> >> >>> >> >>> > >>> > [[alternative HTML version deleted]] >>> > >>> > ______________________________________________ >>> > R-help@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. >>> > >> > >
______________________________________________ R-help@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.