Skip to content

Commit 221e63a

Browse files
committed
Add R examples for Positron page
1 parent ed9e3e8 commit 221e63a

File tree

4 files changed

+158
-1
lines changed

4 files changed

+158
-1
lines changed

docs/get-started/authoring/_text-editor.md

Lines changed: 158 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Knuth says always be literate [@knuth1984].
219219

220220
## Contents of `references.bib`
221221

222-
```{bibtex filename="references.bib"}
222+
```{.bibtex filename="references.bib"}
223223
@article{knuth1984,
224224
title={Literate programming},
225225
author={Knuth, Donald E.},
@@ -254,6 +254,7 @@ Cross-references make it easier for readers to navigate your document by providi
254254

255255
This example illustrates cross-referencing various types of entities.
256256

257+
::: {.content-visible unless-meta="tool.is_positron"}
257258
```` markdown
258259
---
259260
title: Quarto Crossrefs
@@ -283,6 +284,76 @@ $$
283284
s = \sqrt{\frac{1}{N-1} \sum_{i=1}^N (x_i - \overline{x})^2}
284285
$$ {#eq-stddev}
285286
````
287+
:::
288+
289+
290+
::: {.content-visible when-meta="tool.is_positron"}
291+
292+
::: {.panel-tabset group="language"}
293+
## R
294+
295+
```` markdown
296+
---
297+
title: Quarto Crossrefs
298+
format: html
299+
---
300+
301+
## Overview
302+
303+
See @fig-simple in @sec-plot for a demonstration of a simple plot.
304+
305+
See @eq-stddev to better understand standard deviation.
306+
307+
## Plot {#sec-plot}
308+
309+
```{{r}}
310+
#| label: fig-simple
311+
#| fig-cap: "Simple Plot"
312+
plot(c(1, 23, 2, 4), type = "l", ann = FALSE)
313+
```
314+
315+
## Equation {#sec-equation}
316+
317+
$$
318+
s = \sqrt{\frac{1}{N-1} \sum_{i=1}^N (x_i - \overline{x})^2}
319+
$$ {#eq-stddev}
320+
````
321+
322+
## Python
323+
324+
```` markdown
325+
---
326+
title: Quarto Crossrefs
327+
format: html
328+
---
329+
330+
## Overview
331+
332+
See @fig-simple in @sec-plot for a demonstration of a simple plot.
333+
334+
See @eq-stddev to better understand standard deviation.
335+
336+
## Plot {#sec-plot}
337+
338+
```{{python}}
339+
#| label: fig-simple
340+
#| fig-cap: "Simple Plot"
341+
import matplotlib.pyplot as plt
342+
plt.plot([1,23,2,4])
343+
plt.show()
344+
```
345+
346+
## Equation {#sec-equation}
347+
348+
$$
349+
s = \sqrt{\frac{1}{N-1} \sum_{i=1}^N (x_i - \overline{x})^2}
350+
$$ {#eq-stddev}
351+
````
352+
353+
:::
354+
355+
:::
356+
286357

287358
We cross-referenced sections, figures, and equations. The table below shows how we expressed each of these.
288359

@@ -313,7 +384,24 @@ We cross-referenced sections, figures, and equations. The table below shows how
313384

314385
And finally, here is what this document looks like when rendered.
315386

387+
::: {.content-visible unless-meta="tool.is_positron"}
316388
![](/docs/get-started/authoring/images/crossref-render.png){.border width="600" fig-alt="Rendered page with linked cross references to figures and equations."}
389+
:::
390+
391+
::: {.content-visible when-meta="tool.is_positron"}
392+
393+
::: {.panel-tabset group="language"}
394+
## R
395+
396+
![](/docs/get-started/authoring/images/positron-crossref-render-r.png){.border width="600" fig-alt="Rendered page with linked cross references to figures and equations."}
397+
398+
## Python
399+
400+
![](/docs/get-started/authoring/images/positron-crossref-render-python.png){.border width="600" fig-alt="Rendered page with linked cross references to figures and equations."}
401+
:::
402+
403+
:::
404+
317405

318406
See the article on [Cross References](/docs/authoring/cross-references.qmd) to learn more, including how to customize caption and reference text (e.g. use "Fig." rather than "Figure").
319407

@@ -346,6 +434,7 @@ In this example, we use the `reference-location` option to indicate that we woul
346434

347435
We also use the `column: screen-inset` cell option to indicate we would like our figure to occupy the full width of the screen, with a small inset.
348436

437+
::: {.content-visible unless-meta="tool.is_positron"}
349438
```` markdown
350439
---
351440
title: Quarto Layout
@@ -385,6 +474,74 @@ plt.show()
385474
Here is what this document looks like when rendered.
386475

387476
![](images/layout-render.png){.border fig-alt="Document with Quarto Layout title at the top followed by Placing Colorbars header with text below it. Next to the text is a footnote in the page margin. Below the text is a toggleable code widget to hide/reveal the code followed by four plots displayed in two rows and two columns."}
477+
:::
478+
479+
::: {.content-visible when-meta="tool.is_positron"}
480+
481+
::: {.panel-tabset group="language"}
482+
483+
## R
484+
485+
````markdown
486+
---
487+
title: Quarto Layout
488+
format: html
489+
reference-location: margin
490+
---
491+
492+
## Heatmaps
493+
494+
A 2d density estimate of the waiting and eruptions variables from the dataset `faithful`^[See the [documentation](https://rdrr.io/r/datasets/faithful.html) for more details on `faithful` data].
495+
496+
```{{r}}
497+
#| code-fold: true
498+
#| column: screen-inset
499+
#| fig-width: 10
500+
#| fig-height: 4
501+
library(ggplot2)
502+
503+
ggplot(faithfuld, aes(x = waiting, y = eruptions, fill = density)) +
504+
geom_tile() +
505+
scale_fill_viridis_c() +
506+
theme_bw()
507+
```
508+
````
509+
510+
## Python
511+
512+
````markdown
513+
---
514+
title: Quarto Layout
515+
format: html
516+
reference-location: margin
517+
---
518+
519+
## Heatmaps
520+
521+
A 2d density estimate of the waiting and eruptions variables from the dataset `faithful`^[See the [documentation](https://rdrr.io/r/datasets/faithful.html) for more details on `faithful` data].
522+
523+
```{{python}}
524+
#| code-fold: true
525+
#| column: screen-inset
526+
from plotnine import *
527+
from plotnine.data import faithfuld
528+
529+
(
530+
ggplot(faithfuld, aes(x='waiting', y='eruptions', fill='density'))
531+
+ geom_tile()
532+
+ theme_bw()
533+
+ theme(figure_size=(10, 4))
534+
)
535+
```
536+
````
537+
538+
:::
539+
540+
Here is what this document looks like when rendered.
541+
542+
![](images/positron-layout-render.png){.border fig-alt="Document with Quarto Layout title at the top followed by Heatmaps header with text below it. Next to the text is a footnote in the page margin. Below the text is a toggleable code widget to hide/reveal the code followed a wide plot that extends into the right margin."}
543+
544+
:::
388545

389546
You can locate citations, footnotes, and [asides](/docs/authoring/article-layout.html#asides) in the margin. You can also define custom column spans for figures, tables, or other content. See the documentation on [Article Layout](/docs/authoring/article-layout.qmd) for additional details.
390547

222 KB
Loading
209 KB
Loading
174 KB
Loading

0 commit comments

Comments
 (0)