Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine 4 pairs plots in one single figure?

Tags:

plot

r

in advance I am sorry if I am bothering you with trivial questions.

I should made 1 figure which contains 4 different correlation pairwise plots. The look of wanted graph can be seen as follows: enter image description here

Every single pairwise plot I am making with function pairs():

pairs(cbind(AAPL,MSFT,INTC,FB,MU,IBM),main="Frequency=1 Min.",font.labels = 2, col="blue",pch=16, cex=0.8, cex.axis=1.5,las=1)
pairs(cbind(AAPL,MSFT,INTC,FB,MU,IBM),main="Frequency = 2 Min.",font.labels = 2, col="blue",pch=16, cex=0.8, cex.axis=1.5,las=1)
pairs(cbind(AAPL,MSFT,INTC,FB,MU,IBM),main="Frequency = 5 Min.",font.labels = 2, col="blue",pch=16, cex=0.8, cex.axis=1.5,las=1)
pairs(cbind(AAPL,MSFT,INTC,FB,MU,IBM),main="Frequency = 10 Min.",font.labels = 2, col="blue",pch=16, cex=0.8, cex.axis=1.5,las=1)

When I combine above pairwise plots through usage of layout function, it is not working (as far as I understood from similar questions layout() and pairs() cannot be combined).

If anyone has an elegant way to combine 4 different correlation pairwise plots, the help would be greatly appreciated.

like image 927
Robin Hood Avatar asked Jul 31 '14 10:07

Robin Hood


2 Answers

Update, 12014-07-31 11:48:35Z

As ilir pointed out below pairs somehow overwrites par, most likely for some good reason.

@user44037, can you solve your problem working form this code snippet? Copy/pasted from here. I believe the solution can be found using splom from lattice. take a look at ?splom.

 library(lattice) 
 splom(~iris[1:3]|Species, data = iris, 
      layout=c(2,2), pscales = 0,
      varnames = c("Sepal\nLength", "Sepal\nWidth", "Petal\nLength"),
      page = function(...) {
          ltext(x = seq(.6, .8, len = 4), 
                y = seq(.9, .6, len = 4), 
                lab = c("@user44037,", "can you solve your", "problem working form ", "this code snippet?"),
                cex = 1)
      })

enter image description here

Initial answer, 12014-07-31 11:35:33Z

Simply following Avinash directions by copy/pasting code from the website Quick-R. Feel free to improve on this example.

I'm happy to troubleshoot your specific problem if you provide a reproducible example.

# 4 figures arranged in 2 rows and 2 columns
attach(mtcars)
par(mfrow=c(2,2))
plot(wt,mpg, main="Scatterplot of wt vs. mpg")
plot(wt,disp, main="Scatterplot of wt vs disp")
hist(wt, main="Histogram of wt")
boxplot(wt, main="Boxplot of wt")

enter image description here

like image 68
Eric Fail Avatar answered Oct 18 '22 00:10

Eric Fail


The problem is solved by using of splom() function as Eric Fail suggested:

The solution can be found here.

like image 22
Robin Hood Avatar answered Oct 18 '22 01:10

Robin Hood