我在 RStudio 中将 R 脚本 (.R) 转换为RMarkdown
文件 (.rmd),然后按“knit html”会生成两个输出文件(即 .html 和 .md 文件)。我面临2个问题:
该html
文件显示ggplot
图表的标题被切掉了。我已将原来的宽度 11 更改为新的宽度 15:
ggsave(file=outFile, width=15, height=7)
我将如何解决这个问题?以及如何将 .md 文件转换为 PDF 文件?
我在 RStudio 中将 R 脚本 (.R) 转换为RMarkdown
文件 (.rmd),然后按“knit html”会生成两个输出文件(即 .html 和 .md 文件)。我面临2个问题:
该html
文件显示ggplot
图表的标题被切掉了。我已将原来的宽度 11 更改为新的宽度 15:
ggsave(file=outFile, width=15, height=7)
我将如何解决这个问题?以及如何将 .md 文件转换为 PDF 文件?
Your question is not exactly clear. I'm not sure, for example, why you are using ggsave()
to begin with. You can directly create a "ggplot" image in your file to knit
and set your figure width and height in your input file.
In a ".Rmd" file, your code might look something like:
```{r fig.width=7, fig.height=4, echo=FALSE}
library(ggplot2)
qplot(mpg, wt, data=mtcars)
```
The echo=FALSE
will make it so that the code doesn't display, but the resulting plot will. The figure width and height have been set with the relevant arguments.
If you wanted to convert your resulting markdown file to PDF, I would recommend looking at Pandoc which will allow you to do something like the following to convert your file to a PDF:
pandoc infile.md -o outfile.pdf
Alternatively, you can use R Sweave instead of R Markdown in R/RStudio. For instance, if you create a new "Rnw" file in RStudio and paste the following in, you'll have the option to directly compile a PDF instead of compile an HTML.
\documentclass{article}
\begin{document}
<<fig.width=5, fig.height=3, echo=FALSE>>=
library(ggplot2)
qplot(mpg, wt, data=mtcars)
@
\end{document}