r语言 - 在降价演示中自定义绘图 DPI



我正在努力控制降价演示文稿中图像的大小和DPI。 我正在使用xaringan包。

fig.width 和 fig.height 的块选项直观地工作,直到我更改 dpi 设置。 对于更高的 dpi 设置,我似乎无法生成具有适当大小和外观的图像。 增加 dpi 会使图像变大;我可以通过减小图高和图宽来补偿,但这会破坏绘图区域和字体大小的缩放。 任何帮助不胜感激!

我包含了一些代码,但我将它们全部放在注释中,因为否则 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()
# ```

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

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

out.widthout.height而言,输入必须是字符。如果要使用此选项,则可能希望像out.width = "80%"一样使用它。

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

最新更新