r - Correlation matrix plot with ggplot2 -


i want create correlation matrix plot, i.e. plot each variable plotted in scatterplot against each other variable pairs() or splom(). want ggplot2. see here examples. link mentions code wrote doing in ggplot2, however, outdated , no longer works (even after swap out deprecated parts).

one loop in loop , multiplot(), there must better way. tried melting dataset long, , copying value , variable variables , using facets. gives correct.

d = data.frame(x1=rnorm(100),                x2=rnorm(100),                x3=rnorm(100),                x4=rnorm(100),                x5=rnorm(100)) library(reshape2) d = melt(d) d$value2 = d$value d$variable2 = d$variable  library(ggplot2) ggplot(data=d, aes(x=value, y=value2)) +   geom_point() +   facet_grid(variable ~ variable2) 

enter image description here

this gets general structure right, works plotting each variable against itself. there more clever way of doing without resorting 2 loops?

library(ggally)  set.seed(42) d = data.frame(x1=rnorm(100),                x2=rnorm(100),                x3=rnorm(100),                x4=rnorm(100),                x5=rnorm(100))  # estimated density in diagonal ggpairs(d) 

enter image description here

# blank ggpairs(d, diag = list("continuous"="blank") 

enter image description here


Comments

Popular posts from this blog

Java 8 + Maven Javadoc plugin: Error fetching URL -

android - How to delete or change the searchview icon inside the SearchView actionBar? -

c++ - Msgpack packing bools bug -