首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用gridExtra在gridExtra外添加文本时失真的图像

用gridExtra在gridExtra外添加文本时失真的图像
EN

Stack Overflow用户
提问于 2018-06-20 08:01:39
回答 1查看 109关注 0票数 0

我正在尝试使用facet_wrap将文件名添加到ggplot获取的绘图区域之外。我很确定我在这篇文章中找到了解决方案:Add filename or other annotation to ggplot figures。然而,将解决方案应用于我的问题会产生一个扭曲的图像。

生成此代码的代码如下:

代码语言:javascript
复制
require("gridExtra")
library(tidyverse)

df <- data.frame(x =runif(100, 1, 10),
             y = runif(100, 1, 10),
             myfacet = c("one", "two"))
p <- ggplot(data = df,
        aes(x = x,
            y = y)) +
geom_point() +
facet_wrap(~myfacet)

print(p)
script.name <- "myscript.R"
sub.label = textGrob(script.name, 
                 gp=gpar(fontsize=6),
                 x = unit(1, "npc"),
                 hjust = 1,
                 vjust = 1)
ggsave(filename="../plots/myplot.png",
   plot = arrangeGrob(p,
                      sub = sub.label,
                      clip = FALSE))

如果我只是用

代码语言:javascript
复制
ggsave(filename="../plots/myplot2.png",
   plot = p)

我得到以下图像:

请注意,我需要一个解决方案,工作以外的方面。有人能告诉我发生了什么事吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-20 08:15:47

代码语言:javascript
复制
grid.arrange(p, bottom = sub.label)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50943213

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档