我想在图表中使用免费字体Latoggplot2,因为我的 R markdown 文档的其余部分就是用这种字体设置的。
该字体已安装在我的系统上,并且可以在字体簿中使用(仅一次)。
所有可用的字体都随extrafont包一起加载并在extrafontdb.
当我将 Markdown 文档编织为 PDF 时,所有文本都以Lato. 但是,我的 ggPlots 的绘图标签未显示。
我还收到以下警告消息:
Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font width unknown for character 0x20
嵌入文档中包含的字体后,extrafont::embed_fonts所有使用Lato字体的图形都会显示绘图标签,但是
下面提供了一个 MWE,包括带有和不带有 Lato 字体的 ggPlot 图形(Lato 可以在此处免费获得)要随后嵌入字体,需要运行embed_fonts("TestRmd.pdf", outfile="TestRmd_embedded.pdf")
任何帮助是极大的赞赏!
---
title: "Embedding Fonts in PDF"
output: pdf_document
urlcolor: blue
---
```{r echo=FALSE}
library(ggplot2)
```
### Plot with standard font {#standard} …Run Code Online (Sandbox Code Playgroud) 我想在使用 R markdown 生成的 PDF 中包含美人鱼图。
根据这篇文章,mermaid 创建一个 HTML 小部件作为输出。不幸的是,为 xaringan 幻灯片提供的答案不适用于 R markdown 中生成的 PDF。
下面是 Rmd-MWE。任何帮助是极大的赞赏!
---
title: "DiagrammeR: mermaid diagram in Rmd"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
# Simple mermaid diagram
```{r}
library(DiagrammeR)
mermaid("
graph LR
A-->B
", height = '100%', width = '100%')
```
Run Code Online (Sandbox Code Playgroud) 双方natbib并biblatex提供种类繁多的命令中插入引用。
但是,在R markdown 中似乎只有少数可用:
| 描述 | R降价 | natbib 命令 | biblatex 命令 |
|---|---|---|---|
| 经典引文:作者、年份和括号(根据引文风格使用圆括号或方括号) | [@key] |
\citep{key} |
\parencite[Prefix][Suffix]{key} |
| 文本内引用:作者(年份)(不带方括号或带括号,具体取决于引用样式) | @key |
\citet{key} |
\cite[Prefix][Suffix]{key} |
| 仅年份/抑制作者:(年份) | [-@key] |
\citeyear{key} |
\citeyear[Prefix][Suffix]{key} |
| 在参考书目中包含项目而不在文档中引用它 | 未使用的参考文献(nocite) | \nocite{key} |
\nocite{key} |
通常人们想使用更高级的命令,例如只引用作者并隐藏年份。
有没有办法在 R markdown 文档中添加和使用以下 cite 命令以多种输出格式编译,特别是 PDF 和 HTML?
\citetitle{key} Returns the title of the source.
\citeauthor{key} Returns the author(s) of the cited source.
\footcite{key} Creates a footnote within the document.
\fullcite{key} Creates a complete quote like in the bibliography
\footfullcite{key} Creates …Run Code Online (Sandbox Code Playgroud) 我在用Rstudio编译的Rmd报告中使用了美人鱼图。在HTML / PDF输出中,图表上方和下方有很多空白,请参见下面的示例。
# Header
Text
```{r}
library(DiagrammeR)
mermaid("
graph TD
classDef style_main_node fill:orange,stroke:#333,stroke-width:0px;
classDef style_sub_node fill:lightgray,stroke:#333,stroke-width:0px;
0(Top)
0 --> A1(Left)
0 --> B1(Center)
0 --> C1(Right)
class 0 style_main_node;
class A1,B1,C1 style_sub_node;
")
```
Text
Run Code Online (Sandbox Code Playgroud)
有没有办法裁剪/调整图表周围的空白?并可能还要更改其大小?
如何绘制数据包含NA的是“空白”,在stat_summary用geom = "line"?
代替geom_line()使用是可行的geom_path()(请参阅如何使用ggplot2绘制NA间隙以及如何在geom_line 中绘制包含NA的数据作为“间隙”)。
MWE建立在@stuttungr的示例上(从此处开始)
df = data.frame( x = c(1:10), y = c(1:10) )
df[5:7, ]=NA
# get NO gap as expected
ggplot(data=df, aes(x,y)) +
geom_point(color = "green", size = 5) +
geom_line()
Run Code Online (Sandbox Code Playgroud)
# get the gap as expected
ggplot(data=df, aes(x,y)) +
geom_point(color = "green", size = 5) +
geom_path()
Run Code Online (Sandbox Code Playgroud)
# get NO gap unfortunately
ggplot(data=df, aes(x,y)) +
geom_point(color = "orange", size = …Run Code Online (Sandbox Code Playgroud) 我想在用 R markdown 编译的 PDF 报告中包含一个包含 2 列的表格,其中包括图像和文本(图像描述)。在这样做时,我对我的表有以下要求:
宽度:固定列或表格宽度
对齐:列中的内容对齐
文本内容:在代码中也很容易阅读
文本格式:
图像路径:由于图像存储在子目录中,最好使用缩写的图像路径,例如
figpath <- "Folder/Subfolder/" 进而 fig1 <- paste0(figpath, "image1.png")标题:表格标题是必需的
引文:需要添加对表的引用,例如 [@R-base]
参考:其他地方的表格是必需的
理想情况下,该表如下所示:
我根据 LaTex 语法、markdown 语法和 R markdown 语法(使用 kable 和 kableExtra)进行了几次尝试,请参阅下面的 MWE。然而,没有一种方法产生令人满意的结果。LaTex 方法最接近,但不允许包含引文。
带有图像的表格稍后应包含在使用 huskydown 编译的报告(论文)中,该报告与 thesisdown/bookdown 相关。任何帮助是极大的赞赏!
下表总结了我的方法,下面提供的 MWE(有关改进的 LaTex MWE,请参阅 @samcarter 的回复)
YAML header:
header-includes:
\usepackage{array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{table}[H]
\centering
\caption{My caption}
\begin{tabular}{@{} C{6cm} L{9cm} …Run Code Online (Sandbox Code Playgroud) 我想包括图题中的一个脚注中呈现为PDF和HTML的R降价报告(报告是基于bookdown/ thesisdown/ huskydown)。
理想的做法是使用文本引用:
(ref:foo-footnote) Text in the footnote.
Can span multiple lines, but has to start on the line of the text reference.
(ref:foo-caption) My text with a footnote.^[(ref:foo-footnote)]
Run Code Online (Sandbox Code Playgroud)
---
title: "Footnote in Caption"
author: "Test"
output: html_document
#output: pdf_document
---
## Figure with caption which includes a footnote
<!-------------------------------------------------------------------->
<!-- Reference the figure "by number" as usual with \@ref(fig:foo) -->
<!-- Reference the figure "by name" by adding an anchor above the figure: …Run Code Online (Sandbox Code Playgroud) 我正在使用lmerTest::lmer()重复测量数据执行线性回归。
我的模型包含固定效应(具有 5 个级别的因子)和随机效应(主题):
library(lmerTest)
model_lm <- lmer(likertscore ~ task.f + (1 | subject), data = df_long)
Run Code Online (Sandbox Code Playgroud)
我想在我用 生成的回归表中包括观察总数、受试者数量、总 R^2 和固定效应的 R^2 modelsummary()。
我尝试提取这些内容并按照包作者的gof_map 描述构建一个,但没有成功。下面是我从lmerTest::lmer()性能指标中获得的模型输出:
Linear mixed model fit by REML ['lmerModLmerTest']
Formula: likertscore ~ factor + (1 | subject)
Data: df_long
REML criterion at convergence: 6674.915
Random effects:
Groups Name Std.Dev.
subject (Intercept) 1.076
Residual 1.514
Number of obs: 1715, groups: subject, 245
Fixed Effects:
(Intercept) factor1 factor2
3.8262 1.5988 0.3388
factor3 …Run Code Online (Sandbox Code Playgroud) 我想用 ggPairs() 创建一个相关图,其中应该包含
基于@user20650对上述SO问题提供的优秀解决方案,我成功构建了一个函数来生成具有重要性星级的相关值的热图。
不幸的是,当添加(自定义)主题时,彩色 panel.backgrounds 被删除(MWE 在下面提供)。
library(ggplot2)
library(GGally)
# fct. to create heatmap of correlation values with significance stars for upper triangle of ggpairs plot
cor_fun <- function(data, mapping, method="pearson", use="pairwise", ndp=2, sz=5, stars=TRUE, ...){
# grab data
x <- eval_data_col(data, mapping$x)
y <- eval_data_col(data, mapping$y)
# calculate correlation: for significance stars
corr <- cor.test(x, y, method=method)
est <- corr$estimate
lb.size <- sz* abs(est)
# get significance stars
if(stars){
stars …Run Code Online (Sandbox Code Playgroud) 如何调整呈现为输出格式的 R markdown 演示文稿的幻灯片宽度beamer以生成 LaTex/PDF 文件?为了能够快速调整到给定的演示设备(宽屏、4:3 屏幕等),理想情况下可以轻松更改宽高比以采用不同的值。
---
title: "Adjust the width/aspect ratio of slides"
output:
# beamer_presentation: default
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
---
## Some Slides
some content
Run Code Online (Sandbox Code Playgroud) 如何在`rmarkdown::beamer_presentation 中垂直居中对齐多列的内容?
正如对这个 SO 帖子的回答的评论中所建议的那样,我尝试过::: {.column width="30%"},但这对我不起作用。
如果有一种简单的方法可以为每一列以不同的方式对齐内容,那也将非常有用(例如,c1:顶部,c2:中间,c3:底部,c4:中间)。
---
output:
bookdown::pdf_book:
base_format: rmarkdown::beamer_presentation
slide_level: 2
keep_tex: true
---
## Figures in columns top-aligned
::: columns
:::: {.column width="30%"}
```{r top-p-5, echo=FALSE, out.width='30%'}
plot(pressure[1:5,])
```
::::
:::: {.column width="30%"}
```{r top-p-10, echo=FALSE, out.width='50%'}
plot(pressure[1:10,])
```
::::
:::: {.column width="30%"}
```{r top-p-all, echo=FALSE, out.width='100%'}
plot(pressure[1:nrow(pressure),])
```
::::
:::
## Figures in columns center-aligned (not working)
::: columns
::: {.column width="30%"}
```{r center-p-5, echo=FALSE, …Run Code Online (Sandbox Code Playgroud) r ×9
r-markdown ×8
latex ×4
markdown ×4
ggplot2 ×3
beamer ×2
diagrammer ×2
mermaid ×2
biblatex ×1
bibtex ×1
bookdown ×1
caption ×1
citations ×1
extrafont ×1
footnotes ×1
ggally ×1
ggpairs ×1
kable ×1
kableextra ×1
lme4 ×1
lmertest ×1
modelsummary ×1
regression ×1