WordPress网站转HTPPS,WordPress程序漏洞,深圳网站建设制作视频软件,php网站开发使用技术PDF下载简介
本文是《手把手教你使用 Quarto 构建文档》第三期#xff0c;前两期分别介绍了#xff1a; 第一期 介绍了Quarto 构建文档的原理#xff1b;可创建的文档类型#xff1b;对应的参考资源分享。 第二期 介绍了如何使用 Quarto#xff0c;并编译出文档#xff08;PDF…简介
本文是《手把手教你使用 Quarto 构建文档》第三期前两期分别介绍了 第一期 介绍了Quarto 构建文档的原理可创建的文档类型对应的参考资源分享。 第二期 介绍了如何使用 Quarto并编译出文档PDFMS Wordhtml等。
本期将介绍 Quarto 细节设置部分目录如下 文章目录 简介代码框展示隐藏代码折叠代码 图形设置交叉引用多图排版 数据框内联代码缓存 代码框展示
根据第二期的内容读者可以编译出各种格式的文档默认情况下 HTML 输出结果如下 隐藏代码
如果读者需要隐藏所有代码而只展示代码结果可以通过 echo: false 实现。
---
title: Quarto Computations
execute:echo: false
---运行后的结果如下 如果需要指定展示某个代码可以在该代码块中加入 echo: true。 注意这里的选项设置和 R markdown 非常相似具体见Rmarkdown教程3。例如eval、include、prompt、comment、results 和错误信息选项 warning、error、message 等。有关其他 Knitr 单元选项详细信息可见这。 折叠代码
如果读者想折叠代码而不是隐藏所有代码可使用 code-fold。
---
title: Quarto Computations
format:html:code-fold: true
---还可以提供对代码折叠的全局控制尝试添加 code-tools: 。
---
title: Quarto Computations
format:html:code-fold: truecode-tools: true
---图形设置
可以通过设置 fig-width 和 fig-height 来改变宽高比fig-cap 修改标签以进行交叉引用fig-alt 添加替代文本。
交叉引用
使用以下代码设置图片展示效并使用 fig-scatterplot 进行交叉引用。
#| label: fig-scatterplot
#| fig-cap: City and highway mileage for 38 popular models of cars.
#| fig-alt: Scatterplot of city vs. highway mileage for cars, where points are colored by the number of cylinders. The plot displays a positive, linear, and strong relationship between city and highway mileage, and mileage increases as the number of cylinders decreases.
#| fig-width: 6
#| fig-height: 3.5多图排版
如果读者想并排两个图形并为每个图添加描述性小标题。可以配合 使用 layout-ncol: 2、fig-cap 和 fig-subcap。读者可以使用 fig-mpg 引用母图。 fig-mpg-1 和 fig-mpg-2 引用子图。
#| label: fig-mpg
#| fig-cap: City and highway mileage for 38 popular models of cars.
#| fig-subcap:
#| - Color by number of cylinders
#| - Color by engine displacement, in liters
#| layout-ncol: 2
#| column: pageggplot(mpg, aes(x hwy, y cty, color cyl)) geom_point(alpha 0.5, size 2) scale_color_viridis_c() theme_minimal()ggplot(mpg, aes(x hwy, y cty, color displ)) geom_point(alpha 0.5, size 2) scale_color_viridis_c(option E) theme_minimal()数据框
可以使用 df-print 文档选项控制默认情况下打印数据框的方式。 可用选项包括
选项描述default将默认的S3方法用于数据框架。kable使用 knitr::kable()函数生成 Markdown 表格。tibble使用 tibble 包的纯文本表。paged使用 rmarkdown::paged_table() 实现带有行和列溢出分页的 HTML 表格。
例如指定对数据框进行分页打印
---
title: Document
format: html:df-print: paged
---内联代码
要在 markdown 中包含可执行表达式请将表达式括在r中。 例如我们可以使用内联代码来说明数据中的观察数量
我们数据中包含了 r nrow(mpg) 个数据。缓存
如果文档包含计算时间过长的代码块读者可能需要缓存这些代码块的结果。可以在 YAML 执行选项中设置 cache: true 。
execute:cache: true缓存所有代码块可能不合适也可以在特定的代码块中设置
#| cache: true渲染文档时将看到在工作目录中创建了一个新文件夹其名称与文档相同后缀为 _cache。该文件夹包含缓存的结果。如果读者对该方面感兴趣可见详细缓存细节。