【问题标题】:How to render ggplot2 graphics correctly into word with R markdown?如何使用 R markdown 将 ggplot2 图形正确渲染成单词?
【发布时间】:2021-12-07 22:46:49
【问题描述】:

在将 ggplot2 图形渲染到 MS Word 文档时遇到一些问题:

---
title: "test"
author: "Philipp"
date: "20 10 2021"
output: word_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

R 降价


library(tidyverse)
library(ggrepel)

a <- rep(1:50, 200)

b <- sample(x= c("a", "b", "c", "d", "e"), size= 100000, replace= TRUE)

c <- rep(1000:1049, 200)

df <- data.frame(a,b,c) 

ggplot(df, aes(x= b)) + 
  geom_bar() + 
  scale_y_continuous(limits= c(0, 600)) +
  facet_wrap(~a)+
  geom_text(
    data=df, x=4.5, y=550, aes(label=c), size= 3
  )



当我将此代码编织到 MS Word 中时,y 轴上的轴文本在 word 文档中重叠,有时条形变得不可见。我试图最小化轴文本的大小,但这是以牺牲可读性为代价的。但是,在 RStudio 的缩放模式下,一切正常。

这个问题有解决办法吗?

在 MS Word 中,图形如下所示:

【问题讨论】:

    标签: r ggplot2 ms-word r-markdown knitr


    【解决方案1】:

    同时我找到了解决方案:

    {r, fig.width= 10, fig.height= 7, echo= FALSE}
    
    plotname
    

    您可以在代码块的标题中调整图形的大小。这将在 MS word 文档中转换为clean(er) 图形。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-29
      • 2019-11-15
      • 2020-11-14
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      • 2013-06-30
      • 1970-01-01
      相关资源
      最近更新 更多