r - 为什么将带有 ggtheme 的 ggplot 打印到 word 中时没有右边框?
问题描述
我在 R markdown 中创建要打印到 MS word 的图。当我使用基本 R plot() 函数创建绘图时,打印的绘图周围没有边框。如果我使用基本的ggplot也是一样。但是,如果我使用 ggthemes 添加主题,它会在打印图的顶部、左侧和底部添加边框(但不是右侧)。
我不知道它为什么会添加这些边框,或者为什么会省略右侧的边框。无论我使用哪个主题,它似乎都会发生(由于白色背景,我更喜欢 theme_gdocs 或 theme_clean)。而不是删除所有这些边界,我宁愿实际上包括所有四个边的边界。
这是我的代码:(希望图像有效)
---
title: "ggplot reprex"
author: "Me"
date: "11/5/2019"
output: word_document
---
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse); library(ggthemes)
data=pressure
基图:
plot(data)
格图:
ggplot(data=data,aes(x=temperature,y=pressure))+
geom_point()
带有 ggtheme 的 ggplot:
ggplot(data=data,aes(x=temperature,y=pressure))+
geom_point()+
theme_gdocs()
解决方案
我能够使用 theme() 中的 plot.background 修改来解决这个问题,如下所示:
ggplot(data=data,aes(x=temperature,y=pressure))+
geom_point()+
theme_gdocs()+
theme(plot.background=element_rect(colour="black",fill=NA,size=1))
感谢任何致力于修复的人!
推荐阅读
- arrays - 需要帮助证明循环不变性(简单冒泡排序,部分正确性)
- android - Android SharedPreferences 使用 HashMap/For 每个循环设置/检索复选框
- ios - Swift 4 - AVAudioPlayer 从 UISlider 设置 currentTime
- python - 使用 Pandas 在 Python 中读取 excel 文件时用连字符替换 em dash
- amazon-web-services - AWS IAM:AssumeRole 与 GetSessionToken
- c# - 什么时候应该在 Asp.Net Core 中使用 Task.Run?
- javascript - HTML/Electron:防止将可拖动数据拖放到应用程序之外
- reactjs - Reactjs 在 chrome 中下载内容需要太多时间?
- c++ - 链表的复制构造函数
- c# - 无法更新 DataSet 中的 TableAdapter