Я пытаюсь создать группу графики в цикле и хотел бы добавить подписи выше на , используя этот хук .
Можно ли изменить этот хук, чтобы можно было представить вектор длиной> 1 до capT
и получить тот же результат, что и с fig.cap
, но с подписью выше?
Этот документ заканчивается ошибкой!
Ожидаемый результат будет:
Первый рисунок с первым заголовком, Второй рисунок с вторым заголовком и т. Д.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
<<init, echo=FALSE, results='hide'>>=
library(knitr)
knitr::opts_chunk$set(echo=FALSE,
results='hide',
warning=FALSE,
message=FALSE,
error = FALSE)
f <- function(x, options) {
paste("\\end{kframe}\n",
"\\caption{", options$capT, "}\n",
#"\\begin{figure}",
hook_plot_tex(x, options),
#"\\end{figure}",
"\n\\begin{kframe}", sep = "")
}
knitr::knit_hooks$set(plot = f)
@
Some Text.
<<first, capT=c('one', 'two', 'three')>>=
for(i in 1:3)
{
plot(1:10,1:10)
}
@
\end{document}
Обновление
Это работает сейчас. Это было легко исправить. Но теперь у меня проблема с ggplot2
.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
<<init, echo=FALSE, results='hide'>>=
library(knitr)
knitr::opts_chunk$set(echo=FALSE,
results='hide',
warning=FALSE,
message=FALSE,
error = FALSE)
f <- function(x, options) {
paste("\\end{kframe}\n",
"\\begin{figure}",
"\\caption{", options$capT, "}\n",
hook_plot_tex(x, options),
"\\end{figure}",
"\n\\begin{kframe}", sep = "")
}
knitr::knit_hooks$set(plot = f)
@
Some Text.
<<first, capT=c('one', 'two', 'three')>>=
for(i in 1:3)
{
plot(1:10, 1:10)
}
@
\end{document}
При использовании plot()
приводит к:
заголовок1 - сюжет1;
заголовок2 - сюжет2;
подпись3 - сюжет3;
(ожидаемый результат)
ggplot()
ведет к:
заголовок1 - сюжет1;
заголовок 1 - сюжет 2;
заголовок 1 - сюжет 3;
заголовок2 - сюжет1 и т. д.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\begin{document}
<<init, echo=FALSE, results='hide'>>=
library(knitr)
knitr::opts_chunk$set(echo=FALSE,
results='hide',
warning=FALSE,
message=FALSE,
error = FALSE)
f <- function(x, options) {
paste("\\end{kframe}\n",
"\\begin{figure}",
"\\caption{", options$capT, "}\n",
hook_plot_tex(x, options),
"\\end{figure}",
"\n\\begin{kframe}", sep = "")
}
knitr::knit_hooks$set(plot = f)
@
Some Text.
<<first, capT=c('one', 'two', 'three')>>=
library(ggplot2)
for(i in 1:3)
{
d <- data.frame(a=1:10,b=1:10)
p = ggplot(d, aes(a,b)) + geom_point()
print(p)
}
@
\end{document}
Почему выходные данные из ggplot2 ведут себя по-другому?
Спасибо!