Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrap text around plots in Markdown

I am reasking this question: How to wrap text around plots in R Markdown?:

'Currently the default for R Markdown in R is to have one line of text in line with the plot but this looks very awkward and I would like to save space by having the text wrap around the plot (plot aligned left, with text wrapping on the right).'

like image 384
sammyramz Avatar asked Apr 21 '17 20:04

sammyramz


1 Answers

You can use CSS styling to position the elements however you want. However there can be some difficulties and it does require some tweaking. Here is a simple example:

---
title: "Untitled"
author: "Ian Wesley"
date: "April 21, 2017"
output: html_document
---

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

## R Markdown
<div style= "float:right;position: relative; top: -80px;">
```{r pressure, echo=FALSE}
plot(pressure)
```
</div>

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:

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

Yields:

enter image description here

like image 101
Ian Wesley Avatar answered Sep 21 '22 12:09

Ian Wesley