求符合ACS标准的可链接图表引用的化学实验结果页制作方法
实现符合ACS标准的可跳转图表引用(R Markdown)
我正在为化学课程制作符合美国化学学会(ACS)标准的实验结果页,尝试过多种方法但均不符合预期需求,请问是否有通用方法实现可从文本跳转的图表引用?以下是我制作的示例结果页代码:
--- title: "Lab 2 Results" output: html_document ---
library(tidyverse) library(ggpmisc) solution_1 <- tibble( aliquot = c(1:7), time_sec = c(29.07, 26.72, 25.91, 21.37, 18.98, 18.68, 18.07), Cum_time = cumsum(time_sec), total_mol_S2O8 = seq(0.0002, length.out = 7, by = 0.0002) ) solution_2 <- tibble( aliquot = c(1:7), time_sec = c(29.94, 29.81, 25.71, 24.11, 23.20, 21.69, 21.53), Cum_time = cumsum(time_sec), total_mol_S2O8 = seq(0.0002, length.out = 7, by = 0.0002) ) solution_3 <- tibble( aliquot = c(1:7), time_sec = c(26.81, 21.49, 19.70, 18.98, 19.26, 18.85, 21.73), Cum_time = cumsum(time_sec), total_mol_S2O8 = seq(0.0002, length.out = 7, by = 0.0002) ) colnames(solution_1) <- c('aliquot', 'time', 'cum_time', 'moles_S2O8') colnames(solution_2) <- c('aliquot', 'time', 'cum_time', 'moles_S2O8') colnames(solution_3) <- c('aliquot', 'time', 'cum_time', 'moles_S2O8')
knitr::kable(solution_1, caption = 'figure 1.1: Solution 1',col.names = c('aliquot', 'time(s)', 'cumulative time (s)', 'total moles of S2O8 consumed'))
ggplot(data = solution_1, mapping = aes(x = time, y = moles_S2O8)) + stat_poly_line(se = FALSE)+ stat_poly_eq(use_label('eq'), label.x = 'right') + geom_point()+ labs(y = bquote('moles of'~S[2]*O[8]^-4), x = 'time(s)', title = bquote('Rate of reaction per aliquot of'~S[2]*O[8]^-4), subtitle = 'Solution 1')
knitr::kable(solution_2, caption = 'figure 2: Solution 2',col.names = c('aliquot', 'time(s)', 'cumulative time (s)', 'total moles of S2O8 consumed'))
ggplot(data = solution_2, mapping = aes(x = time, y = moles_S2O8)) + stat_poly_line(se = FALSE)+ stat_poly_eq(use_label('eq'), label.x = 'right') + geom_point()+ labs(y = bquote('moles of'~S[2]*O[8]^-4), x = 'time(s)', title = bquote('Rate of reaction per aliquot of'~S[2]*O[8]^-4), subtitle = 'Solution 2')
knitr::kable(solution_3, caption = 'figure 3: Solution 3',col.names = c('aliquot', 'time(s)', 'cumulative time (s)', 'total moles of S2O8 consumed'))
ggplot(data = solution_3, mapping = aes(x = time, y = moles_S2O8)) + stat_poly_line(se = FALSE)+ stat_poly_eq(use_label('eq'), label.x = 'right') + geom_point()+ labs(y = bquote('moles of'~S[2]*O[8]^-4), x = 'time(s)', title = bquote('Rate of reaction per aliquot of'~S[2]*O[8]^-4), subtitle = 'Solution 3')
table { margin: auto; border-top: 1px solid #666; border-bottom: 1px solid #666; } table thead th { border-bottom: 1px solid #ddd; } th, td { padding: 5px; } thead, tfoot, tr:nth-child(even) { background: #eee; } h1 { text-align: center; }
解决方案
要实现符合ACS标准的可跳转图表/表格引用,核心是利用knitr的代码块标签生成锚点,配合Markdown链接实现跳转,同时调整格式满足ACS规范:
1. 规范代码块标签与ACS格式
为每个表格、图表代码块添加唯一label,并按照ACS要求设置标题(表格标题在上方,图表标题在下方,编号格式为Table X/Figure X)。
2. 添加文本跳转链接
使用[引用文本](#标签名)的Markdown语法,实现从文本跳转到对应图表/表格。
3. 修正化学符号细节
ACS中过二硫酸根的正确电荷为-2,需修正代码中的S[2]*O[8]^-4为S[2]*O[8]^-2。
修改后的完整代码示例
--- title: "Lab 2 Results" output: html_document ---
library(tidyverse) library(ggpmisc) # 数据处理(简化重命名逻辑) solution_1 <- tibble( aliquot = c(1:7), time_sec = c(29.07, 26.72, 25.91, 21.37, 18.98, 18.68, 18.07), Cum_time = cumsum(time_sec), total_mol_S2O8 = seq(0.0002, length.out = 7, by = 0.0002) ) %>% rename(time = time_sec, cum_time = Cum_time, moles_S2O8 = total_mol_S2O8) solution_2 <- tibble( aliquot = c(1:7), time_sec = c(29.94, 29.81, 25.71, 24.11, 23.20, 21.69, 21.53), Cum_time = cumsum(time_sec), total_mol_S2O8 = seq(0.0002, length.out = 7, by = 0.0002) ) %>% rename(time = time_sec, cum_time = Cum_time, moles_S2O8 = total_mol_S2O8) solution_3 <- tibble( aliquot = c(1:7), time_sec = c(26.81, 21.49, 19.70, 18.98, 19.26, 18.85, 21.73), Cum_time = cumsum(time_sec), total_mol_S2O8 = seq(0.0002, length.out = 7, by = 0.0002) ) %>% rename(time = time_sec, cum_time = Cum_time, moles_S2O8 = total_mol_S2O8)
实验结果分析
如表1所示,Solution 1的反应时间随S₂O₈²⁻消耗量增加而缩短,二者的线性关系见图1。
Solution 2(表2、图2)和Solution 3(表3、图3)呈现相似趋势,反应速率的细微差异可能源于实验条件波动。
```{r table-sol1, echo=FALSE} knitr::kable(solution_1, caption = 'Table 1. Solution 1: Reaction Time and S₂O₈²⁻ Consumption Data', col.names = c('Aliquot', 'Time (s)', 'Cumulative Time (s)', 'Total Moles of S₂O₈²⁻ Consumed'))
```r ```{r fig-sol1, echo=FALSE, fig.cap='Figure 1. Reaction Rate per Aliquot of S₂O₈²⁻ (Solution 1)'} ggplot(data = solution_1, mapping = aes(x = time, y = moles_S2O8)) + stat_poly_line(se = FALSE)+ stat_poly_eq(use_label('eq'), label.x = 'right') + geom_point()+ labs(y = bquote('Moles of'~S[2]*O[8]^-2), x = 'Time (s)')
```r ```{r table-sol2, echo=FALSE} knitr::kable(solution_2, caption = 'Table 2. Solution 2: Reaction Time and S₂O₈²⁻ Consumption Data', col.names = c('Aliquot', 'Time (s)', 'Cumulative Time (s)', 'Total Moles of S₂O₈²⁻ Consumed'))
```r ```{r fig-sol2, echo=FALSE, fig.cap='Figure 2. Reaction Rate per Aliquot of S₂O₈²⁻ (Solution 2)'} ggplot(data = solution_2, mapping = aes(x = time, y = moles_S2O8)) + stat_poly_line(se = FALSE)+ stat_poly_eq(use_label('eq'), label.x = 'right') + geom_point()+ labs(y = bquote('Moles of'~S[2]*O[8]^-2), x = 'Time (s)')
```r ```{r table-sol3, echo=FALSE} knitr::kable(solution_3, caption = 'Table 3. Solution 3: Reaction Time and S₂O₈²⁻ Consumption Data', col.names = c('Aliquot', 'Time (s)', 'Cumulative Time (s)', 'Total Moles of S₂O₈²⁻ Consumed'))
```r ```{r fig-sol3, echo=FALSE, fig.cap='Figure 3. Reaction Rate per Aliquot of S₂O₈²⁻ (Solution 3)'} ggplot(data = solution_3, mapping = aes(x = time, y = moles_S2O8)) + stat_poly_line(se = FALSE)+ stat_poly_eq(use_label('eq'), label.x = 'right') + geom_point()+ labs(y = bquote('Moles of'~S[2]*O[8]^-2), x = 'Time (s)')
```css table { margin: auto; border-top: 1px solid #666; border-bottom: 1px solid #666; } table thead th { border-bottom: 1px solid #ddd; } th, td { padding: 5px; } thead, tfoot, tr:nth-child(even) { background: #eee; } h1 { text-align: center; } /* 调整图表标题格式,贴合ACS风格 */ .caption { text-align: center; font-size: 0.9em; margin-top: 10px; }
内容的提问来源于stack exchange,提问作者Jakiepoo21
相关产品推荐
相关产品推荐

