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

生成此代码的代码如下:
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))如果我只是用
ggsave(filename="../plots/myplot2.png",
plot = p)我得到以下图像:

请注意,我需要一个解决方案,工作以外的方面。有人能告诉我发生了什么事吗?谢谢!
发布于 2018-06-20 08:15:47
grid.arrange(p, bottom = sub.label)https://stackoverflow.com/questions/50943213
复制相似问题