Printing ggplot shapes side by side in an R markdown HTML file?

I am printing two graphs with ggplot in HTML R Markdown output, but I would like them to appear side by side. Is it possible? Can I set the size of the shapes?

So far, I can only print one after another. I also tried the animation function from the R Cookbook, but this distorts the graphics a lot ...

Thanks!


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)
```

This causes the following:

enter image description here

UPDATE: Following the sentence I received below, I tried to use the library gridExtraand printed the graphs, adding:

grid.arrange(genesDetectedDensity_MiSeq, genesDetectedHistogram_MiSeq, ncol=2)

This almost works, but it's still pretty messy:

enter image description here

+4
source share
2 answers

grid.arrange() gridExtra, :)

: . :

 library(gridExtra)

 plot1 <- qplot(iris$Sepal.Length)
 plot2 <- qplot(iris$Sepal.Width)

 grid.arrange(plot1, plot2, ncol=2)
                              `
+11

html- R Markdown, , R Markdown , . , escape- \n, :

---
title: "test"
author: "Testperson"
output:
  html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

<div class = "row">
<div class = "col-md-6">
```{r cars,  warning = FALSE, echo = FALSE, dev=c('svg')}
plot(pressure, main = paste("Lorem Ipsum ",
                        "Ipsum lorem ipsum. ",
                        "\nLorem ipsum", sep=""))
```
</div>
<div class = "col-md-6">
```{r pressure, warning = FALSE, echo=FALSE, dev=c('svg')}
plot(pressure, main = paste("Lorem Ipsum ",
                        "Ipsum lorem ipsum. ",
                        "\nLorem ipsum", sep=""))
```
</div>
</div>
+2

Source: https://habr.com/ru/post/1612004/


All Articles