Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: setting multiple plot heights with par

Tags:

plot

r

I am trying to plot three charts together, one under the other. I would like to make the height of the first chart twice as big as the others using par, but I am having difficulty with the height parameter.

par(mfrow = c(3, 1),mar=c(2, 4, 2, 0.2), heights=c(2,1,1))

plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l")
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l")
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l")

Thank you for your help.

like image 233
adam.888 Avatar asked May 10 '15 20:05

adam.888


1 Answers

You can use layout for this:

#the first argument is a matrix that shows the order of the graphs
#in this case the matrix has 1 column and 3 rows. therefore, graphs 1,2,3
#will be ploted in this order, one below the other
#you then need to adjust the heights and the widths for each plot
nf <- layout(matrix(c(1,2,3),ncol=1), widths=c(4,4,4), heights=c(2,1,1), TRUE) 
#typing the below command will let you see how the plots will be filled in.
#layout.show(nf)

#then you just run your plots
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l")
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l")
plot(x=1:100,y=cumsum(sample(c(-1, 1), 100, TRUE)), type="l")

enter image description here

like image 167
LyzandeR Avatar answered Oct 07 '22 02:10

LyzandeR