Displaying multiple data frames in ggplot2

后端 未结 2 1502
一整个雨季
一整个雨季 2021-01-27 06:32

I am trying to layer multiple data frames in one line plot, with x = index, y = values. The 8 data.frames I work with come in this format (index and va

2条回答
  •  再見小時候
    2021-01-27 07:11

    No hive mind required:

    d0 <- data.frame(index = 1:100, values = rnorm(100))
    d1 <- data.frame(index = 1:200, values = rnorm(200))
    d2 <- data.frame(index = 1:100, values = rnorm(100))
    d3 <- data.frame(index = 1:100, values = rnorm(100))
    d4 <- data.frame(index = 1:100, values = rnorm(100))
    d5 <- data.frame(index = 1:500, values = rnorm(500))
    d6 <- data.frame(index = 1:100, values = rnorm(100))
    d7 <- data.frame(index = 1:100, values = rnorm(100))
    
    require(ggplot2)
    p0 <- ggplot(d0, aes(x=index, y=values)) + geom_point(alpha=.3)
    p1 <- ggplot(d1, aes(x=index, y=values)) + geom_point(alpha=.3)
    p2 <- ggplot(d2, aes(x=index, y=values)) + geom_point(alpha=.3)
    p3 <- ggplot(d3, aes(x=index, y=values)) + geom_point(alpha=.3)
    p4 <- ggplot(d4, aes(x=index, y=values)) + geom_point(alpha=.3)
    p5 <- ggplot(d5, aes(x=index, y=values)) + geom_point(alpha=.3)
    p6 <- ggplot(d6, aes(x=index, y=values)) + geom_point(alpha=.3)
    p7 <- ggplot(d7, aes(x=index, y=values)) + geom_point(alpha=.3)
    
    require(Rmisc)
    multiplot(p0, p1, p2, p3, p4, p5, p6, p7, cols=2)
    

提交回复
热议问题