Place a legend for each facet_wrap grid in ggplot2

前端 未结 4 846
闹比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条回答
  •  Happy的楠姐
    2020-11-27 04:34

    The best way to do this is with the gridExtra package:

    library(gridExtra)
    
    xs <- split(x,f = x$Server)
    p1 <- ggplot(xs$A,aes(x = Date,y = PercentUsed,group = 1,colour = FileSystem)) + 
            geom_jitter(size=0.5) + 
            geom_smooth(method="loess", se=T) + 
            facet_wrap(~Server, ncol=1)
    
    p2 <- p1 %+% xs$B
    p3 <- p1 %+% xs$C
    
    grid.arrange(p1,p2,p3)
    

    enter image description here

提交回复
热议问题