Thank you Ista. On Wed, Mar 30, 2011 at 5:42 PM, Ista Zahn-2 [via R] <ml-node+3418450-470227041-224...@n4.nabble.com> wrote: > Use facetting: > > sets <- rbind(cbind(set="set1", set), cbind(set="set2", set2)) > ggplot(sets, aes(x = time, y = hours)) + > Â geom_area(colour = 'red', fill = 'red', alpha = 0.5) + > Â geom_area(stat = 'smooth', span = 0.2, alpha = 0.3) + > Â ylim(0,40) + > Â facet_grid(set ~ .) > > Best, > Ista > > On Wed, Mar 30, 2011 at 10:54 AM, Werner Heijstek <[hidden email]> wrote: >> I'm going to go ahead and shamelessly bump this question up the list. >> I saw that out of the 34 posts yesterday, only 9 did not receive an >> answer. Perhaps someone who finds this question trivial is checking >> his e-mail right now :) >> >> Werner >> >> On Tue, Mar 29, 2011 at 10:20 AM, jovian <[hidden email]> wrote: >>> Hello, >>> >>> I asked a similar question before but in an existing thread. I am not >>> sure >>> if it is proper etiquette to repost a similar question as a new tread, I >>> think in this case, it might be because this way more people can see it >>> and >>> perhaps learn from it. (Also, part of the existing thread became private) >>> >>> I want to know how to plot multiple ggplot area plots on top of one >>> another >>> so that the same x-axis is shared? >>> >>> This solution simply stitches multiple plots on top of each other: >>> >>> vp.layout <- function(x, y) viewport(layout.pos.row=x, layout.pos.col=y) >>> arrange <- function(..., nrow=NULL, ncol=NULL, as.table=FALSE) { >>> Â dots <- list(...) >>> Â n <- length(dots) >>> Â if(is.null(nrow) & is.null(ncol)) { nrow = floor(n/2) ; ncol = >>> ceiling(n/nrow)} >>> Â if(is.null(nrow)) { nrow = ceiling(n/ncol)} >>> Â if(is.null(ncol)) { ncol = ceiling(n/nrow)} >>> Â Â Â Â ## NOTE see n2mfrow in grDevices for possible alternative >>> grid.newpage() >>> pushViewport(viewport(layout=grid.layout(nrow,ncol) ) ) >>> Â ii.p <- 1 >>> Â for(ii.row in seq(1, nrow)){ >>> Â ii.table.row <- ii.row >>> Â if(as.table) {ii.table.row <- nrow - ii.table.row + 1} >>> Â for(ii.col in seq(1, ncol)){ >>> Â ii.table <- ii.p >>> Â if(ii.p > n) break >>> Â print(dots[[ii.table]], vp=vp.layout(ii.table.row, ii.col)) >>> Â ii.p <- ii.p + 1 >>> Â } >>> Â } >>> } >>> >>> set <- read.table(file="http://www.jovian.nl/set.csv", head=1, Â sep=",") >>> set2 <- read.table(file="http://www.jovian.nl/set2.csv", head=1, >>> Â sep=",") >>> library(ggplot2) >>> s <- ggplot(set, aes(x = time, y = hours)) + geom_area(colour = 'red', >>> fill >>> = 'red', alpha = 0.5) + >>> Â Â geom_area(stat = 'smooth', span = 0.2, alpha = 0.3) + ylim(0,40) >>> s1 <- ggplot(set2, aes(x = time, y = hours)) + geom_area(colour = 'red', >>> fill = 'red', alpha = 0.5) + >>> Â Â geom_area(stat = 'smooth', span = 0.2, alpha = 0.3) + ylim(0,40) >>> arrange(s,s1,ncol=1) >>> >>> >>> The arrange() function was taken from >>> >>> http://gettinggeneticsdone.blogspot.com/2010/03/arrange-multiple-ggplot2-plots-in-same.html. >>> In this example, the x-axes are only similar because the data sets have >>> the >>> same range. In effect nothing more happens than that two images are >>> plotted >>> on top of one another. Now how to "merge" these two (and later more) area >>> plots on top of each other so that they share the same x-axis (so that >>> only >>> one x-axis would be necessary on the bottom of the plot)? >>> >>> Thanks, >>> >>> Werner >>> >>> >>> -- >>> View this message in context: >>> http://r.789695.n4.nabble.com/Multiple-area-plots-to-share-the-same-x-axis-tp3414050p3414050.html >>> Sent from the R help mailing list archive at Nabble.com. >>> >>> ______________________________________________ >>> [hidden email] 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. >>> >> >> ______________________________________________ >> [hidden email] 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. >> > > > -- > Ista Zahn > Graduate student > University of Rochester > Department of Clinical and Social Psychology > http://yourpsyche.org > > ______________________________________________ > [hidden email] 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. > > > ________________________________ > If you reply to this email, your message will be added to the discussion > below: > http://r.789695.n4.nabble.com/Multiple-area-plots-to-share-the-same-x-axis-tp3414050p3418450.html > To unsubscribe from Multiple area plots to share the same x-axis, click > here.
-- View this message in context: http://r.789695.n4.nabble.com/Multiple-area-plots-to-share-the-same-x-axis-tp3414050p3419256.html Sent from the R help mailing list archive at Nabble.com. [[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.