Ben*_*n G 2 powerpoint r ggplot2 rstudio
因此,我需要将在R / Rstudio中制作的图复制并粘贴到PowerPoint中(不幸的是,我的政府客户要求所有内容都在PowerPoint中,否则只需将图形放在Rmarkdown文件中就可以轻松解决此问题)。直到最近我发现透明对象无法复制并粘贴到PowerPoint中才成为一个大问题,至少在我一直使用的方法中(导出>复制为图元文件>复制图>粘贴) 。相反,在透明对象所在的位置,现在什么都没有了。我读了一些书后发现,这与我的“图形引擎”不支持透明对象有关,并且“开罗”引擎可以,但是我不明白这意味着什么,或者是否可以在Rstudio中更改微软幻灯片软件。
这是一些示例代码:
iris %>%
mutate(small_petal = if_else(Petal.Width > 1.5, "big", "small")) %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species, alpha = small_petal)) +
geom_point()
Run Code Online (Sandbox Code Playgroud)
我尝试了一种非常奢侈的解决方法来获取所需的颜色。我制作了不透明的自定义RGB值,以模仿我想要的透明度。然后,我使用mutate四个if_elses 将它们附加到data.frame (每种alpha颜色组合使用一种颜色)。然后scale_fill_identity,我使用我的自定义颜色,但随后生成了带有不需要元素的图例。我需要使用以下内容使图例与至少一些我想要的元素一起出现:
scale_fill_identity(guide = "legend",
labels = c("DUMMY LABEL",
"DUMMY LABEL",
"Small Petal",
"Big Petal"),
breaks = unique(iris$custom_colors))
Run Code Online (Sandbox Code Playgroud)
然后,我删除PowerPoint中不需要的图例对象。任何帮助是极大的赞赏。
您是否尝试过从RMarkdown直接渲染到PowerPoint?该功能是最近才添加的。您必须安装RMarkdown和RStudio的开发版才能获得它。前面链接中的指令,但tldr; 如下:
devtools::install_github("rstudio/rmarkdown") 在Mac上尝试时,我认为输出看起来不错:
我的RMarkdown测试如下:
---
title: "testing ppt"
author: "JD Long"
date: "8/3/2018"
output: powerpoint_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Test chunk
```{r iris, echo = TRUE}
library(tidyverse)
iris %>%
mutate(small_petal = if_else(Petal.Width > 1.5, "big", "small")) %>%
ggplot(aes(x = Sepal.Length, y = Sepal.Width, color = Species, alpha = small_petal)) +
geom_point()
```
Run Code Online (Sandbox Code Playgroud)