我正在努力控制 Markdown 演示文稿中图像的大小和 DPI。我正在使用该xaringan
软件包。
fig.width 和 fig.height 的块选项可以直观地工作,直到我更改 dpi 设置。对于更高的 dpi 设置,我似乎无法生成具有适当大小和外观的图像。增加dpi会使图像变大;我可以通过减小 fig.height 和 fig.width 来弥补,但这会破坏绘图区域和字体大小的缩放。任何帮助表示赞赏!
我包含了一些代码,但我将它们全部放在注释中,因为否则 StackOverflow 会对格式化块选项感到困惑。
# ---
# title: Test plot appearance
# output:
# xaringan::moon_reader:
# css: [chocolate-fonts]
# lib_dir: libs
# nature:
# highlightStyle: github
# countIncrementalSlides: false
# ---
#
# ```{r include = FALSE}
# library(ggplot2)
# ```
#
# # Default DPI is low res
# ```{r echo = FALSE, fig.width = 6, fig.height = 4}
# ggplot(mtcars) + aes(cyl, mpg) + geom_point()
# ```
#
# ---
# # 300 DPI makes image huge
# ```{r echo = FALSE, fig.width = 6, fig.height = 4, dpi = 300}
# ggplot(mtcars) + aes(cyl, mpg) + geom_point()
# ```
#
# ---
# # I can compensate with small fig.width and height, but looks ugly
# ```{r echo = FALSE, fig.width = 2, fig.height = 2, dpi = 300}
# ggplot(mtcars) + aes(cyl, mpg) + geom_point()
# ```
#
# ---
# # out.width and out.height cause image not to appear
# ```{r echo = FALSE, out.width = 6, out.height = 4, dpi = 300}
# ggplot(mtcars) + aes(cyl, mpg) + geom_point()
# ```