【问题标题】:Customizing plot DPI in markdown presentation在降价演示中自定义绘图 DPI
【发布时间】:2019-10-14 15:04:43
【问题描述】:

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

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

我包含了一些代码,但我把它们都放在了 cmets 中,否则 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()
# ```

【问题讨论】:

    标签: r knitr xaringan


    【解决方案1】:

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

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

    对于out.widthout.height,输入需要是字符。如果你想使用这个选项,你可以像out.width = "80%"一样使用它。

    查看更多情节选项here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多