在R markdown HTML文件中并排打印图形? [英] Printing figures side by side in R markdown HTML file?
问题描述
我将两个带有ggplot的图打印到R Markdown HTML输出中,但我希望它们并排出现.这可能吗? 我也可以设置数字的大小吗?
I'm printing two plots with ggplot into an R Markdown HTML output, but I'd like them to appear side by side. Is this possible? Could I set the size of the figures as well?
到目前为止,我只能一个接一个地打印它们.我还尝试了R Cookbook的多图函数,但是这严重扭曲了图...
SO far I can only print them one after the other. I also tried the multiplot function from the R Cookbook, but that severely distorts the plots...
谢谢!
title: "HT Chip MiSeq/HiSeq Analysis"
date: "October 1, 2015"
output:
html_document:
highlight: haddock
theme: flatly
---
```{r plots, echo=FALSE}
genesDetectedDensity_MiSeq <- ggplot(meta.miseq) + geom_density(aes(genesDetected, fill=column, color=seqRun), alpha=0.2) + scale_x_continuous(limits=c(0,2000), breaks=seq(0, 2000, 100)) + ggtitle("Genes Detected across cells from MiSeq Runs")
return(genesDetectedDensity_MiSeq)
genesDetectedHistogram_MiSeq <- ggplot(meta.miseq) + geom_bar(aes(genesDetected, fill=column, color=seqRun), position="dodge", binwidth=50, alpha=0.2) + scale_x_continuous(limits=c(0,2000), breaks=seq(0, 2000, 100)) + ggtitle("Genes Detected across cells from MiSeq Runs")
return(genesDetectedHistogram_MiSeq)
```
这将产生以下结果:
更新:按照我在下面收到的建议,我尝试使用gridExtra
库,并通过添加以下内容来打印图:
UPDATE: Following the suggestion I received below, I tried using the gridExtra
library, and printed the plots by adding:
grid.arrange(genesDetectedDensity_MiSeq, genesDetectedHistogram_MiSeq, ncol=2)
这几乎可以用,但还是有点混乱:
This almost works, but it's still kind of messy:
推荐答案
您可以在gridExtra库中使用grid.arrange()来实现此目的:)
You can use grid.arrange() in the gridExtra library to achieve this :)
使用虹膜查看图像:
library(gridExtra)
plot1 <- qplot(iris$Sepal.Length)
plot2 <- qplot(iris$Sepal.Width)
grid.arrange(plot1, plot2, ncol=2)
这篇关于在R markdown HTML文件中并排打印图形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!