01 | meetup <- read.csv ( 'MeetupDates.csv' , as.is=T) |
02 | names (meetup) <- 'Dates' |
03 | meetup$Dates <- as.Date (meetup$Dates,format= '%m/%d/%y' ) |
04 | files <- dir (pattern= 'DC_useR' ) |
05 | bl <- list () |
06 | for (f in files){ |
07 | bl[[f]] <- read.csv (f, as.is=T) |
08 | bl[[f]]$Date <- as.Date (bl[[f]]$Date,format= '%m/%d/%y' ) |
09 | } |
10 | dat <- Reduce ( function (x,y) merge (x,y), bl) # Merge the data frames by Date |
11 | dat2 <- melt (dat,id=1) |
12 |
13 | # Here comes the trick !! |
14 | f1 <- ggplot (dat2, aes (x=Date,y=value,ymin=0,ymax=value))+ facet_grid (variable~., scales= 'free' ) |
15 | f2 <- f1+ geom_step (subset= . (variable== 'Total.Members' )) |
16 | f3 <- f2+ geom_step (subset= . (variable== 'Active.Members' )) |
17 | f4 <- f3+ geom_linerange (subset= . (variable== 'Member.Joins' )) |
18 | f5 <- f4+ geom_linerange (subset= . (variable== 'RSVPs' )) |
19 | f5+ geom_vline (xintercept=meetup$Dates, color= 'red' ,alpha=.3)+ ylab ( '' ) |
http://statbandit.wordpress.com/2011/07/29/a-ggplot-trick-to-plot-different-plot-types-in-facets/
没有评论:
发表评论