1

我正在努力控制 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()
# ```
4

1 回答 1

1

我认为您可能想要的是fig.retina块选项。

例如,当 时fig.retina = 2,图像的物理尺寸加倍,显示尺寸减半。

out.widthor而言out.height,输入需要是字符。如果你想使用这个选项,你可能喜欢像out.width = "80%".

在此处查看更多绘图选项。

于 2019-10-20T20:11:24.783 回答