Plot one numeric variable against n numeric variables in n plots

后端 未结 4 1023
难免孤独
难免孤独 2020-11-28 13:44

I have a huge data frame and I would like to make some plots to get an idea of the associations among different variables. I cannot use

pairs(data)
<         


        
4条回答
  •  借酒劲吻你
    2020-11-28 14:24

    Could do reshape2/ggplot2/gridExtra packages combination. This way you don't need to specify the number of plots. This code will work on any number of explaining variables without any modifications

    foo <- data.frame(x1=1:10,x2=seq(0.1,1,0.1),x3=-7:2,x4=runif(10,0,1))
    library(reshape2)
    foo2 <- melt(foo, "x3")
    library(ggplot2)
    p1 <- ggplot(foo2, aes(value, x3)) +  geom_point() + facet_grid(.~variable)
    p2 <- ggplot(foo, aes(x = x3)) + geom_histogram()
    library(gridExtra)
    grid.arrange(p1, p2, ncol=2)
    

    enter image description here

提交回复
热议问题