Place a legend for each facet_wrap grid in ggplot2

前端 未结 4 859
闹比i
闹比i 2020-11-27 04:03

I have this data frame:

        Date Server FileSystem PercentUsed
1  12/1/2011      A          /          60
2   1/2/2012      A       /var          50
3            


        
4条回答
  •  情书的邮戳
    2020-11-27 04:20

    Meh, @joran beat me to it (my gridExtra was out of date but took me 10 minutes to realize it). Here's a similar solution, but this one skins the cat generically by levels in Server.

    library(gridExtra)
    out <- by(data = x, INDICES = x$Server, FUN = function(m) {
          m <- droplevels(m)
          m <- ggplot(m, aes(Date, PercentUsed, group=1, colour = FileSystem)) + 
             geom_jitter(size=2) + geom_smooth(method="loess", se=T)
       })
    do.call(grid.arrange, out)
    
    # If you want to supply the parameters to grid.arrange
    do.call(grid.arrange, c(out, ncol=3))
    

    image

提交回复
热议问题