Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

Multiple plots in a page with R

I have a problem. I want to arrange 7 plots in a single page: 3 plots in a top line, 2 plots below and 2 other below. I could'nt make it work with layout(matrix=)) (I think because the top line has an odd number of plots). I have used aplot and image.plot to make the plots. Thanks. Henri

question from:https://stackoverflow.com/questions/65925457/multiple-plots-in-a-page-with-r

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

1 Answer

0 votes
by (71.8m points)

If you are using ggplot, you might also consider using the patchwork package for this to make it easy. For example:

Step 1: Create all your figures and assign them to objects (e.g., fig1, fig2 etc.). For example:

fig1 <- ggplot(data = myData, mapping = aes(x = x, y = y) +
    geom_point()

#...etc.

Step 2: To create the layout to specified:

library(patchwork)
(fig1 + fig2 + fig3) / (fig4 + fig5) / (fig6 + fig7)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...