我创建了一些表格(使用knitr& kableExtra),在我使用output: html_document时效果很好,但是当我尝试使用output: word_document表格中每个单元格的内容呈现它们时,会打印到 Word 文档中的连续新行上。
是否有:
output: word_document?或者kableExtra::add_header_above和kableExtra::indent_row功能?output: word_document---
title: "A tale of two tables"
output: word_document
---
```{r global_options, R.options=knitr::opts_chunk$set(warning=FALSE, message=FALSE)}
```
```{r two-tables, results='asis', echo=FALSE}
library(tidyverse)
library(knitr)
library(kableExtra)
library(formattable)
a <- tribble(~location, ~'Month (persons)', ~'TTY (persons)', ~'TTY % change',
'new_south_wales',1604,40328,3.3,
'victoria',-2118,13415,3.5,
'queensland',214,10023,3.2,
'south_australia',1969,11787,5.0,
'western_australia',531,1316,1.6,
'tasmania',-887,2428,1.9,
'northern_territory',-44,570,2.4,
'australian_capital_territory',32,-434,-3.1,
'australia',78,1060,4.8)
b <- tribble(~series,~Dec,~Jan,~TTY,
'FT employed', 12700, 49800, 293200, …Run Code Online (Sandbox Code Playgroud) 我正在 rMarkdown 中编写文档,需要在生成 PDF 之前格式化表格。问题是我无法在kable使用命令添加的标题中插入新行add_headers_above。
目前,文本“月份(人)”(这是使用该命令添加的第一个标题)显示为一行。我想打破这一点,以便在“月”和“(人)”之间插入新行。
动机只是为了节省水平页面空间,以便我可以在一张 A4 纸上按大小放置两个表格。
我尝试\n在add_headers_above命令中包含:
[...] %>%
add_header_above(c(" ", 'Month \n (persons)' = 1, "TTY \n (persons)" = 1, "TTY \n (% chg.)" = 1))
但这并没有奏效。
---
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(kableExtra)
library(tibble)
```
```{r}
df <- tribble(~Location, ~Jan_Qrt, ~Jan_year, ~growth,
"New South Wales", 16000, 403300, 3.30,
"Victoria", -21200, 134100, 3.50,
"Queensland", 2100, 100200, 3.20,
"South Australia", 19700, …Run Code Online (Sandbox Code Playgroud) 我想将其中一个ggrepel标签的颜色更改为黑色。我试图通过指定来覆盖继承,...geom_text_repel(...colour='black')但这似乎不起作用。
我试图解决这个问题是在第二个geom_text_repel函数(下面)中。
NB 如果有一种方法可以控制单个geom_text_repel元素的颜色,而不必两次调用该函数,我更愿意这样做。
library("tidyverse")
library("ggthemes")
library("ggrepel")
df1 <- gather(economics, variable_name, observation, -date) %>%
rename(period = date) %>%
filter(variable_name == 'psavert')
df2 <- gather(economics, variable_name, observation, -date) %>%
rename(period = date) %>%
filter(variable_name == 'uempmed')
ggplot(df1, aes(x = period, y = observation, colour = variable_name)) +
geom_line() +
geom_line(data = df2, colour = 'black', size = .8) +
geom_text_repel(
data = subset(df1, period == max(as.Date(period, "%Y-%m-%d"))),
aes(label = variable_name),
size = 3, …Run Code Online (Sandbox Code Playgroud) 我正在尝试在使用 rmarkdown 生成的 HTML 文档的标题中插入带有一些文本的横幅图像。我是 HTML 的新手,但我已经编写了一个基本的网页(见下文),现在我想将它插入 HTML 文档的标题中。
现在我只是想让它工作,所以我一直在使用这个名为melon.png:
我已更新 rmarkdown 中的样板示例以使用in_headerYAML 字段,如下所示:
---
title: "header_test"
author: "Dos"
date: "20 December 2018"
output:
html_document:
includes:
in_header: C:/Users/Dos/Documents/html/CSS Backgrounds.html
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
Run Code Online (Sandbox Code Playgroud)
in_header 中引用的CSS 背景HTML 文件和随附的 …
在长管的末端,我需要将数字舍入到最接近的数百.目前我正在尝试这个:
16036 %>%
round(./100)*100
Run Code Online (Sandbox Code Playgroud)
我希望函数返回16000,如下所示:
round(16036/100)*100
Run Code Online (Sandbox Code Playgroud)
如何使第一个表达式起作用?