簡體   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