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
387 views
in Technique[技术] by (71.8m points)

r - knitr: How to show two plots of different sizes next to each other?

I wanted to generate two images of different sizes, but show them side-by-side. Is this possible?

This works, but then they have to be the same size:

```{r two_plots_same_size_side_by_side, fig.width=5, fig.height=5}
    plot(...)
    plot(...)
```

This doesn't work, but it could since in Markdown, lines that are separated by a single newline, appear on the same line.

```{r normal_plot, fig.width=5, fig.height=5}
    plot(...)
```
```{r tall_plot, fig.width=5, fig.height=9}
    plot(...)
```
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Another option, if you're outputting to HTML is to use the out.extra= chunk option, and set them to be float objects within a block. For example.

```{r fig.width=4, fig.height=6,echo=FALSE,out.extra='style="float:left"'}
plot(cars)
```{r fig.width=8, fig.height=6,echo=FALSE, out.extra='style="float:left"'}
plot(cars)
```

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

...