【发布时间】:2018-11-29 06:59:54
【问题描述】:
我正在尝试使用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)
请注意,我需要一个在各个方面都有效的解决方案。 任何人都可以提供有关正在发生的事情的提示吗?谢谢!
【问题讨论】: