How to create a faceted line-graph using ggplot?

后端 未结 2 572
暖寄归人
暖寄归人 2021-02-18 13:37

I have a data frame created with this code:

require(reshape2)
foo <- data.frame( abs( cbind(rnorm(3),rnorm(3, mean=.8),rnorm(3, mean=.9),rnorm(3, mean=1))))
q         


        
相关标签:
2条回答
  • 2021-02-18 14:24

    Try this:

    ggplot(data=alldf.m, aes(x=variable, y = value, colour = ID, group = ID)) + 
      geom_line() + facet_wrap(~fn)
    

    enter image description here

    0 讨论(0)
  • 2021-02-18 14:30

    Even it is a ggplot2 is required by the OP , but I think this example is suitable for lattice also:

    library(lattice)
    xyplot(data=alldf.m, value~variable|fn, type ='b', groups = ID, auto.key = T)
    

    enter image description here

    and using latticeExtra we can get something colse to ggplot2 solution:

     p <-  xyplot(data=alldf.m, value~variable|fn, type ='b', groups = ID, auto.key = T)
     update(p , par.settings = ggplot2like())
    

    enter image description here

    0 讨论(0)
提交回复
热议问题