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) 
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) 
# blank ggpairs(d, diag = list("continuous"="blank") 
Comments
Post a Comment