This a tutorial on how to use rmarkdown 在这里打字不需要加#号 use tooth growth dataset.
to run R code is a markdown file, we need to dentote the section that is considered R code(要标出Rcode部分).这部分被称为code chunk below is code chunk:
## len supp dose
## 1 4.2 VC 0.5
## 2 11.5 VC 0.5
## 3 7.3 VC 0.5
## 4 5.8 VC 0.5
## 5 6.4 VC 0.5
## 6 10.0 VC 0.5
fit <- lm(len ~ dose, data = Toothdata)
b <- fit$coefficients
plot(len ~ dose, data = Toothdata)
abline(lm(len ~ dose, data = Toothdata))The slope of the regression line is 9.7635714.
第二课
需要在#后面加空格才能起作用
we can use nice quotes into the markdown document. we do this by using the “>”这是一种引用形式,可以放在网页上?
“Genes are the story, and DNA is the language that the story is written in.”
— Sam Kean
can put formatted formulas into markdown in (两个美元符号)
Hard-weinberg Formula \[p^2 +2pq + q^w=1\] And you can get really complex formula \[\Theta= \begin{pmatrix}\alpha & \beta\\ \gamma & \delta \end{pmatrix}\]
latex就是我用的poster网站,可以找到用在表格中的符号
There are also options for your R Markdown file on how knitr interprets the code chunk.
Eval(T or F): whether or not to evaluate the code chunk(即不显示结果)
Echo(T or F): whether or not to show the code for the chunk(不影响显示结果) 下方例子会导致什么都不显示
Cache: If enable, the same code chunk will not be evaluated the next time that the knitr is run. Great for code that has LONG runtimes.(缓存) Cache(缓存)控制是否在下次“编织”时跳过重复计算。 如果 cache = TRUE,knitr 会保存上一次的运行结果; 下次执行时若代码没变,就直接用缓存结果,而不重新运行
fig.width or fig.height: the (graphical device) size of the R plots in inches. 设置 R 绘图的宽度和高度 The figures are first written to the knitr document then to files that are saved separately.
out.width and out.height: the output size of the R plots in the document(这是直接改原始文件,上面是改的机器输出的文件)
fig.cap: 加入figure caption
fit <-lm(len ~ dose,data = Toothdata)
b <- fit$coefficients
plot(len ~ dose, data = Toothdata)
abline(lm(len ~ dose, data = Toothdata))The tooth growth of pigs
we can also add a table of contents to HTML document we do this by altering the YAMLcode(文件最上面的,有title什么的) we can add this: title: “rmarkdown learning” output: html_document: toc: true toc_float: true
date: “2025-11-11”
toc:增加目录 toc_float:增加目录的下拉菜单
We can also add tabs in our report: need to specify each section that you want to become a tab by placing “{.tabset}” after the line. {.tabset}可以给模块增加smaller headers
add themes to HTML document that change highlighting color and hyperlink color of html output. 就是改网站标题的颜色 方法: you can change the theme in hte YAML to one of the followings: cerulean journal flatly readable spacelab united cosmo lumen paper sandstone simplex yeti null
you can change the color by specifying highlight: 在yaml中加highlight: default tango payments kate monochrome espresso zenburn
Theme和highlight只能选一个 Theme作用范围: 整个 HTML文档的布局与配色(标题、正文、边距、字体、背景等)。
highlight作用范围: R 代码块({r} …)中代码与输出的显示颜色风格。
use the code_folding option to allow the reader to toggle between displaying the code and hiding the code.隐藏程序 YAML, is down with code_folding: hide
There are a Ton of options and ways for you to customize your R code using the HTML format. This is a great way to display a portoflio of your work if you try to market yourself to interested parties 总体来说可以做自己的一个网站