Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
779 views
in Technique[技术] by (71.8m points)

plot - Plotting 3 graphs in a 2-1 layout in R

Is it possible to obtain 3 plots in a single figure in R with a distribution as shown in the image below? The plots must have the same width, and plot C should be centered.

-----   -----
| A |   | B |
-----   -----
    -----
    | C |
    -----

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, with the layout(...) function.

layout(matrix(c(1,2,3,3), 2, 2, byrow = TRUE))
hist(mtcars$wt)
hist(mtcars$mpg)
hist(mtcars$disp)

So layout(...) takes a matrix where each element corresponds to a plot number. In this case, [1,1] corresponds to the first plot, [1,2] corresponds the the second plot, and [2,1:2] corresponds to the third plot.

This example is taken with slight modification from here.

If you want the bottom plot to be the same "width" as the two above, you can tweak the margins for that plot.

par(mar=c(4,4,2,2))
layout(matrix(c(1,2,3,3), 2, 2, byrow = TRUE))
hist(mtcars$wt)
hist(mtcars$mpg)
par(mar=c(2,14,2,14))
hist(mtcars$disp)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...