2

I often find following type of scatter + histograms + correlations plots very useful to understand the nature of my data before getting into the analysis. Can anyone help me to generate this kind of combined plot in R?

Example

user4143385
  • 51
  • 1
  • 6
  • Aside from base R there are many packages that offer enhanced plot functionality. The `ggplot2` package makes it particularly easy to generate combined plots. – Christoph Sommer Nov 25 '15 at 21:55
  • @ChristophSommer Yes but unfortunately I haven't figured out how to replicate attached type of plot using `ggplot2` yet :X – user4143385 Nov 25 '15 at 23:49

1 Answers1

1

If you don't care how exactly the plot looks, the GGally package offers a ready-made solution for the kind of plot you indicated.

library(ggplot2)
library(GGally)

# build a data frame of random values
d <- data.frame(a = rnorm(1000, 10))
d$b = rnorm(1000, 10)
d$c = rnorm(1000, 10)
d$d = d$b + rnorm(1000, sd=.1)

# prepare plot
p <- ggpairs(d, diag=list(continuous='bar'))

# show plot
print(p)

enter image description here

Christoph Sommer
  • 6,893
  • 1
  • 17
  • 35