Okay it looks like you need to specify an output latex engine such as latex_engine: xelatex. The default pdflatex does not seem able to d\handle Chinese characters.
Also there is a problem using Chinese characters in the ggplot command. I do not know enough about R encoding to find the problem
Here is some code that almost works but it breaks if I use Chinese characters for the ggtitle. With ggtitle("HI") it compiles and with ggtitle("标题") it breaks
title: "测试文件"
author: "jrkrideau"
date: "20/10/2020"
documentclass: ctexart
output:
rticles::ctex:
latex_engine: xelatex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
options(texlive.verbose = TRUE)
This is just simple attempt. 测试文件
我在测试
正文可以用中文,但ggplot不行,悲伤
library(ggplot2)
dat1 <- data.frame(xx = sample(1:2, 100, replace = TRUE), yy = sample(1:10, 100, replace = TRUE))
ggplot(dat1, aes( yy)) + geom_histogram(bins = 7 ) + ggtitle("HI")
I am sorry I can not be of more help.