繁体   English   中英

为什么将带有 ggtheme 的 ggplot 打印到 word 中时没有右边框?

[英]Why is there no right border when printing a ggplot with a ggtheme into word?

我正在 R markdown 中创建要打印到 MS 字的图。 When I create a plot using the base R plot() function, there are no borders around the printed plot. 如果我使用基本的ggplot也是一样。 但是,如果我使用 ggthemes 添加主题,它会在打印的 plot(但不是右侧)的顶部、左侧和底部添加边框。

我不知道它为什么会添加这些边框,或者为什么会省略右侧的边框。 无论我使用哪个主题,它似乎都会发生(由于白色背景,我更喜欢 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:

plot(data)

基本 plot 图像

格图:

ggplot(data=data,aes(x=temperature,y=pressure))+
  geom_point()

ggplot 图像

带有 ggtheme 的 ggplot:

ggplot(data=data,aes(x=temperature,y=pressure))+
  geom_point()+
  theme_gdocs()

带有 ggtheme 图像的 ggplot

我能够使用 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))

感谢任何致力于修复的人!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM