Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 尝试在kable上对齐图像时,更改latex_引擎会出错_R_R Markdown_Knitr_Kable_Xelatex - Fatal编程技术网

R 尝试在kable上对齐图像时,更改latex_引擎会出错

R 尝试在kable上对齐图像时,更改latex_引擎会出错,r,r-markdown,knitr,kable,xelatex,R,R Markdown,Knitr,Kable,Xelatex,我试图模仿这个问题中的答案 答案真的符合我的要求。但当latex_引擎为Xeletex时,它会出错 但我真的需要用中文展示输出 这是密码 --- title: "Untitled" output: pdf_document: latex_engine: xelatex --- This example highlights the issue I am having with formatting a nice table with the graphics and

我试图模仿这个问题中的答案

答案真的符合我的要求。但当latex_引擎为Xeletex时,它会出错

但我真的需要用中文展示输出

这是密码

---
title: "Untitled"
output: 
    pdf_document:
        latex_engine: xelatex
---

This example highlights the issue I am having with formatting a nice table with the graphics and the vertical alignment of text.

```{r echo=FALSE, results='hide', warning=FALSE, message=FALSE}
## Load modules
library(dplyr)
library(tidyr)
library(ggplot2)

## Create a local function to plot the z score
varianceChart <- function(df, personNumber) {
  plot <- df %>%
             filter(n == personNumber) %>%
             ggplot() +
             aes(x=zscore, y=0) +
             geom_rect(aes(xmin=-3.32, xmax=-1.96, ymin=-1, ymax=1), fill="orange2", alpha=0.8) + 
             geom_rect(aes(xmin=1.96, xmax=3.32, ymin=-1, ymax=1), fill="olivedrab3", alpha=0.8) +
             geom_rect(aes(xmin=min(-4, zscore), xmax=-3.32, ymin=-1, ymax=1), fill="orangered3") + 
             geom_rect(aes(xmin=3.32, xmax=max(4, zscore), ymin=-1, ymax=1), fill="chartreuse4") +
             theme(axis.title = element_blank(), 
                   axis.ticks = element_blank(), 
                   axis.text = element_blank(),
                   panel.grid.minor = element_blank(),
                   panel.grid.major = element_blank()) +
                   geom_vline(xintercept=0, colour="black", alpha=0.3) +
                   geom_point(size=15, shape=4, fill="lightblue") ##Cross looks better than diamond
  return(plot)
}

## Create dummy data
Person1 <- rnorm(1, mean=10, sd=2) 
Person2 <- rnorm(1, mean=10, sd=2)
Person3 <- rnorm(1, mean=10, sd=2)
Person4 <- rnorm(1, mean=10, sd=2) 
Person5 <- rnorm(1, mean=10, sd=2) 
Person6 <- rnorm(1, mean=6,  sd=1) 

## Add to data frame
df <- data.frame(Person1, Person2, Person3, Person4, Person5, Person6)

## Bring all samples into one column and then calculate stats
df2  <- df %>% gather(key=Person, value=time)
mean <- mean(df2$time)
sd   <- sqrt(var(df2$time))

stats <- df2 %>%
             mutate(n = row_number()) %>%
             group_by(Person) %>%
             mutate(zscore = (time - mean) / sd)

graph_directory <- getwd() #'./Graphs'

## Now to cycle through each Person and create a graph
for(i in seq(1, nrow(stats))) {
  print(i)
  varianceChart(stats, i)

  ggsave(sprintf("%s/%s.png", graph_directory, i), plot=last_plot(), units="mm", width=100, height=20, dpi=1200)
}

## add a markup reference to this dataframe
stats$varianceChart <- sprintf('\\raisebox{-.4\\totalheight}{\\includegraphics[width=0.2\\textwidth, height=20mm]{%s/%s.png}}', graph_directory, stats$n) 

df.table <- stats[, c(1,2,5)]
colnames(df.table) <- c("Person Name", "Time taken", "Variance Chart")
```

```{r}
library(knitr)
kable(df.table[, c(1,2)], caption="Rows look neat and a sensible distance apart")
kable(df.table, caption="中文中文")
```
---
标题:“无标题”
输出:
pdf\U文件:
乳胶引擎:Xeletex
---
这个例子突出了我在用图形和文本的垂直对齐格式化一个漂亮的表格时遇到的问题。
```{r echo=FALSE,results='hide',warning=FALSE,message=FALSE}
##加载模块
图书馆(dplyr)
图书馆(tidyr)
图书馆(GG2)
##创建一个局部函数来绘制z分数
方差Chart%
ggplot()+
aes(x=zscore,y=0)+
几何误差(aes(xmin=-3.32,xmax=-1.96,ymin=-1,ymax=1),fill=“orange2”,alpha=0.8)+
几何校正(aes(xmin=1.96,xmax=3.32,ymin=-1,ymax=1),fill=“olivedrab3”,alpha=0.8)+
geom_rect(aes(xmin=min(-4,zscore),xmax=-3.32,ymin=-1,ymax=1),fill=“orangered3”)+
geom_rect(aes(xmin=3.32,xmax=max(4,zscore),ymin=-1,ymax=1),fill=“chartreuse4”)+
主题(axis.title=element_blank(),
axis.ticks=元素_blank(),
axis.text=元素_blank(),
panel.grid.minor=元素_blank(),
panel.grid.major=元素_blank()+
几何线(xintercept=0,color=“黑色”,alpha=0.3)+
几何点(大小=15,形状=4,fill=“lightblue”)###十字架看起来比钻石好
返回(绘图)
}
##创建虚拟数据

Person1我无法重现错误消息。取而代之的是,我用空盒子装汉字,这也没什么帮助。我很确定你收到的错误信息不是根本原因。我怀疑解决方案是选择一组支持所需字符的字体。例如,我安装了适用于Noto的CJK变体,因此以下添加到YAML头中的功能对我有效:

mainfont: Noto Serif CJK TC
monofont: Noto Sans Mono CJK TC
sansfont: Noto Sans CJK TC
结果:

顺便说一句,在电视和电视上遵循建议通常是有帮助的

选项(tinytex.verbose=TRUE)

我记得读过一篇文章,一慧建议选择tinytex。我建议安装tinytex,但我还有一个问题。我不能用这种方法更改列宽。当我应用“kableExtra”包时,图片不会显示出来,更不用说column_spec函数了。我也使用了“linebreak”函数,但它仍然不起作用;图书馆(kableExtra);可折叠(df.table,“latex”)%%>%kable\u样式(全宽=F)%%>%column\u规格(4,width=“4em”)@蔡佳諭 这很难根据评论的格式来判断。你能发一个新问题吗?@RalfStubner好的~我会试着复制它。
mainfont: Noto Serif CJK TC
monofont: Noto Sans Mono CJK TC
sansfont: Noto Sans CJK TC