R语言 创建表格和图形的图形可链接

cidc1ykv  于 2023-06-03  发布在  其他
关注(0)|答案(1)|浏览(263)

我一直在努力为我的化学课制作一个符合美国化学学会标准的结果页面。我试过不同的方法,但它们并不是我想要的。有没有人知道一个好的一般方法,使图引用,可以从文本链接?
这是我做的一个示例结果页面。

---
title: "Lab 2 Results"
output: html_document
---

```{r, echo = FALSE, warning = FALSE, message = FALSE}
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;
}
juzqafwq

juzqafwq1#

您可以考虑在Rmarkdown文档中使用以下代码进行PDF输出:
''' {r fig,fig.cap =“\label{fig:myfig}Plot”}
plot(rnorm(10),type =“l”)'''
以下是我的数字:\ref{fig:myfig}。
对于HTML输出,可以考虑编织到bookdown::html_document2:

output:
 bookdown::html_document2
link-citations: yes

使用link-citations选项:是的。在文本后面,你可以使用@ref(fig:myfig)

相关问题